This seems like an example of where subclasses and polymorphism actually make sense.
use Attack::Heavy; use Attack::Lite; use Attack::Fast; my @attacks = ( Attack::Heavy->new, Attack::Lite->new, Attack::Fast->new, );
If you prefer, internally "Attack" could be a role that defines a common interface, and "Attack::Heavy", "Attack::Lite", and "Attack::Fast" could be composed with that role. Or inheritance could be used, whichever is your preference. Actually, inheritance is probably preferable here, because there are probably times where you would just instantiate an Attack object without using the defaults provided by ::Heavy, ::Lite, and ::Fast.
This is classic Perl-style object polymorphism; As long as an object can 'type', 'damage', and 'speed', it's sufficiently Attack like to be treated like an Attack object.
Dave
In reply to Re: Convenient Constructors - a Moo question
by davido
in thread Convenient Constructors - a Moo question
by blindluke
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |