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 metaclass also because I also want to apply some roles to it.)
相关问题
- What uses more memory in c++? An 2 ints or 2 funct
- $ENV{$variable} in perl
- __call__ method of type class
- How Does WebSphere Choose the Classloading Order i
- Stop child process when parent process stops
相关文章
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Can NOT List directory including space using Perl
- NameError: name 'self' is not defined, eve
- Extracting columns from text file using Perl one-l
- Lazy (ungreedy) matching multiple groups using reg
- How do I tell DBD::mysql where mysql.sock is?
- What is a good way to deploy a Perl application?
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:MooseX::SingletonMethod
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:
/I3az/
The metaclass is the class, of course. If you want an instance of that class, just do:
You might also need to make sure that $meta doesn't get collected too soon. Generally, you do this:
That will keep the metaclass around, but you're going to leak the class if you aren't careful. If you only do this once, it won't matter; if you do it thousands of times, you could get yourself into trouble.
Much better to use something higher-level like
Moose::Meta::Class::create_anon_class
orMooseX::Traits
.