Skip to content

Instantly share code, notes, and snippets.

@akzhan
Last active April 19, 2017 08:05
Show Gist options
  • Save akzhan/421579163dfc86f570809f50d239800f to your computer and use it in GitHub Desktop.
Save akzhan/421579163dfc86f570809f50d239800f to your computer and use it in GitHub Desktop.
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