in reply to Re: Dynamically adding methods to Moo class
in thread Dynamically adding methods to Moo class
Hi hippo,
thank you for your fast reply. I really hoped that there is a possibility to use this kind of "method installation infrastructure" Moo must have for e.g. to implement the 'has'-declaration. With this declaration you get later an appropriate sub which you can call as method.
For an example use case. Assume you have a simple class:
package Me; use strict; use warnings; use Moo; has 'typ' => ( is => 'ro', required => 1, ); has 'other' => ( is => 'ro', required => 1, ); sub info { my $self = shift; return $self->new( 'typ' => 'INFO', 'other' => "@_", ); }
The method 'info' is just a convenience constructor for the Moo generated constructor 'new'. If I like to do this for several values of 'typ' I would repeat myself. So I hoped to "create" / "generate" these methods more elegant.
Regards
McA
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Dynamically adding methods to Moo class
by tobyink (Canon) on Apr 23, 2014 at 16:41 UTC | |
by McA (Priest) on Apr 23, 2014 at 16:54 UTC | |
by Arunbear (Prior) on Apr 24, 2014 at 12:51 UTC |
In Section
Seekers of Perl Wisdom