Skip to content

Instantly share code, notes, and snippets.

@akzhan akzhan/moose_dynamic.pl
Last active Apr 19, 2017

Embed
What would you like to do?
moose dynamic
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
You can’t perform that action at this time.