StickyForm/RequestHash.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 12 / 12 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 96.0% 48 / 50 CC 9 SCAR 14.1
CC
9
Cov
98%
new
5.0
param
5.0
BEGIN
1.0
CRAP 4.1
« StickyForm.pm ↑ Summary
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
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 13 19 32
52 13 ▶ my $array=$self{$name}||=[];
Condition100%2/2
$self{$name} ||= []
l!l
76
MC/DC100%1/1
$self{$name} ||= []
$self{$name}
Truth table100%2/2
A
A= $self{$name}
Aresult
11
00
53 13 ▶ if($val && ref($val) eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if ($val and ref $val eq 'ARRAY') { } 5 8 13
Condition66%2/3
$val and ref $val eq "ARRAY"
!ll&&!rl&&r
085
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (my($name) = ) { } 48 19 67
84 48 ▶ $name='' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 6 42 48
85 48 ▶ my $array=$self->{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $array = $self->{$name} or return 8 40 48
86 or return;
87 40 ▶ return @$array if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 36 4 40
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  
« StickyForm.pm ↑ Summary