After creating a metaclass using Moose::Meta::Class->create
, how do I instantiate a real Moose class with that class as a metaclass?
(I need to create the metacl
Not sure this answers this or your other SO question How do I build a Moose class at runtime, add a method to it, apply a role to it and instantiate it once? How would you approach this?
at Building a Moose class at runtime and tuning it but have a look at:
It may do what you want. Or you may find it useful to peer into our it works.
The documentation does provide links to blog posts I made while coming to grips with building this module so you may find those helpful also.
Here is an brief code example of MooseX::SingletonMethod:
{
package Foo;
use MooseX::SingletonMethod;
sub bar { say 'bar' }
}
my $baz = Foo->new;
my $bar = Foo->new;
$baz->add_singleton_method( baz => sub { say 'baz' } );
$baz->bar; # => bar
$bar->bar; # => bar
$baz->baz; # => baz
$bar->baz; # Throws can't find baz error
/I3az/