Last active
April 19, 2017 08:05
-
-
Save akzhan/421579163dfc86f570809f50d239800f to your computer and use it in GitHub Desktop.
moose dynamic
This file contains 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 Cat; | |
use Moose; | |
package Generator; | |
use Mouse::Meta::Class; | |
use Mouse::Meta::Attribute; | |
sub generate { | |
my $siberian = Mouse::Meta::Class->create('Siberian'); | |
$siberian->add_method( | |
echo => sub { print 'yeah!' } | |
); | |
my $tiger = Mouse::Meta::Class->create('Tiger'); | |
$tiger->add_attribute( | |
Siberian => { | |
is => 'ro', | |
default => sub { $siberian->new_object; } | |
}, | |
); | |
Cat->meta->add_attribute( | |
Tiger => { | |
is => 'ro', | |
default => sub { $tiger->new_object }, | |
}, | |
); | |
print "Generation done!\n"; | |
} | |
generate(); | |
package main; | |
my $a = Cat->new; | |
warn $a->Tiger->Siberian->echo; # must print 'yeah!' but prints Can't locate object method "new" via package "Tiger" at dynamic.pl line 33 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment