| 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
| |||||||||||||||
| 14 | 347 | $self->size( $params->{size} ); | |||||||||||||
| 15 | 347 | $self->mime_type( $params->{mimeType} ); | |||||||||||||
| 16 | 347 | ▶ | if ( defined $params->{compression} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 17 | 74 | $self->compression( $params->{compression} ); | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | 347 | ▶ | if ( defined $params->{text} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | 119 | $self->text( $params->{text} ); | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | 347 | ▶ | if ( defined $params->{encoding} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | 48 | $self->encoding( $params->{encoding} ); | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | 347 | ▶ | if ( defined $params->{comment} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 41 | 352 | $self->{mimeType} = $new; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | 832 | ▶ | if ( defined $old ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 55 | 352 | $self->{size} = $new; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 832 | ▶ | if ( defined $old ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 109 | 5 | $old = $self->{$name}; | |||||||||||||
| 110 | 5 | ▶ | if ( @_ > 1 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 131 | 37 | $json->{compression} = $self->compression(); | |||||||||||||
| 132 | } | ||||||||||||||
| 133 | 479 | ▶ | if ( defined $self->text() ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 134 | 81 | $json->{text} = $self->text(); | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | 479 | ▶ | if ( defined $self->encoding() ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 137 | 24 | $json->{encoding} = $self->encoding(); | |||||||||||||
| 138 | } | ||||||||||||||
| 139 | 479 | ▶ | if ( defined $self->comment() ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 144 | 1116 | ▶ | if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 145 | 21 | $json->{$key} = $self->{$key}; | |||||||||||||
| 146 | } | ||||||||||||||
| 147 | } | ||||||||||||||
| 148 | 479 | return $json; | |||||||||||||
| 149 | } | ||||||||||||||
| 150 | |||||||||||||||
| 151 | 10 | 1; | |||||||||||||
| 152 | __END__ | ||||||||||||||