Tested/Test/Request.pm

filter: Statementstmt 81.9% 59 / 72 Branchbran 56.2% 18 / 32 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 85.0% 17 / 20 Podpod 7.6% 1 / 13 totaltotal 69.5% 105 / 151 CC 21 SCAR 19.6
CC
21
Cov
74%
dir_config
30.0
pnotes
12.0
param
7.0
CRAP 7.1
↑ Summary Tested/Value/Array.pm »
1 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package HTML::Tested::Test::Request::Upload;
5 7 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 __PACKAGE__->mk_accessors(qw(name filename fh size));
7  
8 package HTML::Tested::Test::Request;
9 7 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use HTML::Tested::Seal;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 __PACKAGE__->mk_accessors(qw(_param _pnotes _uploads _dir_config uri));
15  
16 1 ▶sub hostname { return "some.host"; }
Subroutine hostname: called CC=1 SCAR=0.0
Pod undocumented
17 1 ▶sub server { return shift(); }
Subroutine server: called CC=1 SCAR=0.0
Pod undocumented
18 1 ▶sub port { return 80; }
Subroutine port: called CC=1 SCAR=0.0
Pod undocumented
19  
20 0 ▶sub server_root_relative {
Subroutine server_root_relative: not called CC=1 SCAR=6.9
Pod undocumented
21 0 return $_[1];
22 }
23  
24 1 ▶sub body_status { return 'Success'; }
Subroutine body_status: called CC=1 SCAR=0.0
Pod undocumented
25  
26 45 ▶sub param {
Subroutine param: called CC=7 SCAR=19.5
Pod undocumented
27 45 my ($self, $name, $val) = @_;
28 45 ▶ return $self->_param unless (wantarray || $name);
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray or $name 2 43 45
Condition100%3/3
wantarray or $name
l!l&&r!l&&!r
19242
MC/DC100%2/2
wantarray or $name
wantarray $name
Truth table100%3/3
A or B
A= wantarrayB= $name
ABresult
1X1
011
000
29 43 ▶ $self->_param({}) unless $self->_param;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_param 8 35 43
30 43 ▶ $self->_param->{$name} = $val if @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 18 25 43
31 43 ▶ return $self->_param->{$name} if ($name);
Branch: 1 branch
BranchTrueFalseTotal
if $name 37 6 43
32 6 ▶ return keys %{ $self->_param || {} };
Condition50%1/2
$self->_param || {}
l!l
60
MC/DC0%0/1
$self->_param || {}
$self->_param
Truth table50%1/2
A
A= $self->_param
Aresult
11
00
33 }
34  
35 0 ▶sub dir_config {
Subroutine dir_config: not called CC=5 SCAR=34.0
Pod undocumented
36 0 my ($self, $name, $val) = @_;
37 0 my $dc = $self->_dir_config;
38 0 ▶ if (!$dc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dc) 0 0 0
39 0 $dc = {};
40 0 $self->_dir_config($dc);
41 }
42 0 ▶ return $dc->{$name} if (@_ < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
43 0 ▶ $dc->{$name} = $val if defined($val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
44 0 ▶ delete $dc->{$name} if !defined($val);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $val 0 0 0
45 }
46  
47 =head2 $object->set_params($paramref)
48  
49 Sets param values according to C<$paramref> hash. Clears old params first.
50  
51 Parameter names starting with C<HT_SEALED_> are encrypted and C<HT_SEALED_>
52 prefix is removed.
53  
54 =cut
55 3 ▶sub set_params {
Subroutine set_params: called CC=3 SCAR=11.0
Pod documented
56 3 my ($self, $p) = @_;
57 3 $self->_param({});
58 3 ▶ while (my ($n, $v) = each %$p) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$p) 4 3 7
59 4 ▶ $v = HTML::Tested::Seal->instance->encrypt($v)
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ s/^HT_SEALED_// 1 3 4
60 if ($n =~ s/^HT_SEALED_//);
61 4 $self->param($n, $v);
62 }
63 }
64  
65 3 ▶sub parse_url {
Subroutine parse_url: called CC=3 SCAR=11.0
Pod undocumented
66 3 my ($self, $url) = @_;
67 3 my ($arg_str) = ($url =~ /\?(.+)/);
68 3 ▶ return unless $arg_str;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg_str 0 3 3
69 3 my @nvs = split('&', $arg_str);
70 my %res = map {
71 3 my @a = split('=', $_);
72 8 ▶ ($a[0], ($a[1] || ''));
Condition100%2/2
$a[1] || ''
l!l
53
MC/DC100%1/1
$a[1] || ''
$a[1]
Truth table100%2/2
A
A= $a[1]
Aresult
11
00
73 } @nvs;
74 3 $self->_param(\%res);
75 }
76  
77 0 ▶sub pnotes {
Subroutine pnotes: not called CC=3 SCAR=24.8
Pod undocumented
78 0 my ($self, $name, $val) = @_;
79 0 ▶ $self->_pnotes({}) unless $self->_pnotes;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_pnotes 0 0 0
80 0 ▶ return $self->_pnotes->{$name} unless scalar(@_) > 2;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ > 2 0 0 0
81 0 $self->_pnotes->{$name} = $val;
82 }
83  
84 6 ▶sub add_upload {
Subroutine add_upload: called CC=3 SCAR=11.0
Pod undocumented
85 6 my ($self, $n, $v) = @_;
86 6 ▶ $self->_uploads([]) unless $self->_uploads;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_uploads 4 2 6
87 6 ▶ open(my $fh, $v) or die "Unable to open $v";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $v or die "Unable to open $v" 6 0 6
88 6 push @{ $self->_uploads }, HTML::Tested::Test::Request::Upload->new({
89 name => $n, filename => $v , fh => $fh, size => -s $v });
90 }
91  
92 20 ▶sub upload {
Subroutine upload: called CC=3 SCAR=11.0
Pod undocumented
93 20 my ($self, $n) = @_;
94 20 ▶ my $ups = $self->_uploads || [];
Condition50%1/2
$self->_uploads || []
l!l
200
MC/DC0%0/1
$self->_uploads || []
$self->_uploads
Truth table50%1/2
A
A= $self->_uploads
Aresult
11
00
95 20 ▶ return $n ? (grep { $_->name eq $n } @$ups)[0] : map { $_->name } @$ups;
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 11 9 20
96 }
97  
98 1 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
99 1 return Dumper(shift());
100 }
101  
102 7 1;
↑ Summary Tested/Value/Array.pm »