Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Way to use Moo::Role to extend non-Moo class?

by tobyink (Abbot)
on Nov 13, 2013 at 12:04 UTC ( #1062378=note: print w/ replies, xml ) Need Help??


in reply to Way to use Moo::Role to extend non-Moo class?

Roles don't "extend" classes. Subclasses extend classes.

This will work:

package Foo { sub new { bless {}, shift; } sub foo { print "foo\n"; } } package Bar { use Moo; # NOT Moo::Role extends "Foo"; }

... but if the constructor for class Foo is any more complicated than the above, you'll need to write a FOREIGNBUILDARGS method for Bar to tell Bar's constructor what argument need to be passed along to Foo's constructor.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re: Way to use Moo::Role to extend non-Moo class?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1062378]
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: (13)
As of 2015-07-29 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls