A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Mojo::UserAgent request format

The get(), post(), etc. methods are both too magic, and not magic enough.

They do what I mean, but only if I remember the order or parameters. Luckily Perl has an easy solution to this problem: Named parameters! AKA Passing a hash, like a normal person.


# Existing Mojo::UserAgent interface:
->get('www.☃.net?hello=there' => {Accept => '*/*'});
->post('https://example.com' => json => {top => 'secret'});
# Alternative improved interface (proposed):
->get({
url => 'www.☃.net?hello=there',
headers => { Accept => '*/*' },
});
->post({
url => 'https://example.com',
json => { top => 'secret' },
});

Good hex values

For UUIDs:

c0ffeeee-cafe-cafe-cafe-c0ffeec0ffee

fadedfad-fade-fade-fade-decaffdecaff

g00dg00d-g00d-g00d-g00d-g00dg00dg00d


Perl Postgres test fixtures

Test::PostgreSQL approach:

my $postgres_db = Test::PostgreSQL->new;
my $test_schema = MyDBIC::Schema->connect( $postgres_db->dsn );
my $test_migration = DBIx::Class::Migration->new(
schema => $test_schema,
target_dir => 'share',
);
$test_migration->install;
$t->app->helper( 'schema' => sub { $test_schema } );


Test::DBIx::Class approach:

use Test::DBIx::Class {
schema_class => 'MyDBIC::Schema',
connect_info => { dsn => 'dbi:Pg:' },
};
my $test_schema = Schema;
# This works, but not sure why it's necessary to duplicate the fixtures
# that are already in share/migrations/PostgreSQL/deploy/1
fixtures_ok [
FooTable => [
[ qw/code/ ],
[ qw/CREATED/ ],
],
# Or possibly
# fixtures_ok 'basic' => 'installed the basic fixtures from configuration files';
# DBIx::Class::Fixtures->new({config_dir => $fixtures_path})
# ->populate({no_deploy => 1, schema => $test_schema, directory => "$fixtures_path"});
$t->app->helper( 'payments_schema' => sub { $test_schema } );