Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Package problems

by Anonymous Monk
on Apr 14, 2017 at 18:41 UTC ( [id://1187956]=note: print w/replies, xml ) Need Help??


in reply to Package problems

You really want something more like this:
package Animal; use Moo; has [qw(name gender)] => (is => 'ro'); package Pet; use Moo::Role; has [qw(treats pref)] => (is => 'ro'); sub play { sprintf "%s a %s", $_[0]->pref, @{$_[0]->treats}[rand@{$_[0 +]->treats}] } package Dog; use Moo; extends 'Animal'; with 'Pet'; package Cat; use Moo; extends 'Animal'; with 'Pet'; package main; my @pets = ( Dog->new( name => 'Odie', gender => 'male', pref => 'chases', trea +ts => [qw(ball bone doll)] ), Cat->new( name => 'Garfield', gender => 'male', pref => 'eats', tr +eats => [qw(lasagna pookie blanket)] ), ); printf "%s, being %s, %s.\n", $_->name, $_->gender, $_->play for @pets +;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-18 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found