This is just a desire for more functionality in MooseX::Param. I like
CGI::Application's param and it works just a little different. I've
included a patch.
Basically, I like that CGI::App::param allows you to set values via a
hashref as an argument and it will process it for ya. This was the
handiest change as far as I'm concerned.
The other change, optional though it may be, was that when you set one
value, it returns that value. CGI::App just uses that for testing and I
don't necessarily see a huge value in it, but I've included it for
completeness.
This doesn't break any backwards compatibility as far as I can see so I
thought it'd be a nice add on.
Regardless of whether you choose to include this, thankee for a nifty
little addon that saves me much time!
And Moose. Thanks for Moose. Still getting into it but I am loving it.
Cheers,
Dave Doyle
Subject: | MooseX-Param.pm.patch |
--- Param.pm 2008-10-10 18:58:35.000000000 +0000
+++ Param.pm-ddoyle 2008-10-10 18:59:09.000000000 +0000
@@ -19,9 +19,15 @@
# if they want the list of keys ...
return keys %{$self->params} if scalar @_ == 0;
- # if they want to fetch a particular key ...
- return $self->params->{$_[0]} if scalar @_ == 1;
+ # set via hashref
+ if ( ref $_[0] eq 'HASH' ) {
+ $self->params->{$_} = $_[0]->{$_} foreach keys %{$_[0]};
+ return;
+ }
+ # if they want to fetch a particular key ...
+ return $self->params->{$_[0]} if scalar @_ == 1;
+
((scalar @_ % 2) == 0)
|| confess "parameter assignment must be an even numbered list";
@@ -29,8 +35,9 @@
while (my ($key, $value) = each %new) {
$self->params->{$key} = $value;
}
-
- return;
+
+ # if we're setting exactly one param, return it
+ return scalar @_ == 2 ? $_[1] : undef;
}
1;