| 1 | |||||||||||||||||||||||||||||
| 2 | =head1 NAME | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | HTML::StickyForm::RequestHash - Minimal CGI-like request object | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | my $req=HTML::StickyForm::RequestHash->new( | ||||||||||||||||||||||||||||
| 9 | key1 => 'abc', | ||||||||||||||||||||||||||||
| 10 | key1 => 'def', | ||||||||||||||||||||||||||||
| 11 | key2 => ['ghi','jkl'], | ||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||
| 13 | my @keys=$req->param; | ||||||||||||||||||||||||||||
| 14 | my $val1=$req->param('key1'); | ||||||||||||||||||||||||||||
| 15 | my @val2=$req->param('key2'); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | This class provides the minimum features required of a request object by | ||||||||||||||||||||||||||||
| 20 | L<HTML::StickyForm>, for use in cases where a normal request is not available. | ||||||||||||||||||||||||||||
| 21 | This might be because an empty request is needed, or where parameters are | ||||||||||||||||||||||||||||
| 22 | available, but it is not appropriate to use L<CGI> or L<Apache::Request>. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | package HTML::StickyForm::RequestHash; | ||||||||||||||||||||||||||||
| 27 | BEGIN { | ||||||||||||||||||||||||||||
| 28 | 15 | ▶ | $HTML::StickyForm::RequestHash::VERSION = '0.07_02'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =over | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =item new(PAIRLIST) | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | Constructor. Creates a request object with the supplied list of parameters. | ||||||||||||||||||||||||||||
| 41 | Multiple values for the same parameter name can be set up either by passing | ||||||||||||||||||||||||||||
| 42 | multiple name/value pairs, or by passing arrayrefs for values. It is not an | ||||||||||||||||||||||||||||
| 43 | error to mix these methods - all supplied values will be set in the new object. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub new{ | ||||||||||||||||||||||||||||
| 48 | 19 | ▶ | my $class=shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 19 | my %self; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 19 | ▶ | while(my($name,$val)=splice @_,0,2){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 13 | ▶ | my $array=$self{$name}||=[]; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self{$name} ||= []
MC/DC100%1/1
$self{$name} ||= []
$self{$name}
Truth table100%2/2
A
A= $self{$name}
| |||||||||||||||||||||||||||||
| 53 | 13 | ▶ | if($val && ref($val) eq 'ARRAY'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$val and ref $val eq "ARRAY"
MC/DC50%1/2
$val and ref $val eq "ARRAY"
$val
ref $val eq "ARRAY"
Truth table66%2/3
A and B
A= $valB= ref $val eq "ARRAY"
| |||||||||||||||||||||||||||||
| 54 | 5 | push @$array,@$val; | |||||||||||||||||||||||||||
| 55 | }else{ | ||||||||||||||||||||||||||||
| 56 | 8 | push @$array,$val; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 19 | bless \%self,$class; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =back | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 METHODS | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =over | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =item param() | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Returns a list of the names of all configured parameters. Each name is listed | ||||||||||||||||||||||||||||
| 72 | only once, regardless of how many values are configured for any given name. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =item param($name) | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | In scalar context, returns the first configured value for the given name. | ||||||||||||||||||||||||||||
| 77 | In list context, returns all configured values for the given name. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub param{ | ||||||||||||||||||||||||||||
| 82 | 67 | ▶ | my($self)=shift; | ||||||||||||||||||||||||||
|
Subroutine
param: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 67 | ▶ | if(my($name)=@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 48 | ▶ | $name='' unless defined $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 48 | ▶ | my $array=$self->{$name} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | or return; | ||||||||||||||||||||||||||||
| 87 | 40 | ▶ | return @$array if wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 4 | return $array->[0]; | |||||||||||||||||||||||||||
| 89 | }else{ | ||||||||||||||||||||||||||||
| 90 | 19 | return keys %$self; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =back | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # Return true to require | ||||||||||||||||||||||||||||
| 99 | 15 | 1; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Copyright (C) Institute of Physics Publishing 2005-2011 | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Peter Haworth <pmh@edison.ioppublishing.com> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | You may use and distribute this module according to the same terms | ||||||||||||||||||||||||||||
| 109 | that Perl is distributed under. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||