Har/Entry/Request/PostData.pm

filter: Statementstmt 100% 90 / 90 Branchbran 94.4% 34 / 36 Conditioncond 55.5% 5 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 11 / 11 Podpod 83.3% 5 / 6 totaltotal 92.9% 146 / 157 CC 26 SCAR 17.4
CC
26
Cov
96%
new
10.1
params
6.1
TO_JSON
6.0
CRAP 5.7
« Har/Entry/Cache.pm ↑ Summary Har/Page.pm »
1 package Archive::Har::Entry::Request::PostData;
2  
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Archive::Har::Entry::Request::PostData::Params();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 our $VERSION = '0.21';
9  
10 38 ▶sub new {
Subroutine new: called CC=10 SCAR=23.1
Pod documented
11 38 my ( $class, $params ) = @_;
12 38 my $self = {};
13 38 bless $self, $class;
14 38 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 37 1 38
15 37 $self->mime_type( $params->{mimeType} );
16 37 ▶ if ( ( defined $params->{params} )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $params->{'params'} and ref $params->{'params'} eq 'ARRAY' and scalar @{$params->{'params'};} > 0) { } 4 33 37
elsif (defined $params->{'text'}) { } 33 0 33
Condition66%4/6
defined $params->{"params"} and ref $params->{"params"} eq "ARRAY" and scalar @{$params->{"params"};} > 0
!ll&&!rl&&r
3304
defined $params->{"params"} and ref $params->{"params"} eq "ARRAY"
!ll&&!rl&&r
3304
MC/DC33%1/3
defined $params->{"params"} and ref $params->{"params"} eq "ARRAY" and scalar @{$params->{"params"};} > 0
defined $params->{"params"} ref $params->{"params"} eq "ARRAY" scalar @{$params->{"params"};} > 0
Truth table50%2/4
A and B and C
A= defined $params->{"params"}B= ref $params->{"params"} eq "ARRAY"C= scalar @{$params->{"params"};} > 0
ABCresult
0XX0
10X0
1100
1111
17 && ( ref $params->{params} eq 'ARRAY' )
18 4 && ( scalar @{ $params->{params} } > 0 ) )
19 {
20 4 my @params;
21 4 foreach my $param ( @{ $params->{params} } ) {
22 7 push @params,
23 Archive::Har::Entry::Request::PostData::Params->new($param);
24 }
25 4 $self->params( \@params );
26 }
27 elsif ( defined $params->{text} ) {
28 33 $self->text( $params->{text} );
29 }
30 37 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 1 36 37
31 1 $self->comment( $params->{comment} );
32 }
33 37 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
34 77 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 1 76 77
35 1 $self->$key( $params->{$key} );
36 }
37 }
38 }
39 38 return $self;
40 }
41  
42 69 ▶sub mime_type {
Subroutine mime_type: called CC=2 SCAR=6.9
Pod documented
43 69 my ( $self, $new ) = @_;
44 69 my $old = $self->{mimeType};
45 69 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 38 31 69
46 38 $self->{mimeType} = $new;
47 }
48 69 return $old;
49 }
50  
51 70 ▶sub text {
Subroutine text: called CC=2 SCAR=6.9
Pod documented
52 70 my ( $self, $new ) = @_;
53 70 my $old = $self->{text};
54 70 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 35 35 70
55 35 delete $self->{params};
56 35 $self->{text} = $new;
57 }
58 70 return $old;
59 }
60  
61 41 ▶sub params {
Subroutine params: called CC=6 SCAR=18.0
Pod documented
62 41 my ( $self, $new ) = @_;
63 41 my $old = $self->{params};
64 41 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 4 37 41
65 4 delete $self->{text};
66 4 $self->{params} = [];
67 4 ▶ if ( ( defined $new ) && ( ref $new eq 'ARRAY' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new and ref $new eq "ARRAY") 4 0 4
Condition33%1/3
defined $new and ref $new eq "ARRAY"
!ll&&!rl&&r
004
MC/DC0%0/2
defined $new and ref $new eq "ARRAY"
defined $new ref $new eq "ARRAY"
Truth table33%1/3
A and B
A= defined $newB= ref $new eq "ARRAY"
ABresult
0X0
100
111
68 4 foreach my $param ( @{$new} ) {
69 7 push @{ $self->{params} }, $param;
70 }
71 }
72 }
73 41 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 33 8 41
74 33 return @{$old};
75 }
76 else {
77 8 return ();
78 }
79 }
80  
81 53 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
82 53 my ( $self, $new ) = @_;
83 53 my $old = $self->{comment};
84 53 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 52 53
85 1 $self->{comment} = $new;
86 }
87 53 return $old;
88 }
89  
90 42 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
91 42 my ( $self, $new ) = @_;
92  
93 42 my $name = $Archive::Har::Entry::Request::PostData::AUTOLOAD;
94 42 $name =~ s/.*://smx; # strip fully-qualified portion
95  
96 42 my $old;
97 42 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 4 38 42
elsif ($name eq 'DESTROY') { } 37 1 38
98 4 $old = $self->{$name};
99 4 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 3 1 4
100 3 $self->{$name} = $new;
101 }
102 }
103 elsif ( $name eq 'DESTROY' ) {
104 }
105 else {
106 1 Carp::croak(
107 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
108 );
109 }
110 41 return $old;
111 }
112  
113 30 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=6 SCAR=17.9
Pod undocumented
114 30 my ($self) = @_;
115 30 my $json = {};
116 30 $json->{mimeType} = $self->mime_type();
117 30 $json->{params} = [ $self->params() ];
118 30 ▶ if ( defined $self->text() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->text) 4 26 30
119 4 $json->{text} = $self->text();
120 }
121 30 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 22 8 30
122 22 $json->{comment} = $self->comment();
123 }
124 30 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
125 104 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 23 81 104
126 81 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 21 60 81
127 21 $json->{$key} = $self->{$key};
128 }
129 }
130 30 return $json;
131 }
132  
133 10 1;
134 __END__
« Har/Entry/Cache.pm ↑ Summary Har/Page.pm »