view release on metacpan or search on metacpan
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
```
- [ ] **Step 4: Die Tests schreiben**
`t/10-qr.t`:
```perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
use MIME::Base64 qw( decode_base64 );
use Airlock::QR;
my $uri = 'https://my.example.org/airlock?user_code=BCDF-GHJK';
# finder pattern: 7x7 dark ring, light ring, 3x3 dark core
my @finder = qw( 1111111 1000001 1011101 1011101 1011101 1000001 1111111 );
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
done_testing;
```
`t/11-qr-readback.t`:
```perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
use File::Temp qw( tempdir );
use Airlock::QR;
# Proof that what Airlock::QR draws is a real QR code: an independent decoder
# (zbarimg from zbar-tools) has to read the text back.
my ( $zbarimg ) = grep { -x } map { $_.'/zbarimg' } split /:/, $ENV{PATH} // '';
plan skip_all => 'zbarimg not found in PATH (apt install zbar-tools)' unless $zbarimg;
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
=method max_bytes
Longest text, in bytes, this class encodes. 1000.
=cut
sub _build_matrix {
my ( $self ) = @_;
my $bytes = $self->text;
utf8::encode($bytes) if utf8::is_utf8($bytes);
croak __PACKAGE__.'->matrix needs a text' unless length $bytes;
croak __PACKAGE__.'->matrix text is longer than '.$self->max_bytes.' bytes'
if length $bytes > $self->max_bytes;
my $pattern = $self->has_encoder ? $self->encoder->( $bytes, $self->ecc ) : $self->_encode($bytes);
my @rows = map { [ split // ] } grep { length } split /\n/, $pattern // '';
croak __PACKAGE__.'->matrix encoder returned no square pattern of 0 and 1'
if !@rows || grep { @$_ != @rows || grep { $_ ne '0' && $_ ne '1' } @$_ } @rows;
while ( @rows > 21 && !grep { $_ } @{ $rows[0] }, @{ $rows[-1] }, map { $_->[0], $_->[-1] } @rows ) {
@rows = map { [ @{$_}[ 1 .. $#$_ - 1 ] ] } @rows[ 1 .. $#rows - 1 ];
}
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
=method otpauth_uri
my $uri = $totp->otpauth_uri( secret => $secret, account => 'getty@example.org', issuer => 'Mothership' );
The C<otpauth://> URI for enrolment. Feed it to L<Airlock::QR>.
=cut
sub _escape {
my ( $self, $text ) = @_;
utf8::encode($text) if utf8::is_utf8($text);
$text =~ s/([^A-Za-z0-9\-._~])/sprintf '%%%02X', ord $1/ge;
return $text;
}
1;
```
- [ ] **Step 6: `lib/Airlock/Factor/Upstream.pm` schreiben**
`lib/Airlock/Factor/Upstream.pm`:
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
Largest request body, in bytes, the endpoints read. 16384.
=cut
has _json => (
is => 'lazy',
init_arg => undef
);
sub _build__json { JSON::MaybeXS->new( utf8 => 1, canonical => 1, convert_blessed => 1 ) }
sub respond {
my ( $self, $method, $path, $param, $origin ) = @_;
my ( $route ) = ( $path // '' ) =~ m{([^/]*)/?\z};
return $self->_reply( 404, { error => 'not_found' } )
unless $route eq 'device' || $route eq 'token';
return $self->_reply( 405, { error => 'invalid_request' }, Allow => 'POST' )
unless uc( $method // '' ) eq 'POST';
return $self->_reply( 400, { error => 'invalid_request' } ) unless ref $param eq 'HASH';
return $self->_reply( 400, { error => 'unsupported_grant_type' } )
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
- [ ] **Step 1: Den Test schreiben**
Der Test ersetzt `HTTP::Tiny` durch eine Unterklasse, die eine PSGI-App im selben Prozess aufruft; so teilen Test und Server Uhr und Speicher. Ein Subtest geht zusätzlich über einen echten Socket. Dort baut der Server-Prozess sein eigenes `Airlock`...
`t/70-client.t`:
```perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
use lib 't/lib';
use HTTP::Server::PSGI;
use Test::TCP;
use JSON::MaybeXS;
use Airlock::Client;
use AirlockTest;
# A stand-in for HTTP::Tiny that talks to a PSGI app in-process: no socket, no
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
unless eval { require DBI; require DBD::SQLite; 1 };
}
use Path::Tiny qw( path );
use Airlock;
use Airlock::Test::Store;
use AirlockExample::StoreDBI;
sub database {
my $dbh = DBI->connect( 'dbi:SQLite:dbname=:memory:', '', '', { RaiseError => 1, PrintError => 0 } );
$dbh->do($_) for grep { /\S/ } split /;/, path('examples/schema.sql')->slurp_utf8 =~ s/^--.*$//mgr;
return $dbh;
}
subtest 'store contract' => sub {
Airlock::Test::Store->new( store => AirlockExample::StoreDBI->new( dbh => database() )->as_subs )->run;
};
subtest 'a whole flow on the database' => sub {
my $dbh = database();
my $clock = 1_000_000;
docs/superpowers/plans/2026-10-02-airlock-phase-1.md view on Meta::CPAN
}
use Path::Tiny qw( path );
use Airlock;
use Airlock::Test::Store;
use AirlockExample::Schema;
use AirlockExample::StoreDBIO;
sub schema {
my $schema = AirlockExample::Schema->connect( 'dbi:SQLite:dbname=:memory:', '', '', { RaiseError => 1, PrintError => 0 } );
my @ddl = grep { /\S/ } split /;/, path('examples/schema.sql')->slurp_utf8 =~ s/^--.*$//mgr;
$schema->storage->dbh_do( sub { $_[1]->do($_) for @ddl } );
return $schema;
}
subtest 'store contract' => sub {
Airlock::Test::Store->new( store => AirlockExample::StoreDBIO->new( schema => schema() )->as_subs )->run;
};
subtest 'a whole flow on the schema' => sub {
my $schema = schema();
lib/Airlock/Code.pm view on Meta::CPAN
}
return $code;
}
sub secret { unpack 'H*', urandom( $_[0]->secret_bytes ) }
sub hash {
my ( $self, $value ) = @_;
utf8::encode($value) if utf8::is_utf8($value);
return sha256_hex($value);
}
sub normalize {
my ( $self, $input ) = @_;
return unless defined $input;
my $code = uc $input;
$code =~ s/[\s\-_.]//g;
my $alphabet = $self->alphabet;
lib/Airlock/Factor/TOTP.pm view on Meta::CPAN
}
return 'otpauth://totp/'.$self->_escape( $arg{issuer} ).':'.$self->_escape( $arg{account} )
.'?secret='.$self->base32( $arg{secret} )
.'&issuer='.$self->_escape( $arg{issuer} )
.'&algorithm=SHA1&digits='.$self->digits.'&period='.$self->period;
}
sub _escape {
my ( $self, $text ) = @_;
utf8::encode($text) if utf8::is_utf8($text);
$text =~ s/([^A-Za-z0-9\-._~])/sprintf '%%%02X', ord $1/ge;
return $text;
}
1;
__END__
=pod
lib/Airlock/QR.pm view on Meta::CPAN
init_arg => undef
);
sub max_bytes { 1000 }
sub _build_matrix {
my ( $self ) = @_;
my $bytes = $self->text;
utf8::encode($bytes) if utf8::is_utf8($bytes);
croak __PACKAGE__.'->matrix needs a text' unless length $bytes;
croak __PACKAGE__.'->matrix text is longer than '.$self->max_bytes.' bytes'
if length $bytes > $self->max_bytes;
my $pattern = $self->has_encoder ? $self->encoder->( $bytes, $self->ecc ) : $self->_encode($bytes);
my @rows = map { [ split // ] } grep { length } split /\n/, $pattern // '';
croak __PACKAGE__.'->matrix encoder returned no square pattern of 0 and 1'
if !@rows || grep { @$_ != @rows || grep { $_ ne '0' && $_ ne '1' } @$_ } @rows;
while ( @rows > 21 && !grep { $_ } @{ $rows[0] }, @{ $rows[-1] }, map { $_->[0], $_->[-1] } @rows ) {
@rows = map { [ @{$_}[ 1 .. $#$_ - 1 ] ] } @rows[ 1 .. $#rows - 1 ];
}
lib/Airlock/Role/Endpoints.pm view on Meta::CPAN
sub device_grant_type { 'urn:ietf:params:oauth:grant-type:device_code' }
sub max_body { 16384 }
has _json => (
is => 'lazy',
init_arg => undef
);
sub _build__json { JSON::MaybeXS->new( utf8 => 1, canonical => 1, convert_blessed => 1 ) }
sub respond {
my ( $self, $method, $path, $param, $origin ) = @_;
my ( $route ) = ( $path // '' ) =~ m{([^/]*)/?\z};
return $self->_reply( 404, { error => 'not_found' } )
unless $route eq 'device' || $route eq 'token';
return $self->_reply( 405, { error => 'invalid_request' }, Allow => 'POST' )
unless uc( $method // '' ) eq 'POST';
return $self->_reply( 400, { error => 'invalid_request' } ) unless ref $param eq 'HASH';
return $self->_reply( 400, { error => 'unsupported_grant_type' } )
misc/agent-context/.claude/skills/getty-perl-core/SKILL.md view on Meta::CPAN
## Control flow
- **Postfix `if`/`unless`** for guards and short conditions: `croak(...) if $self->readonly;`
- **`unless $x`** instead of `if !$x`.
- **Guard clauses return bare:** `return unless $res->is_success;` â not `return undef;`.
- **Nested ternaries** for a return that picks between expressions, instead of an if/elsif chain.
## Data
- **`{ %hash }` and `\%hash` are different operations, not two styles.** `{ %h }` builds a new anonymous copy; `\%h` references the existing hash. Return a copy when the caller must not mutate your state; return the reference when sharing is the poin...
- **`Path::Tiny`** for every file operation â not `File::Spec`, not bare `open`. `path(...)->child(...)->slurp_utf8`.
- **`JSON::MaybeXS`** always â never `JSON::PP`, `JSON::XS`, `Cpanel::JSON::XS` directly. Encoders get `canonical => 1, convert_blessed => 1`.
- **Every serialiser is deterministic.** MessagePack `->canonical`, DBIC `serializer_options => { canonical => 1 }`. Same rule, every format.
- **Booleans: `JSON->true` / `JSON->false`.** `use JSON::MaybeXS;` covers codec and booleans.
- `$YAML::XS::Boolean = 'JSON::PP'` is one of YAML::XS's fixed mode names, not a module choice â leave it alone.
- **Align `=>` in multi-line hash literals** when keys are of similar length.
- **Optional pairs inline:** `$cond ? ( experimental => 1 ) : (),`
## Configuration
Config comes from environment variables prefixed with the project name
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
use MIME::Base64 qw( decode_base64 );
use Airlock::QR;
my $uri = 'https://my.example.org/airlock?user_code=BCDF-GHJK';
# finder pattern: 7x7 dark ring, light ring, 3x3 dark core
my @finder = qw( 1111111 1000001 1011101 1011101 1011101 1000001 1111111 );
t/11-qr-readback.t view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
use File::Temp qw( tempdir );
use Airlock::QR;
# Proof that what Airlock::QR draws is a real QR code: an independent decoder
# (zbarimg from zbar-tools) has to read the text back.
my ( $zbarimg ) = grep { -x } map { $_.'/zbarimg' } split /:/, $ENV{PATH} // '';
plan skip_all => 'zbarimg not found in PATH (apt install zbar-tools)' unless $zbarimg;
t/70-client.t view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
use lib 't/lib';
use HTTP::Server::PSGI;
use Test::TCP;
use JSON::MaybeXS;
use Airlock::Client;
use AirlockTest;
# A stand-in for HTTP::Tiny that talks to a PSGI app in-process: no socket, no
t/80-example-store-dbi.t view on Meta::CPAN
unless eval { require DBI; require DBD::SQLite; 1 };
}
use Path::Tiny qw( path );
use Airlock;
use Airlock::Test::Store;
use AirlockExample::StoreDBI;
sub database {
my $dbh = DBI->connect( 'dbi:SQLite:dbname=:memory:', '', '', { RaiseError => 1, PrintError => 0 } );
$dbh->do($_) for grep { /\S/ } split /;/, path('examples/schema.sql')->slurp_utf8 =~ s/^--.*$//mgr;
return $dbh;
}
subtest 'store contract' => sub {
Airlock::Test::Store->new( store => AirlockExample::StoreDBI->new( dbh => database() )->as_subs )->run;
};
subtest 'a whole flow on the database' => sub {
my $dbh = database();
my $clock = 1_000_000;
t/81-example-store-dbio.t view on Meta::CPAN
}
use Path::Tiny qw( path );
use Airlock;
use Airlock::Test::Store;
use AirlockExample::Schema;
use AirlockExample::StoreDBIO;
sub schema {
my $schema = AirlockExample::Schema->connect( 'dbi:SQLite:dbname=:memory:', '', '', { RaiseError => 1, PrintError => 0 } );
my @ddl = grep { /\S/ } split /;/, path('examples/schema.sql')->slurp_utf8 =~ s/^--.*$//mgr;
$schema->storage->dbh_do( sub { $_[1]->do($_) for @ddl } );
return $schema;
}
subtest 'store contract' => sub {
Airlock::Test::Store->new( store => AirlockExample::StoreDBIO->new( schema => schema() )->as_subs )->run;
};
subtest 'a whole flow on the schema' => sub {
my $schema = schema();