From 3ec0af6bd055f49d2b6a4dff6cf7cc21e3718f79 Mon Sep 17 00:00:00 2001 From: Hugh Davenport Date: Thu, 17 Jan 2013 18:15:43 +1300 Subject: [PATCH] bug 9412 Add optional_params sub to C4::Service Similar to require_params, but just returns undef for any param that wasn't sent by request Signed-off-by: Hugh Davenport --- C4/Service.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/C4/Service.pm b/C4/Service.pm index d9990ff..82604f1 100644 --- a/C4/Service.pm +++ b/C4/Service.pm @@ -204,6 +204,32 @@ sub require_params { return @values; } +=head2 optional_params + + my @values = C4::Service->optional_params( @params ); + +Check that each of of the parameters specified in @params was sent in the +request, then return their values in that order. If any were not sent in +the request, undef is returned for that value. + +=cut + +sub optional_params { + my ( $class, @params ) = @_; + + my @values; + + for my $param ( @params ) { + if ( !defined( $query->param( $param ) ) ) { + push @values, undef; + } else { + push @values, $query->param( $param ); + } + } + + return @values; +} + =head2 dispatch C4::Service->dispatch( -- 1.7.10.4