Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Dynamically adding methods to Moo class

by tobyink (Abbot)
on Apr 23, 2014 at 16:41 UTC ( #1083389=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Dynamically adding methods to Moo class
in thread Dynamically adding methods to Moo class

Don't forget that Moo is still Perl. You can still do all the stuff you could normally do using Perl!

for my $t (qw/ INFO BINFO WINFO SCHMINFO /) { no strict 'refs'; *{lc $t} = sub { my $class = shift; $class->new( typ => $t, other => "@_" ); }; }
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re^3: Dynamically adding methods to Moo class
Download Code
Re^4: Dynamically adding methods to Moo class
by McA (Priest) on Apr 23, 2014 at 16:54 UTC

    Thank you, Tobyink. That's what I meant with "Or do I have to tweak with the symbol table?" in my initial question. I thought that this kind of functionality is somewhere accessible in a more "formal" manner. A kind of:

    install_method('method_name', sub {});

    Best regards
    McA

      Not part of Moo, but ...
      use Sub::Install; Sub::Install::install_sub({ code => sub { ... }, into => $package, as => $subname });
      Link: Sub::Install

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-12-19 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (84 votes), past polls