neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
Greetings,
I have a moose question. I'm still new to moose. Normally I would pass parameters to a new object thusly.
my $ob = MyModule->new( colour => $colour, shape => $shape, );
Suppose that colour and shape are arguments and that they are optional. It seems that if no argument is given via my program the value is ''. This seems to confuse my classes on the moose side where it fails to set the default. My thought was to build the parameter hash before hand so as to pass only the arguments that are defined.
if ( $colour ) { $param{'colour'} = $colour }; if ( $shape ) { $param{'shape'} = $shape }; my $ob = MyModule->new( %param );
I tried this but nothing seems to make it to moose. Am I on the right track? Is there better way?
Neil Watson
watson-wilson.ca
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing params, as a hash, to moose
by frozenwithjoy (Priest) on Oct 13, 2012 at 04:53 UTC | |
|
Re: Passing params, as a hash, to moose
by kcott (Archbishop) on Oct 13, 2012 at 09:47 UTC | |
|
Re: Passing params, as a hash, to moose
by mbethke (Hermit) on Oct 13, 2012 at 02:22 UTC |