Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Moose: creating sub-classes on the fly

by ikegami (Patriarch)
on Oct 10, 2014 at 16:02 UTC ( [id://1103437]=note: print w/replies, xml ) Need Help??


in reply to Moose: creating sub-classes on the fly

for my $error_type (qw( Unrecoverable Unrecoverable::BrainDamage )) { eval(" package MonkeyMan::Error::$error_type; our \@ISA = 'MonkeyMan::Error'; 1 ") or die $@; }

Replies are listed 'Best First'.
Re^2: Moose: creating sub-classes on the fly
by McA (Priest) on Oct 10, 2014 at 16:36 UTC

    I'm really interested in the question whether this straight forward solution builds up all the metaclass stuff of Moose based classes?

    Best regards
    McA

      Well, I guess that depends on how the inherited meta behaves. If you want to be sure to have all that overhead, you could use
      for my $error_type (qw( Unrecoverable Unrecoverable::BrainDamage )) { eval(" package MonkeyMan::Error::$error_type; use Moose; extends 'MonkeyMan::Error'; 1 ") or die $@; }

        As documented in Moose, you don't actually inherit the meta method from Moose::Object. Each Moose class gets its own individual meta method built for it, completely overriding any that would have been inherited.

        They're all much of a muchness though:

        sub meta { $metaclass->initialize(blessed($_[0]) || $_[0]); }

        The $metaclass variable which has been closed over is usually the string "Moose::Meta::Class", though it may be a different class name if you're doing interesting metaprogramming stuff.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1103437]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found