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