Created
April 19, 2020 02:22
-
-
Save jjn1056/5661686e7a8ad29e9bf6c83ef5813115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.