Har/Entry/Response/Content.pm

filter: Statementstmt 100% 92 / 92 Branchbran 100% 46 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 87.5% 7 / 8 totaltotal 99.3% 157 / 158 CC 26 SCAR 15.9
CC
26
Cov
100%
new
8.0
TO_JSON
8.0
AUTOLOAD
4.0
CRAP 4.9
« Har/Page/PageTimings.pm ↑ Summary Har/Browser.pm »
1 package Archive::Har::Entry::Response::Content;
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 352 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
10 352 my ( $class, $params ) = @_;
11 352 my $self = {};
12 352 bless $self, $class;
13 352 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 347 5 352
14 347 $self->size( $params->{size} );
15 347 $self->mime_type( $params->{mimeType} );
16 347 ▶ if ( defined $params->{compression} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"compression"}) 74 273 347
17 74 $self->compression( $params->{compression} );
18 }
19 347 ▶ if ( defined $params->{text} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"text"}) 119 228 347
20 119 $self->text( $params->{text} );
21 }
22 347 ▶ if ( defined $params->{encoding} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"encoding"}) 48 299 347
23 48 $self->encoding( $params->{encoding} );
24 }
25 347 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 36 311 347
26 36 $self->comment( $params->{comment} );
27 }
28 347 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
29 971 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 2 969 971
30 2 $self->$key( $params->{$key} );
31 }
32 }
33 }
34 352 return $self;
35 }
36  
37 832 ▶sub mime_type {
Subroutine mime_type: called CC=3 SCAR=11.0
Pod documented
38 832 my ( $self, $new ) = @_;
39 832 my $old = $self->{mimeType};
40 832 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 352 480 832
41 352 $self->{mimeType} = $new;
42 }
43 832 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 458 374 832
44 458 return $old;
45 }
46 else {
47 374 return 'text/plain';
48 }
49 }
50  
51 832 ▶sub size {
Subroutine size: called CC=3 SCAR=11.0
Pod documented
52 832 my ( $self, $new ) = @_;
53 832 my $old = $self->{size};
54 832 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 352 480 832
55 352 $self->{size} = $new;
56 }
57 832 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 458 374 832
58 458 return $old;
59 }
60 else {
61 374 return 0;
62 }
63 }
64  
65 591 ▶sub compression {
Subroutine compression: called CC=2 SCAR=6.9
Pod documented
66 591 my ( $self, $new ) = @_;
67 591 my $old = $self->{compression};
68 591 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 74 517 591
69 74 $self->{compression} = $new;
70 }
71 591 return $old;
72 }
73  
74 683 ▶sub text {
Subroutine text: called CC=2 SCAR=6.9
Pod documented
75 683 my ( $self, $new ) = @_;
76 683 my $old = $self->{text};
77 683 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 122 561 683
78 122 $self->{text} = $new;
79 }
80 683 return $old;
81 }
82  
83 551 ▶sub encoding {
Subroutine encoding: called CC=2 SCAR=6.9
Pod documented
84 551 my ( $self, $new ) = @_;
85 551 my $old = $self->{encoding};
86 551 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 48 503 551
87 48 $self->{encoding} = $new;
88 }
89 551 return $old;
90 }
91  
92 554 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
93 554 my ( $self, $new ) = @_;
94 554 my $old = $self->{comment};
95 554 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 36 518 554
96 36 $self->{comment} = $new;
97 }
98 554 return $old;
99 }
100  
101 356 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
102 356 my ( $self, $new ) = @_;
103  
104 356 my $name = $Archive::Har::Entry::Response::Content::AUTOLOAD;
105 356 $name =~ s/.*://smx; # strip fully-qualified portion
106  
107 356 my $old;
108 356 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 5 351 356
elsif ($name eq 'DESTROY') { } 350 1 351
109 5 $old = $self->{$name};
110 5 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 4 1 5
111 4 $self->{$name} = $new;
112 }
113 }
114 elsif ( $name eq 'DESTROY' ) {
115 }
116 else {
117 1 Carp::croak(
118 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
119 );
120 }
121 355 return $old;
122 }
123  
124 479 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=8 SCAR=20.8
Pod undocumented
125 479 my ($self) = @_;
126 479 my $json = {
127 mimeType => $self->mime_type(),
128 size => $self->size(),
129 };
130 479 ▶ if ( defined $self->compression() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->compression) 37 442 479
131 37 $json->{compression} = $self->compression();
132 }
133 479 ▶ if ( defined $self->text() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->text) 81 398 479
134 81 $json->{text} = $self->text();
135 }
136 479 ▶ if ( defined $self->encoding() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->encoding) 24 455 479
137 24 $json->{encoding} = $self->encoding();
138 }
139 479 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 39 440 479
140 39 $json->{comment} = $self->comment();
141 }
142 479 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
143 1161 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 45 1116 1161
144 1116 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 21 1095 1116
145 21 $json->{$key} = $self->{$key};
146 }
147 }
148 479 return $json;
149 }
150  
151 10 1;
152 __END__
« Har/Page/PageTimings.pm ↑ Summary Har/Browser.pm »