| 1 | package Archive::Har::Entry::Header; | ||||||||||||||
| 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::Header(); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 10 | our $VERSION = '0.21'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 3211 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||
| 11 | 3211 | my ( $class, $params ) = @_; | |||||||||||||
| 12 | 3211 | my $self = {}; | |||||||||||||
| 13 | 3211 | bless $self, $class; | |||||||||||||
| 14 | 3211 | ▶ | if ( defined $params ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | 3149 | $self->name( $params->{name} ); | |||||||||||||
| 16 | 3149 | $self->value( $params->{value} ); | |||||||||||||
| 17 | 3149 | ▶ | if ( defined $params->{comment} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | 1 | $self->comment( $params->{comment} ); | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | 3149 | foreach my $key ( sort { $a cmp $b } keys %{$params} ) { | |||||||||||||
| 21 | 6298 | ▶ | if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | 1 | $self->$key( $params->{$key} ); | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | } | ||||||||||||||
| 25 | } | ||||||||||||||
| 26 | 3211 | return $self; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 11725 | ▶ | sub name { | ||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 30 | 11725 | my ( $self, $new ) = @_; | |||||||||||||
| 31 | 11725 | my $old = $self->{name}; | |||||||||||||
| 32 | 11725 | ▶ | if ( @_ > 1 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 3211 | $self->{name} = $new; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | 11725 | return $old; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 11725 | ▶ | sub value { | ||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 39 | 11725 | my ( $self, $new ) = @_; | |||||||||||||
| 40 | 11725 | my $old = $self->{value}; | |||||||||||||
| 41 | 11725 | ▶ | if ( @_ > 1 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 3211 | $self->{value} = $new; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | 11725 | return $old; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 8535 | ▶ | sub comment { | ||||||||||||
|
Subroutine
comment: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 48 | 8535 | my ( $self, $new ) = @_; | |||||||||||||
| 49 | 8535 | my $old = $self->{comment}; | |||||||||||||
| 50 | 8535 | ▶ | if ( @_ > 1 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 1 | $self->{comment} = $new; | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | 8535 | return $old; | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 3185 | ▶ | sub AUTOLOAD { | ||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=13.9
| |||||||||||||||
| 57 | 3185 | my ( $self, $new ) = @_; | |||||||||||||
| 58 | |||||||||||||||
| 59 | 3185 | my $name = $Archive::Har::Entry::Header::AUTOLOAD; | |||||||||||||
| 60 | 3185 | $name =~ s/.*://smx; # strip fully-qualified portion | |||||||||||||
| 61 | |||||||||||||||
| 62 | 3185 | my $old; | |||||||||||||
| 63 | 3185 | ▶ | if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 64 | 4 | $old = $self->{$name}; | |||||||||||||
| 65 | 4 | ▶ | if ( @_ > 1 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | 3 | $self->{$name} = $new; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | } | ||||||||||||||
| 69 | elsif ( $name eq 'DESTROY' ) { | ||||||||||||||
| 70 | } | ||||||||||||||
| 71 | else { | ||||||||||||||
| 72 | 1 | Carp::croak( | |||||||||||||
| 73 | "$name is not specified in the HAR 1.2 spec and does not start with an underscore" | ||||||||||||||
| 74 | ); | ||||||||||||||
| 75 | } | ||||||||||||||
| 76 | 3184 | return $old; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 8512 | ▶ | sub TO_JSON { | ||||||||||||
|
Subroutine
TO_JSON: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||
| 80 | 8512 | my ($self) = @_; | |||||||||||||
| 81 | 8512 | my $json = {}; | |||||||||||||
| 82 | 8512 | $json->{name} = $self->name(); | |||||||||||||
| 83 | 8512 | $json->{value} = $self->value(); | |||||||||||||
| 84 | 8512 | ▶ | if ( defined $self->comment() ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | 22 | $json->{comment} = $self->comment(); | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | 8512 | foreach my $key ( sort { $a cmp $b } keys %{$self} ) { | |||||||||||||
| 88 | 17068 | ▶ | next if ( !defined $self->{$key} ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | 17023 | ▶ | if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 90 | 21 | $json->{$key} = $self->{$key}; | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | } | ||||||||||||||
| 93 | 8512 | return $json; | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | |||||||||||||||
| 96 | 10 | 1; | |||||||||||||
| 97 | __END__ | ||||||||||||||