Har/Entry/Request/PostData/Params.pm

filter: Statementstmt 100% 81 / 81 Branchbran 97.2% 35 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 85.7% 6 / 7 totaltotal 98.5% 133 / 135 CC 21 SCAR 14.9
CC
21
Cov
99%
new
7.0
TO_JSON
7.0
AUTOLOAD
4.0
CRAP 4.4
« Har/Entry.pm ↑ Summary Har/Entry/Response.pm »
1 package Archive::Har::Entry::Request::PostData::Params;
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  
7 10 our $VERSION = '0.21';
8  
9 7 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
10 7 my ( $class, $params ) = @_;
11 7 my $self = {};
12 7 bless $self, $class;
13 7 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 7 0 7
14 7 $self->name( $params->{name} );
15 7 $self->value( $params->{value} );
16 7 ▶ if ( defined $params->{fileName} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"fileName"}) 1 6 7
17 1 $self->file_name( $params->{fileName} );
18 }
19 7 ▶ if ( defined $params->{contentType} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"contentType"}) 1 6 7
20 1 $self->content_type( $params->{contentType} );
21 }
22 7 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 1 6 7
23 1 $self->comment( $params->{comment} );
24 }
25 7 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
26 16 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 1 15 16
27 1 $self->$key( $params->{$key} );
28 }
29 }
30 }
31 7 return $self;
32 }
33  
34 41 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod documented
35 41 my ( $self, $new ) = @_;
36 41 my $old = $self->{name};
37 41 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 7 34 41
38 7 $self->{name} = $new;
39 }
40 41 return $old;
41 }
42  
43 41 ▶sub value {
Subroutine value: called CC=2 SCAR=6.9
Pod documented
44 41 my ( $self, $new ) = @_;
45 41 my $old = $self->{value};
46 41 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 7 34 41
47 7 $self->{value} = $new;
48 }
49 41 return $old;
50 }
51  
52 54 ▶sub file_name {
Subroutine file_name: called CC=2 SCAR=6.9
Pod documented
53 54 my ( $self, $new ) = @_;
54 54 my $old = $self->{fileName};
55 54 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 53 54
56 1 $self->{fileName} = $new;
57 }
58 54 return $old;
59 }
60  
61 54 ▶sub content_type {
Subroutine content_type: called CC=2 SCAR=6.9
Pod documented
62 54 my ( $self, $new ) = @_;
63 54 my $old = $self->{contentType};
64 54 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 53 54
65 1 $self->{contentType} = $new;
66 }
67 54 return $old;
68 }
69  
70 53 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
71 53 my ( $self, $new ) = @_;
72 53 my $old = $self->{comment};
73 53 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 52 53
74 1 $self->{comment} = $new;
75 }
76 53 return $old;
77 }
78  
79 10 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
80 10 my ( $self, $new ) = @_;
81  
82 10 my $name = $Archive::Har::Entry::Request::PostData::Params::AUTOLOAD;
83 10 $name =~ s/.*://smx; # strip fully-qualified portion
84  
85 10 my $old;
86 10 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 4 6 10
elsif ($name eq 'DESTROY') { } 5 1 6
87 4 $old = $self->{$name};
88 4 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 3 1 4
89 3 $self->{$name} = $new;
90 }
91 }
92 elsif ( $name eq 'DESTROY' ) {
93 }
94 else {
95 1 Carp::croak(
96 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
97 );
98 }
99 9 return $old;
100 }
101  
102 33 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=7 SCAR=19.5
Pod undocumented
103 33 my ($self) = @_;
104 33 my $json = {};
105 33 $json->{name} = $self->name();
106 33 $json->{value} = $self->value();
107 33 ▶ if ( defined $self->file_name() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->file_name) 19 14 33
108 19 $json->{fileName} = $self->file_name();
109 }
110 33 ▶ if ( defined $self->content_type() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->content_type) 19 14 33
111 19 $json->{contentType} = $self->content_type();
112 }
113 33 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 19 14 33
114 19 $json->{comment} = $self->comment();
115 }
116 33 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
117 142 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 39 103 142
118 103 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 18 85 103
119 18 $json->{$key} = $self->{$key};
120 }
121 }
122 33 return $json;
123 }
124  
125 10 1;
126 __END__
« Har/Entry.pm ↑ Summary Har/Entry/Response.pm »