Skip to content

Instantly share code, notes, and snippets.

View j1n3l0's full-sized avatar

Nelo Onyiah j1n3l0

  • Goznel Limited
  • Kent UK
  • 22:51 (UTC -12:00)
View GitHub Profile
@j1n3l0
j1n3l0 / Client.pm
Created March 17, 2021 11:10
Trying to avoid mutating a readonly attribute
package Client;
use Moo;
use Type::Utils qw< class_type >;
use Types::Standard -types;
use URI;
use experimental qw< signatures >;
has service_uri => (
@j1n3l0
j1n3l0 / undef.t
Last active March 3, 2021 08:04
Coerce an attribute from Undef|EmptyStr to a default value
use Test2::V0;
package Api::Client 1.0 {
use Moose;
use Moose::Util::TypeConstraints;
use Readonly;
Readonly my $DEFAULT_HOSTNAME => 'api.example.com';
subtype 'EmptyStr', as 'Str', where { /^$/ };
@j1n3l0
j1n3l0 / cpanfile
Created December 3, 2020 13:52
cpanm --installdeps . -v
requires Minion => '== 10.13';
@j1n3l0
j1n3l0 / 00-basic.t
Last active December 4, 2020 18:34
yath vs prove (on Mac OS)
use Test2::V0;
use File::Temp;
use Redis;
use Test::RedisServer;
my $test_server = Test::RedisServer->new(
tmpdir => File::Temp->newdir( CLEANUP => 1, DIR => '.' ),
conf => { port => 9000 },
) || bail_out('Failed to start test redis server');
@j1n3l0
j1n3l0 / override-isa.t
Created August 19, 2020 10:58
Override the response to ->isa fot Test2 mock objects
use Test2::V0;
subtest 'Overriding "isa" on a mock object' => sub {
isa_ok(
mock( {}, override => [ isa => sub { pop eq 'Foo' } ] ),
['Foo'],
'should correctly respond to "isa"',
);
};
@j1n3l0
j1n3l0 / maybe.t
Last active August 12, 2020 11:44
Investigating some interesting usage of Maybe[`a] observed
use Test2::V0;
subtest 'Given a class with attribute: Maybe[`a]' => sub {
package Job {
use Moo;
use Types::Standard qw< :types >;
has title => ( is => 'ro', isa => Str );
};
package PwC;
use 5.032;
use Moo;
use SOAP::Data::Builder::Simple qw< data >;
use Type::Params qw< Invocant compile >;
use Type::Utils qw< class_type >;
use Types::Standard qw< ArrayRef >;
@j1n3l0
j1n3l0 / Service.pm
Last active January 22, 2021 16:52
Coerce an attribute from a Str to a URI object
package Service;
use Moo;
use Type::Utils qw( class_type );
use Types::Standard qw( Str );
use URI;
has endpoint => (
coerce => 1,
default => 'https://example.com/service',
@j1n3l0
j1n3l0 / Foo.pm
Last active July 10, 2020 11:41
A simple type library demonstrating Dict with optional arguments
package Foo;
use Type::Library -base;
use Type::Utils qw( as declare );
use Types::Standard qw( Dict HashRef Int slurpy );
declare Params, as Dict[ id => Int, slurpy HashRef ];
1;
use Test2::V0;
package Controller {
use 5.030;
use Moo;
use Type::Params qw< Invocant compile >;
use Type::Utils qw< declare as where >;
use Types::Standard qw< :types >;
my $Controller = declare as Object,