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