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