| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Archive::Har::Entry::Request::PostData; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 18 |  | 
| 5 | 1 |  |  | 1 |  | 6 | use Carp(); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 15 |  | 
| 6 | 1 |  |  | 1 |  | 631 | use Archive::Har::Entry::Request::PostData::Params(); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 897 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = 0.19; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub new { | 
| 11 | 0 |  |  | 0 | 1 |  | my ( $class, $params ) = @_; | 
| 12 | 0 |  |  |  |  |  | my $self = {}; | 
| 13 | 0 |  |  |  |  |  | bless $self, $class; | 
| 14 | 0 | 0 |  |  |  |  | if ( defined $params ) { | 
| 15 | 0 |  |  |  |  |  | $self->mime_type( $params->{mimeType} ); | 
| 16 | 0 | 0 | 0 |  |  |  | if (   ( defined $params->{params} ) | 
|  |  | 0 | 0 |  |  |  |  | 
| 17 |  |  |  |  |  |  | && ( ref $params->{params} eq 'ARRAY' ) | 
| 18 | 0 |  |  |  |  |  | && ( scalar @{ $params->{params} } > 0 ) ) | 
| 19 |  |  |  |  |  |  | { | 
| 20 | 0 |  |  |  |  |  | my @params; | 
| 21 | 0 |  |  |  |  |  | foreach my $param ( @{ $params->{params} } ) { | 
|  | 0 |  |  |  |  |  |  | 
| 22 | 0 |  |  |  |  |  | push @params, | 
| 23 |  |  |  |  |  |  | Archive::Har::Entry::Request::PostData::Params->new($param); | 
| 24 |  |  |  |  |  |  | } | 
| 25 | 0 |  |  |  |  |  | $self->params( \@params ); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  | elsif ( defined $params->{text} ) { | 
| 28 | 0 |  |  |  |  |  | $self->text( $params->{text} ); | 
| 29 |  |  |  |  |  |  | } | 
| 30 | 0 | 0 |  |  |  |  | if ( defined $params->{comment} ) { | 
| 31 | 0 |  |  |  |  |  | $self->comment( $params->{comment} ); | 
| 32 |  |  |  |  |  |  | } | 
| 33 | 0 |  |  |  |  |  | foreach my $key ( sort { $a cmp $b } keys %{$params} ) { | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 34 | 0 | 0 |  |  |  |  | if ( $key =~ /^_[[:alnum:]]+$/smx ) {    # private fields | 
| 35 | 0 |  |  |  |  |  | $self->$key( $params->{$key} ); | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | } | 
| 39 | 0 |  |  |  |  |  | return $self; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub mime_type { | 
| 43 | 0 |  |  | 0 | 1 |  | my ( $self, $new ) = @_; | 
| 44 | 0 |  |  |  |  |  | my $old = $self->{mimeType}; | 
| 45 | 0 | 0 |  |  |  |  | if ( @_ > 1 ) { | 
| 46 | 0 |  |  |  |  |  | $self->{mimeType} = $new; | 
| 47 |  |  |  |  |  |  | } | 
| 48 | 0 |  |  |  |  |  | return $old; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub text { | 
| 52 | 0 |  |  | 0 | 1 |  | my ( $self, $new ) = @_; | 
| 53 | 0 |  |  |  |  |  | my $old = $self->{text}; | 
| 54 | 0 | 0 |  |  |  |  | if ( @_ > 1 ) { | 
| 55 | 0 |  |  |  |  |  | delete $self->{params}; | 
| 56 | 0 |  |  |  |  |  | $self->{text} = $new; | 
| 57 |  |  |  |  |  |  | } | 
| 58 | 0 |  |  |  |  |  | return $old; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | sub params { | 
| 62 | 0 |  |  | 0 | 1 |  | my ( $self, $new ) = @_; | 
| 63 | 0 |  |  |  |  |  | my $old = $self->{params}; | 
| 64 | 0 | 0 |  |  |  |  | if ( @_ > 1 ) { | 
| 65 | 0 |  |  |  |  |  | delete $self->{text}; | 
| 66 | 0 |  |  |  |  |  | $self->{params} = []; | 
| 67 | 0 | 0 | 0 |  |  |  | if ( ( defined $new ) && ( ref $new eq 'ARRAY' ) ) { | 
| 68 | 0 |  |  |  |  |  | foreach my $param ( @{$new} ) { | 
|  | 0 |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  |  | push @{ $self->{params} }, $param; | 
|  | 0 |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  | } | 
| 73 | 0 | 0 |  |  |  |  | if ( defined $old ) { | 
| 74 | 0 |  |  |  |  |  | return @{$old}; | 
|  | 0 |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  | else { | 
| 77 | 0 |  |  |  |  |  | return (); | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub comment { | 
| 82 | 0 |  |  | 0 | 1 |  | my ( $self, $new ) = @_; | 
| 83 | 0 |  |  |  |  |  | my $old = $self->{comment}; | 
| 84 | 0 | 0 |  |  |  |  | if ( @_ > 1 ) { | 
| 85 | 0 |  |  |  |  |  | $self->{comment} = $new; | 
| 86 |  |  |  |  |  |  | } | 
| 87 | 0 |  |  |  |  |  | return $old; | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub AUTOLOAD { | 
| 91 | 0 |  |  | 0 |  |  | my ( $self, $new ) = @_; | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 0 |  |  |  |  |  | my $name = $Archive::Har::Entry::Request::PostData::AUTOLOAD; | 
| 94 | 0 |  |  |  |  |  | $name =~ s/.*://smx;    # strip fully-qualified portion | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 0 |  |  |  |  |  | my $old; | 
| 97 | 0 | 0 |  |  |  |  | if ( $name =~ /^_[[:alnum:]]+$/smx ) {    # private fields | 
| 98 | 0 |  |  |  |  |  | $old = $self->{$name}; | 
| 99 | 0 | 0 |  |  |  |  | if ( @_ > 1 ) { | 
| 100 | 0 |  |  |  |  |  | $self->{$name} = $new; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  | else { | 
| 104 | 0 |  |  |  |  |  | Carp::croak( | 
| 105 |  |  |  |  |  |  | "$name is not specified in the HAR 1.2 spec and does not start with an underscore" | 
| 106 |  |  |  |  |  |  | ); | 
| 107 |  |  |  |  |  |  | } | 
| 108 | 0 |  |  |  |  |  | return $old; | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | sub TO_JSON { | 
| 112 | 0 |  |  | 0 | 0 |  | my ($self) = @_; | 
| 113 | 0 |  |  |  |  |  | my $json = {}; | 
| 114 | 0 |  |  |  |  |  | $json->{mimeType} = $self->mime_type(); | 
| 115 | 0 |  |  |  |  |  | $json->{params}   = [ $self->params() ]; | 
| 116 | 0 | 0 |  |  |  |  | if ( defined $self->text() ) { | 
| 117 | 0 |  |  |  |  |  | $json->{text} = $self->text(); | 
| 118 |  |  |  |  |  |  | } | 
| 119 | 0 | 0 |  |  |  |  | if ( defined $self->comment() ) { | 
| 120 | 0 |  |  |  |  |  | $json->{comment} = $self->comment(); | 
| 121 |  |  |  |  |  |  | } | 
| 122 | 0 |  |  |  |  |  | foreach my $key ( sort { $a cmp $b } keys %{$self} ) { | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 123 | 0 | 0 |  |  |  |  | next if ( !defined $self->{$key} ); | 
| 124 | 0 | 0 |  |  |  |  | if ( $key =~ /^_[[:alnum:]]+$/smx ) {    # private fields | 
| 125 | 0 |  |  |  |  |  | $json->{$key} = $self->{$key}; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  | } | 
| 128 | 0 |  |  |  |  |  | return $json; | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | 1; | 
| 132 |  |  |  |  |  |  | __END__ |