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