| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 37 | $self->mime_type( $params->{mimeType} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 37 | ▶ | if ( ( defined $params->{params} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
defined $params->{"params"} and ref $params->{"params"} eq "ARRAY" and scalar @{$params->{"params"};} > 0
defined $params->{"params"} and ref $params->{"params"} eq "ARRAY"
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | delete $self->{text}; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | $self->{params} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | if ( ( defined $new ) && ( ref $new eq 'ARRAY' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $new and ref $new eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | foreach my $param ( @{$new} ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | push @{ $self->{params} }, $param; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 41 | ▶ | if ( defined $old ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | $old = $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | $json->{text} = $self->text(); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 30 | ▶ | if ( defined $self->comment() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 81 | ▶ | if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 21 | $json->{$key} = $self->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 30 | return $json; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||