| 1 | package Badger::Period; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | use Badger::Class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | version => 0.01, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | debug => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | base => 'Badger::Comparable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | utils => 'numlike is_object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | accessors => 'uri', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | as_text => 'uri', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | is_true => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | constants => 'HASH ARRAY DELIMITER', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | constant => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | FIELD_NAMES => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | TYPE_NAME => 'period', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | messages => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | bad_type => 'Invalid %s: %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | bad_duration => 'Invalid duration: %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Time::Local; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use POSIX 'strftime'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | our @YMD = qw( year month day ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | our @HMS = qw( hour minute second ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | our @SMHD = qw( second minute hour day ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | our @YMDHMS = (@YMD, @HMS); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | our $SECONDS = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | s => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | m => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | h => 60*60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | d => 60*60*24, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | M => 60*60*24*30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | y => 60*60*24*365, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub split_regex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_regex: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | shift->not_implemented; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub join_format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join_format: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | shift->not_implemented; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub text_format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | shift->join_format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 28 | ▶ | sub field_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field_names: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 28 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 28 | ▶ | my $names = $class->FIELD_NAMES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$class->FIELD_NAMES || (return $class->not_implemented)
MC/DC0%0/1
$class->FIELD_NAMES || (return $class->not_implemented)
$class->FIELD_NAMES
Truth table50%1/2
A
A= $class->FIELD_NAMES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | || return $class->not_implemented; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 28 | ▶ | $names = [ split(DELIMITER, $names) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | unless ref $names eq ARRAY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 28 | ▶ | ? @$names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | : \@$names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | my @fields = $class->field_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | ▶ | my $self = bless { map { ($_, 0) } @fields }, ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | my ($config, $time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # multiple arguments are named params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $config = { @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ▶ | elsif (@_ == 1 && defined $_[0]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
@_ == 1 and defined $_[0]
MC/DC50%1/2
@_ == 1 and defined $_[0]
@_ == 1
defined $_[0]
Truth table66%2/3
A and B
A= @_ == 1B= defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # single argument is a hash of named params, a timestamp or time in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # seconds since the epoch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | $config = ref $_[0] eq HASH ? shift : { time => shift }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # otherwise we default to now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | $config = { time => time() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | ▶ | if ($time = $config->{ time }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | if (numlike $time) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # $time is seconds since epoch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | (@$config{ @YMDHMS }) = reverse( ( localtime($time) )[0..5] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | $config->{ year }+= 1900; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | $config->{ month }++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | $config->{ etime } = $time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ▶ | elsif (is_object(ref $class || $class, $time)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $config->{ uri } = $time->uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $config->{ etime } = $time->epoch_time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->split_uri($config->{ uri }, $config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # $time is a timestamp so split and rejoin into canonical form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | $config->{ uri } = $time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | $self->split_uri($config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | $self->join_uri($config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # set any fields defined in config, allowing singular (second,month, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # etc) and plural (seconds, months, etc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | foreach my $field (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 12 | ▶ | $self->{ $field } = $config->{ $field } || $config->{"${field}s"} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$config->{$field} || $$config{"${field}s"} || 0
$config->{$field} or $$config{"${field}s"}
MC/DC0%0/2
$config->{$field} || $$config{"${field}s"} || 0
$config->{$field}
$$config{"${field}s"}
Truth table33%1/3
A or B
A= $config->{$field}B= $$config{"${field}s"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | $self->join_uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | sub copy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $self->new( $self->{ uri } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | ▶ | sub split_uri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_uri: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | ▶ | my $target = shift || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self
MC/DC0%0/2
shift() || $self
shift()
$self
Truth table33%1/3
A || B
A= shift()B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | my $regex = $self->split_regex; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | my @fields = $self->field_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | ▶ | $target->{ uri } = '' unless defined $target->{ uri }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | (@$target{ @fields } = map { 0+$_ } $target->{ uri } =~ m/$regex/o) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | || return $self->error_msg( bad_type => $self->TYPE_NAME, $target->{ uri } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | ▶ | sub join_uri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join_uri: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | ▶ | my $target = shift || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self
MC/DC0%0/2
shift() || $self
shift()
$self
Truth table66%2/3
A || B
A= shift()B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | my @fields = $self->field_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | return ($target->{ uri } = sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | $self->join_format, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 27 | ▶ | map { defined $_ ? $_ : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 9 | @$target{ @fields } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub epoch_time { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
epoch_time: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | return $self->{ etime } ||= timelocal( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"etime"} ||= timelocal($self->posix_args)
MC/DC0%0/2
$self->{"etime"} ||= timelocal($self->posix_args)
$self->{"etime"}
timelocal($self->posix_args)
Truth table0%0/3
A ||= B
A= $self->{"etime"}B= timelocal($self->posix_args)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | $self->posix_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | sub posix_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
posix_args: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | map { $self->{ $_ } || 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->{$_} || 0
$self->{'month'} || 1
$self->{'year'} || 1900
MC/DC100%1/1
$self->{$_} || 0
$self->{$_}
MC/DC0%0/1
$self->{'month'} || 1
$self->{'month'}
MC/DC0%0/1
$self->{'year'} || 1900
$self->{'year'}
Truth table100%2/2
A
A= $self->{$_}
Truth table50%1/2
A
A= $self->{'month'}
Truth table50%1/2
A
A= $self->{'year'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | @SMHD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ($self->{ month } || 1) - 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | ($self->{ year } || 1900) - 1900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | sub format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | my $fmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | return strftime( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | $fmt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | $self->posix_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | sub text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | my @fields = $self->field_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | return $self->{ text } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | ||= sprintf( $self->text_format, @$self{ @fields } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"text"} ||= sprintf($self->text_format, @$self{@fields})
MC/DC0%0/2
$self->{"text"} ||= sprintf($self->text_format, @$self{@fields})
$self->{"text"}
sprintf($self->text_format, @$self{@fields})
Truth table33%1/3
A ||= B
A= $self->{"text"}B= sprintf($self->text_format, @$self{@fields})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub duration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
duration: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my ($self, $duration) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # $duration can be a number, assumed to be seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | return $duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | if numlike($duration); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Otherwise the $duration should be of the form "3 minutes". We only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # look at the first character of the word (e.g. "3 m"), which creates a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # potential conflict between "m(inute) and m(onth)". So we use a capital | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # 'M' for month. This is based on code by Mark Fisher in CGI.pm. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $duration =~ s/month/Month/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # TODO: make this parser a bit smarter so we can support multiple | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # items (e.g. "2 hours 30 minutes") as per adjust() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ($duration =~ /^ ( -? (?: \d+ | \d*\.\d+ ) ) \s* ([smhdMy]?) /x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return ($SECONDS->{ $2 } || 1) * $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$Badger::Period::SECONDS->{$2} || 1
MC/DC0%0/1
$Badger::Period::SECONDS->{$2} || 1
$Badger::Period::SECONDS->{$2}
Truth table0%0/2
A
A= $Badger::Period::SECONDS->{$2}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return $self->error_msg( bad_duration => $duration ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 10 | ▶ | sub compare { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare: called CC=10 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 10 | my @fields = $self->field_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # optimisation: if the $self object has an epoch time and a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # numerical argument is passed (also an epoch time) then we can do a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # simple comparison | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | return $self->{ etime } <=> $_[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | if $self->{ etime } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 10 | ▶ | && @_ == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->{"etime"} and @_ == 1 and &numlike($_[0])
$self->{"etime"} and @_ == 1
MC/DC0%0/3
$self->{"etime"} and @_ == 1 and &numlike($_[0])
$self->{"etime"}
@_ == 1
&numlike($_[0])
Truth table25%1/4
A and B and C
A= $self->{"etime"}B= @_ == 1C= &numlike($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | && numlike $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # otherwise we upgrade any argument(s) to another timestamp and comare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # them piecewise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 10 | ▶ | my $comp = @_ && is_object(ref $self || $self, $_[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@_ and &is_object(scalar(ref $self || $self), $_[0])
ref $self || $self
MC/DC0%0/2
@_ and &is_object(scalar(ref $self || $self), $_[0])
@_
&is_object(scalar(ref $self || $self), $_[0])
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A and B
A= @_B= &is_object(scalar(ref $self || $self), $_[0])
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ? shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | : $self->new(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 10 | foreach my $item (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 30 | ▶ | if ($self->{ $item } < $comp->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 5 | return -1; # -1 - self earlier than comparison timestamp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | elsif ($self->{ $item } > $comp->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | return 1; # 1 - self later than comparison timestamp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return 0; # 0 - same time | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | ▶ | sub days_in_month { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
days_in_month: called CC=8 SCAR=31.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | ▶ | my $month = shift || $self->{ month }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'month'}
MC/DC0%0/2
shift() || $self->{'month'}
shift()
$self->{'month'}
Truth table33%1/3
A || B
A= shift()B= $self->{'month'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | if ($month == 4 || $month == 6 || $month == 9 || $month == 11) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%3/9
$month == 4 or $month == 6 or $month == 9 or $month == 11
$month == 4 or $month == 6 or $month == 9
$month == 4 or $month == 6
MC/DC0%0/4
$month == 4 or $month == 6 or $month == 9 or $month == 11
$month == 4
$month == 6
$month == 9
$month == 11
Truth table20%1/5
A or B or C or D
A= $month == 4B= $month == 6C= $month == 9D= $month == 11
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | return 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | elsif ($month == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | return $self->leap_year(@_) ? 29 : 28; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | return 31; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub leap_year { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leap_year: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my $year = shift || $self->{ year }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $self->{'year'}
MC/DC0%0/2
shift() || $self->{'year'}
shift()
$self->{'year'}
Truth table0%0/3
A || B
A= shift()B= $self->{'year'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ($year % 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | elsif ($year % 400 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | elsif ($year % 100 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||