Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created April 19, 2020 02:22
Show Gist options
  • Save jjn1056/5661686e7a8ad29e9bf6c83ef5813115 to your computer and use it in GitHub Desktop.
Save jjn1056/5661686e7a8ad29e9bf6c83ef5813115 to your computer and use it in GitHub Desktop.
package Local::Base;
use Moo::Role;
has attr1 => (
is => 'ro',
required => 1,
default => sub { 100 },
);
package Local::Layer;
use Moo::Role;
with 'Local::Base';
has attr2 => (
is => 'ro',
lazy => 1,
default => sub {
return +{
aaa => 111,
bbb => $_[0]->attr1,
};
},
);
package Test::MooObject;
use Moo;
with 'Local::Layer';
package Test::RoleTinyObject;
use Role::Tiny::With;
with 'Local::Layer';
sub new { return bless +{}, shift }
package Local::Tests;
use Test::Most;
ok my $moo = Test::MooObject->new;
is_deeply $moo->attr2, +{
aaa => 111,
bbb => 100,
};
ok my $role_tiny_obj = Test::RoleTinyObject->new;
is_deeply $role_tiny_obj->attr2, +{
aaa => 111,
bbb => 100,
};
done_testing;
@jjn1056
Copy link
Author

jjn1056 commented Apr 19, 2020

$ prove test.pl 
test.pl .. 1/? 
#   Failed test at test.pl line 55.
#     Structures begin differing at:
#          $got->{bbb} = undef
#     $expected->{bbb} = '100'
# Looks like you failed 1 test of 4.
test.pl .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/4 subtests 

Test Summary Report
-------------------
test.pl (Wstat: 256 Tests: 4 Failed: 1)
  Failed test:  4
  Non-zero exit status: 1
Files=1, Tests=4,  1 wallclock secs ( 0.01 usr  0.01 sys +  0.08 cusr  0.04 csys =  0.14 CPU)
Result: FAIL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment