| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## DateTime Format Lite - ~/lib/DateTime/Format/Lite.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.1.3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2026/04/14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2026/04/23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ## All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | package DateTime::Format::Lite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use v5.10.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | ▶ | use warnings::register; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | ▶ | use vars qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $VERSION $ERROR $FATAL_EXCEPTIONS $IsPurePerl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 12 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 12 | ▶ | use DateTime::Lite (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 12 | ▶ | use DateTime::Lite::TimeZone (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | use DateTime::Locale::FromCLDR (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 12 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 12 | ▶ | use Locale::Unicode (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 12 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 12 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 12 | ▶ | use Wanted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 12 | our $VERSION = 'v0.1.3'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 12 | our @EXPORT_OK = qw( strptime strftime ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | our $IsPurePerl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # NOTE: Load XS; fall back to pure-Perl implementations if unavailable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 12 | my $loaded = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 12 | ▶ | unless( $ENV{PERL_DATETIME_FORMAT_LITE_PP} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 12 | ▶ | local $SIG{__WARN__} = sub{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 12 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 12 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 12 | require XSLoader; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | XSLoader::load( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 12 | exists( $DateTime::Format::Lite::{VERSION} ) && ${ $DateTime::Format::Lite::{VERSION} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 12 | ▶ | ? ${ $DateTime::Format::Lite::{VERSION} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $DateTime::Format::Lite::{"VERSION"} and ${$DateTime::Format::Lite::{"VERSION"};}
MC/DC0%0/2
exists $DateTime::Format::Lite::{"VERSION"} and ${$DateTime::Format::Lite::{"VERSION"};}
exists $DateTime::Format::Lite::{"VERSION"}
${$DateTime::Format::Lite::{"VERSION"};}
Truth table33%1/3
A and B
A= exists $DateTime::Format::Lite::{"VERSION"}B= ${$DateTime::Format::Lite::{"VERSION"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | : 42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | $loaded = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | $IsPurePerl = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | die( $@ ) if( $@ && $@ !~ /object version|loadable object/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ and not $@ =~ /object version|loadable object/
MC/DC0%0/2
$@ and not $@ =~ /object version|loadable object/
$@
not $@ =~ /object version|loadable object/
Truth table0%0/3
A and not(B)
A= $@B= not $@ =~ /object version|loadable object/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | unless( $loaded ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | require DateTime::Format::Lite::PP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $IsPurePerl = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Fields captured during parsing that cannot be passed directly to DateTime::Lite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # constructors, so they require munging in _munge_args first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | my @NON_DT_KEYS = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | am_pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | century | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | day_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | day_of_week | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | day_of_week_sun_0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | hour_12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | iso_week_year | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | iso_week_year_100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | month_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | time_zone_abbreviation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | time_zone_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | time_zone_offset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | week_mon_1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | week_sun_0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | year_100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Locale-independent token table. Locale-dependent tokens (%a/%A, %b/%B/%h, %p/%P) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # are built per-object in _parser_pieces() since they depend on the locale's day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # and month names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 12 | my $DIGIT = qr/(?:[0-9])/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 12 | my $ONE_OR_TWO_DIGITS = qr/[0-9 ]?$DIGIT/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | my %UNIVERSAL_PATTERNS = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | '%' => { regex => qr/%/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | C => { regex => $ONE_OR_TWO_DIGITS, field => 'century' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | d => { regex => $ONE_OR_TWO_DIGITS, field => 'day' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | e => { regex => $ONE_OR_TWO_DIGITS, field => 'day' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | g => { regex => $ONE_OR_TWO_DIGITS, field => 'iso_week_year_100' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | G => { regex => qr/$DIGIT{4}/, field => 'iso_week_year' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | H => { regex => $ONE_OR_TWO_DIGITS, field => 'hour' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | I => { regex => $ONE_OR_TWO_DIGITS, field => 'hour_12' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | k => { regex => $ONE_OR_TWO_DIGITS, field => 'hour' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | l => { regex => $ONE_OR_TWO_DIGITS, field => 'hour_12' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | j => { regex => qr/$DIGIT{1,3}/, field => 'day_of_year' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | m => { regex => $ONE_OR_TWO_DIGITS, field => 'month' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | M => { regex => $ONE_OR_TWO_DIGITS, field => 'minute' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | n => { regex => qr/\s+/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | t => { regex => qr/\s+/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | O => { regex => qr{[a-zA-Z_]+(?:/[a-zA-Z_]+(?:/[a-zA-Z_]+)?)?}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | field => 'time_zone_name' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | s => { regex => qr/-?$DIGIT+/, field => 'epoch' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | S => { regex => $ONE_OR_TWO_DIGITS, field => 'second' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | U => { regex => $ONE_OR_TWO_DIGITS, field => 'week_sun_0' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | u => { regex => $ONE_OR_TWO_DIGITS, field => 'day_of_week' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | w => { regex => $ONE_OR_TWO_DIGITS, field => 'day_of_week_sun_0' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | W => { regex => $ONE_OR_TWO_DIGITS, field => 'week_mon_1' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | y => { regex => $ONE_OR_TWO_DIGITS, field => 'year_100' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | Y => { regex => qr/$DIGIT{4}/, field => 'year' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | z => { regex => qr/(?:Z|[+-]$DIGIT{2}(?:[:]?$DIGIT{2})?)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | field => 'time_zone_offset' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | Z => { regex => qr{[a-zA-Z]{1,6}(?:/[a-zA-Z_]+(?:/[a-zA-Z_]+)?)?|[\-\+]$DIGIT{2}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | field => 'time_zone_abbreviation' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Compound tokens expanded before the main token pass (up to 2 rounds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 12 | my %UNIVERSAL_REPLACEMENTS = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | D => '%m/%d/%y', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | F => '%Y-%m-%d', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | r => '%I:%M:%S %p', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | R => '%H:%M', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | T => '%H:%M:%S', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # NOTE: subroutine pre-declaration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # for sub in `perl -ln -E 'say "$1" if( /^sub (\w+)[[:blank:]\v]*(?:\{|\Z|[[:blank:]\v]*:[[:blank:]\v]*lvalue)/ )' ./lib/DateTime/Format/Lite.pm | LC_COLLATE=C sort -uV`; do echo "sub $sub;"; done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | sub FREEZE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub STORABLE_freeze; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | sub STORABLE_thaw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | sub THAW; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | sub TO_JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | sub debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | sub error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | sub fatal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | sub format_datetime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | sub format_duration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | sub locale; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | sub new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | sub on_error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | sub parse_datetime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | sub parse_duration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | sub pass_error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | sub strftime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | sub strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | sub strptime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | sub time_zone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | sub zone_map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | sub _build_parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub _check_dt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | sub _locale_days; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | sub _locale_months; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | sub _munge_args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | sub _on_error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | sub _parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | sub _parser_pieces; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | sub _restore_state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | sub _serialise_state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | sub _set_get_prop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | sub _token_re_for; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 227 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 227 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 227 | ▶ | my $class = ref( $this ) || $this; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 227 | my %p = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 227 | ▶ | unless( defined( $p{pattern} ) && length( $p{pattern} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $p{"pattern"} and length $p{"pattern"}
MC/DC50%1/2
defined $p{"pattern"} and length $p{"pattern"}
defined $p{"pattern"}
length $p{"pattern"}
Truth table66%2/3
A and B
A= defined $p{"pattern"}B= length $p{"pattern"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | return( $class->error( "Parameter 'pattern' is required for ", __PACKAGE__, "::new()." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | my $self = bless( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 226 | ▶ | debug => $ENV{DATETIME_FORMAT_LITE_DEBUG} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"DATETIME_FORMAT_LITE_DEBUG"} // 0
MC/DC0%0/1
$ENV{"DATETIME_FORMAT_LITE_DEBUG"} // 0
$ENV{"DATETIME_FORMAT_LITE_DEBUG"}
Truth table50%1/2
A
A= $ENV{"DATETIME_FORMAT_LITE_DEBUG"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | locale => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | on_error => 'undef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | pattern => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | strict => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | time_zone => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | zone_map => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Internal caches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | _parser => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | _locale_days => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | _locale_months => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | }, $class ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Process each parameter through its accessor for validation and coercion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 226 | foreach my $param ( qw( debug locale on_error pattern strict time_zone zone_map ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1582 | ▶ | next unless( exists( $p{ $param } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 652 | ▶ | $self->$param( $p{ $param } ) // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->$param($p{$param}) // (return $class->pass_error($self->error))
MC/DC0%0/1
$self->$param($p{$param}) // (return $class->pass_error($self->error))
$self->$param($p{$param})
Truth table50%1/2
A
A= $self->$param($p{$param})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | return( $class->pass_error( $self->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Force compilation at construction time to catch invalid patterns early | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | $self->_parser || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 226 | ▶ | return( $class->pass_error( $self->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 225 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | sub debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 27 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 27 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 27 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 17 | ▶ | $self->{debug} = $_[0] ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 17 | ▶ | if( $self->{debug} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # Ensure STDERR handles UTF-8 when debug output is enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | binmode( STDERR, ':encoding(UTF-8)' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 27 | return( $self->{debug} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # NOTE: Error handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | sub error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 65 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 65 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 65 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 34 | require DateTime::Format::Lite::Exception; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 34 | ▶ | my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 34 | my $e = DateTime::Format::Lite::Exception->new({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | skip_frames => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | message => $msg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 34 | $ERROR = $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 34 | ▶ | $self->{error} = $e if( ref( $self ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 34 | ▶ | if( $self->fatal ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | die( $self->{error} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 34 | ▶ | warn( $msg ) if( warnings::enabled() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 34 | ▶ | rreturn( DateTime::Format::Lite::NullObject->new ) if( want( 'OBJECT' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 33 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 31 | ▶ | return( ref( $self ) ? $self->{error} : $ERROR ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | sub fatal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 34 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: called CC=5 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 34 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 34 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if( ref( $this ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return( $this->_set_get_prop( 'fatal', @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | warn( "Cannot call fatal in mutator mode as a class method." ) if( warnings::enabled() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 34 | ▶ | return( ref( $this ) ? $this->_set_get_prop( 'fatal' ) : $FATAL_EXCEPTIONS ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | sub format_datetime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | my $dt = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | unless( defined( $dt ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | Scalar::Util::blessed( $dt ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | $dt->isa( 'DateTime::Lite' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | return( $self->error( "A DateTime::Lite object is required for format_datetime()." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # XS path: delegates to strftime without clone() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | unless( $IsPurePerl ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | return( DateTime::Format::Lite::format_datetime( $self, $dt ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # Pure-Perl fallback: strftime is already XS-accelerated in DateTime::Lite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | return( $dt->strftime( $self->{pattern} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | sub format_duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_duration: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $dur = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | unless( defined( $dur ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $dur and builtin::blessed($dur) and $dur->isa("DateTime::Lite::Duration")
defined $dur and builtin::blessed($dur)
MC/DC0%0/3
defined $dur and builtin::blessed($dur) and $dur->isa("DateTime::Lite::Duration")
defined $dur
builtin::blessed($dur)
$dur->isa("DateTime::Lite::Duration")
Truth table0%0/4
A and B and C
A= defined $durB= builtin::blessed($dur)C= $dur->isa("DateTime::Lite::Duration")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | Scalar::Util::blessed( $dur ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | $dur->isa( 'DateTime::Lite::Duration' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return( $self->error( "A DateTime::Lite::Duration object is required for format_duration()." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $str = 'P'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | $str .= $dur->years . 'Y' if( $dur->years ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | $str .= $dur->months . 'M' if( $dur->months ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $str .= $dur->days . 'D' if( $dur->days ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $time = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | $time .= $dur->hours . 'H' if( $dur->hours ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | $time .= $dur->minutes . 'M' if( $dur->minutes ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $time .= $dur->seconds . 'S' if( $dur->seconds ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | $str .= 'T' . $time if( length( $time ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # Edge case: zero duration -> PT0S | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $str = 'PT0S' if( $str eq 'P' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | return( $str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | sub locale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1198 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
locale: called CC=11 SCAR=31.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1198 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1198 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 116 | my $locale = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 116 | ▶ | if( !defined( $locale ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # Default to English | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $self->{locale} = DateTime::Locale::FromCLDR->new( 'en' ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
'DateTime::Locale::FromCLDR'->new('en') || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new('en') || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
'DateTime::Locale::FromCLDR'->new('en')
Truth table0%0/2
A
A= 'DateTime::Locale::FromCLDR'->new('en')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | return( $self->pass_error( DateTime::Locale::FromCLDR->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | elsif( Scalar::Util::blessed( $locale ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | unless( $locale->isa( 'DateTime::Locale::FromCLDR' ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$locale->isa("DateTime::Locale::FromCLDR") or $locale->isa("Locale::Unicode")
MC/DC0%0/2
$locale->isa("DateTime::Locale::FromCLDR") or $locale->isa("Locale::Unicode")
$locale->isa("DateTime::Locale::FromCLDR")
$locale->isa("Locale::Unicode")
Truth table0%0/3
A or B
A= $locale->isa("DateTime::Locale::FromCLDR")B= $locale->isa("Locale::Unicode")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | $locale->isa( 'Locale::Unicode' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return( $self->error( "Locale object must be a DateTime::Locale::FromCLDR or Locale::Unicode instance, got: ", ref( $locale ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $self->{locale} = $locale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | elsif( ref( $locale ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return( $self->error( "locale must be a string or object, got an unblessed reference: ", ref( $locale ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 116 | ▶ | $self->{locale} = DateTime::Locale::FromCLDR->new( $locale ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
'DateTime::Locale::FromCLDR'->new($locale)
Truth table50%1/2
A
A= 'DateTime::Locale::FromCLDR'->new($locale)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | return( $self->pass_error( DateTime::Locale::FromCLDR->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Invalidate locale-dependent caches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 116 | $self->{_parser} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 116 | $self->{_locale_days} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 116 | $self->{_locale_months} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # Initialise lazily on first access | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1198 | ▶ | unless( defined( $self->{locale} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 116 | ▶ | $self->{locale} = DateTime::Locale::FromCLDR->new( 'en' ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'DateTime::Locale::FromCLDR'->new('en') || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new('en') || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
'DateTime::Locale::FromCLDR'->new('en')
Truth table50%1/2
A
A= 'DateTime::Locale::FromCLDR'->new('en')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | return( $self->pass_error( DateTime::Locale::FromCLDR->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1198 | return( $self->{locale} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | sub on_error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 228 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_error: called CC=7 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 228 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 228 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 228 | my $val = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 228 | ▶ | if( ref( $val ) eq 'CODE' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 22 | $self->{on_error} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | ▶ | elsif( defined( $val ) && ( $val eq 'croak' || $val eq 'die' || $val eq 'undef' ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
defined $val and $val eq "croak" || $val eq "die" || $val eq "undef"
$val eq "croak" or $val eq "die" or $val eq "undef"
$val eq "croak" or $val eq "die"
MC/DC0%0/4
defined $val and $val eq "croak" || $val eq "die" || $val eq "undef"
defined $val
$val eq "croak"
$val eq "die"
$val eq "undef"
Truth table40%2/5
A and B or C or D
A= defined $valB= $val eq "croak"C= $val eq "die"D= $val eq "undef"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 206 | $self->{on_error} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | return( $self->error( "on_error must be 'croak', 'die', 'undef', or a code reference." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 228 | return( $self->{on_error} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | sub parse_datetime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 209 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_datetime: called CC=20 SCAR=37.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 209 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 209 | my $string = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 209 | ▶ | if( !defined( $string ) || ( defined( $string ) && !length( $string // '' ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition37%3/8
not defined $string or defined $string and not length($string // "")
defined $string and not length($string // "")
$string // ""
MC/DC0%0/3
not defined $string or defined $string and not length($string // "")
not defined $string
defined $string
$string
Truth table25%1/4
not(A) or B and not(C)
A= not defined $stringB= defined $stringC= $string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return( $self->error( "A string to parse is required for parse_datetime()." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 209 | ▶ | my $parser = $self->_parser || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_parser || (return $self->pass_error)
MC/DC0%0/1
$self->_parser || (return $self->pass_error)
$self->_parser
Truth table50%1/2
A
A= $self->_parser
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 209 | ▶ | if( $self->{debug} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | warn( "Regex for $self->{pattern}: $parser->{regex}\nFields: @{$parser->{fields}}\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 209 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 209 | ▶ | if( $IsPurePerl ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my @matches = ( $string =~ $parser->{regex} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | unless( @matches ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | return( $self->_on_error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 'Your datetime does not match your pattern' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | . ( $self->{debug} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | ? qq{ - string="$string" regex=$parser->{regex}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | . '.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | foreach my $f ( @{$parser->{fields}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $args{ $f } = $matches[ $i++ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # XS _match_and_extract returns a hashref or undef on no match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | my $extracted = DateTime::Format::Lite::_match_and_extract( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | $parser->{regex}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | $parser->{fields}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 209 | $string, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 209 | ▶ | unless( defined( $extracted ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | return( $self->_on_error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 'Your datetime does not match your pattern' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | . ( $self->{debug} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 12 | ▶ | ? qq{ - string="$string" regex=$parser->{regex}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | . '.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 197 | %args = %$extracted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # _munge_args modifies a copy of %args; pass a copy to preserve original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 197 | my( $constructor, $args, $post_construct ) = $self->_munge_args( {%args} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 197 | ▶ | return( $self->pass_error ) unless( $constructor && $args ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$constructor and $args
MC/DC50%1/2
$constructor and $args
$constructor
$args
Truth table66%2/3
A and B
A= $constructorB= $args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 187 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 187 | my $dt = eval{ DateTime::Lite->$constructor( %$args ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 187 | ▶ | if( $@ || !$dt ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ or not $dt
MC/DC50%1/2
$@ or not $dt
$@
not $dt
Truth table66%2/3
A or not(B)
A= $@B= not $dt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 2 | return( $self->_on_error( 'Parsed values did not produce a valid datetime.' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 185 | ▶ | $post_construct->( $dt ) if( $post_construct ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 185 | ▶ | return( $self->pass_error ) unless( $self->_check_dt( $dt, \%args ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 157 | ▶ | $dt->set_time_zone( $self->{time_zone} ) if( $self->{time_zone} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 157 | return( $dt ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | sub parse_duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_duration: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my $string = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if( !defined( $string ) || ( defined( $string ) && !length( $string // '' ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
not defined $string or defined $string and not length($string // "")
defined $string and not length($string // "")
$string // ""
MC/DC0%0/3
not defined $string or defined $string and not length($string // "")
not defined $string
defined $string
$string
Truth table0%0/4
not(A) or B and not(C)
A= not defined $stringB= defined $stringC= $string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | return( $self->error( "A string to parse is required for parse_duration()." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # ISO 8601 duration: PnYnMnDTnHnMnS (decimal fractions allowed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | unless( $string =~ /\A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | P | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | (?:(\d+(?:[.,]\d+)?)Y)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | (?:(\d+(?:[.,]\d+)?)M)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | (?:(\d+(?:[.,]\d+)?)W)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | (?:(\d+(?:[.,]\d+)?)D)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | (?:T | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | (?:(\d+(?:[.,]\d+)?)H)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | (?:(\d+(?:[.,]\d+)?)M)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | (?:(\d+(?:[.,]\d+)?)S)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | \z/x ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | return( $self->_on_error( "String '$string' does not match the ISO 8601 duration format." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | my( $years, $months, $weeks, $days, $hours, $minutes, $seconds ) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | map{ defined( $_ ) ? do{ ( my $v = $_ ) =~ s/,/./; $v + 0 } : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | ( $1, $2, $3, $4, $5, $6, $7 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # Fold weeks into days (ISO 8601 weeks are always exactly 7 days) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $days += $weeks * 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | return( DateTime::Lite::Duration->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | years => $years, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | months => $months, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | days => $days, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | hours => $hours, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | minutes => $minutes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | seconds => $seconds, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | sub pass_error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 40 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pass_error: called CC=38 SCAR=52.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 40 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 40 | ▶ | my $pack = ref( $self ) || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 40 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 40 | my( $err, $class, $code ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 12 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 40 | ▶ | if( scalar( @_ ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # Either an hash defining a new error and this will be passed along to error(); or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # an hash with a single property: { class => 'Some::ExceptionClass' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | ▶ | if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $opts = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | ▶ | if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
MC/DC0%0/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1
ref $_[-1] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $opts = pop( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 1 | $err = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 40 | ▶ | $err = $opts->{error} if( !defined( $err ) && CORE::exists( $opts->{error} ) && defined( $opts->{error} ) && CORE::length( $opts->{error} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
not defined $err and exists $opts->{"error"} and defined $opts->{"error"}
not defined $err and exists $opts->{"error"}
MC/DC0%0/4
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
not defined $err
exists $opts->{"error"}
defined $opts->{"error"}
length $opts->{"error"}
Truth table40%2/5
not(A) and B and C and D
A= not defined $errB= exists $opts->{"error"}C= defined $opts->{"error"}D= length $opts->{"error"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # We set $class only if the hash provided is a one-element hash and not an error-defining hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 40 | ▶ | $class = $opts->{class} if( CORE::exists( $opts->{class} ) && defined( $opts->{class} ) && CORE::length( $opts->{class} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
exists $opts->{"class"} and defined $opts->{"class"}
MC/DC0%0/3
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
exists $opts->{"class"}
defined $opts->{"class"}
length $opts->{"class"}
Truth table25%1/4
A and B and C
A= exists $opts->{"class"}B= defined $opts->{"class"}C= length $opts->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 40 | ▶ | $code = $opts->{code} if( CORE::exists( $opts->{code} ) && defined( $opts->{code} ) && CORE::length( $opts->{code} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
exists $opts->{"code"} and defined $opts->{"code"}
MC/DC0%0/3
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
exists $opts->{"code"}
defined $opts->{"code"}
length $opts->{"code"}
Truth table25%1/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length $opts->{"code"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # called with no argument, most likely from the same class to pass on an error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # set up earlier by another method; or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # with an hash containing just one argument class => 'Some::ExceptionClass' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 40 | ▶ | if( !defined( $err ) && ( !scalar( @_ ) || defined( $class ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
not defined $err and !scalar(@_) || defined $class
not scalar @_ or defined $class
MC/DC33%1/3
not defined $err and !scalar(@_) || defined $class
not defined $err
not scalar @_
defined $class
Truth table50%2/4
not(A) and not(B) or C
A= not defined $errB= not scalar @_C= defined $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # $error is a previous erro robject | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | my $error = ref( $self ) ? $self->{error} : length( ${ $pack . '::ERROR' } ) ? ${ $pack . '::ERROR' } : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 39 | ▶ | if( !defined( $error ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 18 | warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 21 | ▶ | $err = ( defined( $class ) ? bless( $error => $class ) : $error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 21 | ▶ | $err->code( $code ) if( defined( $code ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | ▶ | elsif( defined( $err ) && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%3/12
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class
defined $err and builtin::blessed($err)
scalar @_ == 1 or scalar @_ == 2 and defined $class
scalar @_ == 2 and defined $class
MC/DC0%0/5
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class
defined $err
builtin::blessed($err)
scalar @_ == 1
scalar @_ == 2
defined $class
Truth table16%1/6
A and B and C or D and E
A= defined $errB= builtin::blessed($err)C= scalar @_ == 1D= scalar @_ == 2E= defined $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | Scalar::Util::blessed( $err ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | ( scalar( @_ ) == 1 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | ( scalar( @_ ) == 2 && defined( $class ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 1 | ▶ | $self->{error} = ${ $pack . '::ERROR' } = ( defined( $class ) ? bless( $err => $class ) : $err ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | ▶ | $self->{error}->code( $code ) if( defined( $code ) && $self->{error}->can( 'code' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $code and $self->{"error"}->can("code")
MC/DC0%0/2
defined $code and $self->{"error"}->can("code")
defined $code
$self->{"error"}->can("code")
Truth table33%1/3
A and B
A= defined $codeB= $self->{"error"}->can("code")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # Use $pack (always defined) not $class (only set when explicitly provided) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # to check for FATAL_EXCEPTIONS, to avoid "uninitialized value" warnings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 1 | ▶ | my $check_class = $class // $pack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$class // $pack
MC/DC0%0/2
$class // $pack
$class
$pack
Truth table33%1/3
A // B
A= $classB= $pack
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | if( $self->{fatal} || ( defined( ${"${check_class}::FATAL_EXCEPTIONS"} ) && ${"${check_class}::FATAL_EXCEPTIONS"} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->{"fatal"} or defined ${"${check_class}::FATAL_EXCEPTIONS";} and ${"${check_class}::FATAL_EXCEPTIONS";}
defined ${"${check_class}::FATAL_EXCEPTIONS";} and ${"${check_class}::FATAL_EXCEPTIONS";}
MC/DC0%0/3
$self->{"fatal"} or defined ${"${check_class}::FATAL_EXCEPTIONS";} and ${"${check_class}::FATAL_EXCEPTIONS";}
$self->{"fatal"}
defined ${"${check_class}::FATAL_EXCEPTIONS";}
${"${check_class}::FATAL_EXCEPTIONS";}
Truth table25%1/4
A or B and C
A= $self->{"fatal"}B= defined ${"${check_class}::FATAL_EXCEPTIONS";}C= ${"${check_class}::FATAL_EXCEPTIONS";}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | die( $self->{error} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # If the error provided is not an object, we call error to create one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | return( $self->error( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 40 | ▶ | if( want( 'OBJECT' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | rreturn( DateTime::Format::Lite::NullObject->new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 40 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | sub pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 242 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pattern: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 242 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 242 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 232 | my $pat = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 232 | ▶ | unless( defined( $pat ) && length( $pat ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pat and length $pat
MC/DC0%0/2
defined $pat and length $pat
defined $pat
length $pat
Truth table33%1/3
A and B
A= defined $patB= length $pat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | return( $self->error( "pattern must be a non-empty string." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 232 | $self->{pattern} = $pat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # Invalidate cached parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 232 | $self->{_parser} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 242 | return( $self->{pattern} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | sub strict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 71 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strict: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 71 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 71 | ▶ | $self->{strict} = $_[0] ? 1 : 0 if( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 71 | return( $self->{strict} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | # NOTE: strftime() -> Exportable convenience function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | sub strftime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strftime: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 2 | my( $pattern, $dt ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 2 | ▶ | my $fmt = __PACKAGE__->new( pattern => $pattern ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
__PACKAGE__->new('pattern', $pattern) || die(__PACKAGE__->error)
MC/DC0%0/1
__PACKAGE__->new('pattern', $pattern) || die(__PACKAGE__->error)
__PACKAGE__->new('pattern', $pattern)
Truth table50%1/2
A
A= __PACKAGE__->new('pattern', $pattern)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | die( __PACKAGE__->error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 2 | return( $fmt->format_datetime( $dt ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | # NOTE: strptime() -> Exportable convenience function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | sub strptime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strptime: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 2 | my( $pattern, $string ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 2 | ▶ | my $fmt = __PACKAGE__->new( pattern => $pattern ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
__PACKAGE__->new('pattern', $pattern) || die(__PACKAGE__->error)
MC/DC0%0/1
__PACKAGE__->new('pattern', $pattern) || die(__PACKAGE__->error)
__PACKAGE__->new('pattern', $pattern)
Truth table50%1/2
A
A= __PACKAGE__->new('pattern', $pattern)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | die( __PACKAGE__->error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 2 | return( $fmt->parse_datetime( $string ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | sub time_zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 38 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time_zone: called CC=7 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 38 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 38 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 18 | my $tz = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 18 | ▶ | if( !defined( $tz ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | $self->{time_zone} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | elsif( Scalar::Util::blessed( $tz ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | unless( $tz->isa( 'DateTime::Lite::TimeZone' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | return( $self->error( "time_zone object must be a DateTime::Lite::TimeZone instance, got: ", ref( $tz ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | $self->{time_zone} = $tz; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | elsif( ref( $tz ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | return( $self->error( "time_zone must be a string or a DateTime::Lite::TimeZone object." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 18 | ▶ | $self->{time_zone} = DateTime::Lite::TimeZone->new( name => $tz, extended => 1 ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'DateTime::Lite::TimeZone'->new('name', $tz, 'extended', 1) || (return $self->pass_error('DateTime::Lite::TimeZone'->error))
MC/DC0%0/1
'DateTime::Lite::TimeZone'->new('name', $tz, 'extended', 1) || (return $self->pass_error('DateTime::Lite::TimeZone'->error))
'DateTime::Lite::TimeZone'->new('name', $tz, 'extended', 1)
Truth table50%1/2
A
A= 'DateTime::Lite::TimeZone'->new('name', $tz, 'extended', 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | return( $self->pass_error( DateTime::Lite::TimeZone->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 38 | return( $self->{time_zone} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | sub zone_map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 39 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
zone_map: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 39 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 39 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 22 | my $map = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 22 | ▶ | unless( ref( $map ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | return( $self->error( "zone_map must be a hash reference." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 22 | $self->{zone_map} = $map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 39 | ▶ | return( $self->{zone_map} //= {} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"zone_map"} //= {}
MC/DC0%0/1
$self->{"zone_map"} //= {}
$self->{"zone_map"}
Truth table50%1/2
A
A= $self->{"zone_map"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # NOTE: Serialisation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # FREEZE / THAW (Sereal >= 4, CBOR::XS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | sub FREEZE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FREEZE: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 4 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 4 | ▶ | my $serialiser = CORE::shift( @_ ) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ // ""
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 4 | my $class = CORE::ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 4 | ▶ | my $state = $self->_serialise_state || CORE::return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_serialise_state || (return)
MC/DC0%0/1
$self->_serialise_state || (return)
$self->_serialise_state
Truth table50%1/2
A
A= $self->_serialise_state
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # Sereal <= 4.023 requires an arrayref; later versions and CBOR accept a list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 4 | ▶ | if( $serialiser eq 'Sereal' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$serialiser eq "Sereal" and defined &Sereal::Encoder::VERSION and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" and defined &Sereal::Encoder::VERSION
MC/DC0%0/3
$serialiser eq "Sereal" and defined &Sereal::Encoder::VERSION and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal"
defined &Sereal::Encoder::VERSION
"Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table50%2/4
A and B and C
A= $serialiser eq "Sereal"B= defined &Sereal::Encoder::VERSIONC= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | defined( &Sereal::Encoder::VERSION ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | Sereal::Encoder->VERSION <= version->parse( '4.023' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | CORE::return( [$class, $state] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 4 | CORE::return( $class, $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | sub THAW | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
THAW: called CC=10 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 3 | my( $self, $serialiser, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 3 | ▶ | my $ref = ( CORE::scalar( @args ) == 1 && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1
ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | CORE::ref( $args[0] ) eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | ? CORE::shift( @args ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | : \@args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 3 | ▶ | my $class = ( CORE::ref( $ref ) eq 'ARRAY' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
ref $ref eq "ARRAY" and scalar @$ref > 1
ref $self or $self
MC/DC0%0/2
ref $ref eq "ARRAY" and scalar @$ref > 1
ref $ref eq "ARRAY"
scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self
$self
Truth table33%1/3
A and B
A= ref $ref eq "ARRAY"B= scalar @$ref > 1
Truth table0%0/3
A or B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | CORE::scalar( @$ref ) > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | ? CORE::shift( @$ref ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | : ( CORE::ref( $self ) || $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 3 | ▶ | my $state = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 3 | ▶ | if( CORE::ref( $self ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # Storable pattern: modify the existing object in place | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | $self->_restore_state( $state ) || CORE::return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | CORE::return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 3 | my $new = CORE::bless( {}, $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 3 | ▶ | $new->_restore_state( $state ) || CORE::return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 3 | CORE::return( $new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | # STORABLE_freeze / STORABLE_thaw (Storable) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | sub STORABLE_freeze | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: called CC=14 SCAR=34.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 3 | my $cloning = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 3 | ▶ | my $state = $self->_serialise_state || CORE::return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_serialise_state || (return)
MC/DC0%0/1
$self->_serialise_state || (return)
$self->_serialise_state
Truth table50%1/2
A
A= $self->_serialise_state
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 3 | ▶ | if( !defined( $state ) || ( defined( $state ) && ref( $state ) ne 'HASH' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $state or defined $state and ref $state ne "HASH"
defined $state and ref $state ne "HASH"
MC/DC0%0/3
not defined $state or defined $state and ref $state ne "HASH"
not defined $state
defined $state
ref $state ne "HASH"
Truth table25%1/4
not(A) or B and C
A= not defined $stateB= defined $stateC= ref $state ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | warn( "state returned by _serialise_state() is not an hash reference." ) if( warnings::enabled() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | CORE::return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # Encode the state as a compact key:value string, with the zone_map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # JSON-encoded since it may contain arbitrary string values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 3 | my $zone_map_json = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 3 | ▶ | if( defined( $state->{zone_map} ) && scalar( keys( %{$state->{zone_map}} ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
defined $state->{"zone_map"} and scalar keys %{$$state{"zone_map"};}
MC/DC0%0/1
defined $state->{"zone_map"} and scalar keys %{$$state{"zone_map"};}
defined $state->{"zone_map"}
Truth table50%1/2
A
A= defined $state->{"zone_map"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 3 | require JSON; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 3 | $zone_map_json = JSON::encode_json( $state->{zone_map} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | my $serialised = join( '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 'pattern:' . ( $state->{pattern} // '' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 'locale:' . ( $state->{locale} // 'en' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 'on_error:' . ( $state->{on_error} // 'undef' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 'strict:' . ( $state->{strict} // 0 ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 3 | ▶ | 'debug:' . ( $state->{debug} // 0 ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%5/10
$state->{"pattern"} // ""
$state->{"locale"} // "en"
$state->{"on_error"} // "undef"
$state->{"strict"} // 0
$state->{"debug"} // 0
MC/DC0%0/1
$state->{"pattern"} // ""
$state->{"pattern"}
MC/DC0%0/1
$state->{"locale"} // "en"
$state->{"locale"}
MC/DC0%0/1
$state->{"on_error"} // "undef"
$state->{"on_error"}
MC/DC0%0/1
$state->{"strict"} // 0
$state->{"strict"}
MC/DC0%0/1
$state->{"debug"} // 0
$state->{"debug"}
Truth table50%1/2
A
A= $state->{"pattern"}
Truth table50%1/2
A
A= $state->{"locale"}
Truth table50%1/2
A
A= $state->{"on_error"}
Truth table50%1/2
A
A= $state->{"strict"}
Truth table50%1/2
A
A= $state->{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 'zone_map:' . $zone_map_json, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | # time_zone is passed as a separate object for Storable reference tracking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 3 | ▶ | return( $serialised, \( $state->{time_zone} // '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state->{"time_zone"} // ""
MC/DC0%0/1
$state->{"time_zone"} // ""
$state->{"time_zone"}
Truth table50%1/2
A
A= $state->{"time_zone"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | sub STORABLE_thaw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: called CC=16 SCAR=34.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 3 | my $cloning = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 3 | my $serialised = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 3 | my $tz_ref = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 3 | my %s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 3 | foreach my $pair ( split( /\|/, $serialised ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 18 | my( $k, $v ) = split( /:/, $pair, 2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 18 | ▶ | $s{ $k } = $v // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$v // ""
MC/DC0%0/1
$v // ""
$v
Truth table50%1/2
A
A= $v
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | my %state = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | pattern => $s{pattern}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | locale => $s{locale} || 'en', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | on_error => $s{on_error} || 'undef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | strict => $s{strict} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 3 | ▶ | debug => $s{debug} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%4/8
$s{'locale'} || 'en'
$s{'on_error'} || 'undef'
$s{"strict"} // 0
$s{"debug"} // 0
MC/DC0%0/1
$s{'locale'} || 'en'
$s{'locale'}
MC/DC0%0/1
$s{'on_error'} || 'undef'
$s{'on_error'}
MC/DC0%0/1
$s{"strict"} // 0
$s{"strict"}
MC/DC0%0/1
$s{"debug"} // 0
$s{"debug"}
Truth table50%1/2
A
A= $s{'locale'}
Truth table50%1/2
A
A= $s{'on_error'}
Truth table50%1/2
A
A= $s{"strict"}
Truth table50%1/2
A
A= $s{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 3 | ▶ | if( defined( $s{zone_map} ) && length( $s{zone_map} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $s{"zone_map"} and length $s{"zone_map"}
MC/DC0%0/2
defined $s{"zone_map"} and length $s{"zone_map"}
defined $s{"zone_map"}
length $s{"zone_map"}
Truth table33%1/3
A and B
A= defined $s{"zone_map"}B= length $s{"zone_map"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 3 | require JSON; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 3 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 3 | $state{zone_map} = eval{ JSON::decode_json( $s{zone_map} ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 3 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | die( "Error serialising DateTime::Format::Lite object: $@" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 3 | ▶ | if( defined( $tz_ref ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $tz_ref and ref $tz_ref and defined $$tz_ref and length $$tz_ref
defined $tz_ref and ref $tz_ref and defined $$tz_ref
defined $tz_ref and ref $tz_ref
MC/DC0%0/4
defined $tz_ref and ref $tz_ref and defined $$tz_ref and length $$tz_ref
defined $tz_ref
ref $tz_ref
defined $$tz_ref
length $$tz_ref
Truth table20%1/5
A and B and C and D
A= defined $tz_refB= ref $tz_refC= defined $$tz_refD= length $$tz_ref
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | ref( $tz_ref ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | defined( $$tz_ref ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | length( $$tz_ref ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 3 | $state{time_zone} = $$tz_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 3 | ▶ | $self->_restore_state( \%state ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref($self)->error || 'STORABLE_thaw: failed to restore state'
MC/DC0%0/1
ref($self)->error || 'STORABLE_thaw: failed to restore state'
ref($self)->error
Truth table0%0/2
A
A= ref($self)->error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | die( ref( $self )->error || "STORABLE_thaw: failed to restore state" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 3 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | sub TO_JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 5 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 5 | return( $self->_serialise_state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | sub _build_parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 228 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_parser: called CC=13 SCAR=26.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 228 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 228 | my @pieces = $self->_parser_pieces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 228 | ▶ | return( $self->pass_error ) unless( @pieces ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 228 | my( $replacement_tokens_re, $replacements, $pattern_tokens_re, $patterns ) = @pieces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 228 | my $pattern = $self->{pattern}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | # Two expansion passes: the first may turn %c into %H:%M:%S etc., the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | # second resolves any tokens introduced by that first expansion. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 228 | $pattern =~ s/%($replacement_tokens_re)/$replacements->{$1}/g for( 1..2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 228 | ▶ | if( $self->{debug} && $pattern ne $self->{pattern} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"debug"} and $pattern ne $self->{"pattern"}
MC/DC0%0/2
$self->{"debug"} and $pattern ne $self->{"pattern"}
$self->{"debug"}
$pattern ne $self->{"pattern"}
Truth table33%1/3
A and B
A= $self->{"debug"}B= $pattern ne $self->{"pattern"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | warn( "Pattern after replacement substitution: $pattern\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 228 | my $regex = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 228 | my @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 228 | ▶ | while( $pattern =~ / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | \G | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | %($pattern_tokens_re) # named token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | %([1-9]?)(N) # %N or %nN nanoseconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | (%[0-9]*[a-zA-Z]) # unrecognised token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | ([^%]+) # literal text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | /xg ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 1343 | ▶ | if( defined( $1 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 790 | ▶ | my $p = $patterns->{ $1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | or return( $self->error( qq{Unidentified token "%$1" in pattern: $self->{pattern}} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 790 | ▶ | if( $p->{field} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 785 | $regex .= qr/($p->{regex})/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 785 | push( @fields, $p->{field} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 5 | $regex .= qr/$p->{regex}/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | elsif( defined( $3 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | # %N captures all digits; %nN captures exactly n digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 3 | ▶ | $regex .= $2 ? qr/([0-9]{$2})/ : qr/([0-9]+)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 3 | push( @fields, 'nanosecond' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | elsif( defined( $4 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 1 | return( $self->error( qq{Pattern contained an unrecognised strptime token, "$4"} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # Literal text - escape for regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 549 | $regex .= qr/\Q$5/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | return({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | regex => ( $self->{strict} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 227 | ▶ | ? qr/(?:\A|\b)$regex(?:\b|\Z)/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | : qr/$regex/ ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | fields => \@fields, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | sub _check_dt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 185 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_dt: called CC=39 SCAR=40.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 185 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 185 | ▶ | my $dt = shift( @_ ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || (return $self->_on_error('No DateTime::Lite or DateTime object was provided.'))
MC/DC0%0/1
shift @_ || (return $self->_on_error('No DateTime::Lite or DateTime object was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | return( $self->_on_error( "No DateTime::Lite or DateTime object was provided." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 185 | ▶ | my $args = shift( @_ ) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || {}
MC/DC0%0/1
shift @_ || {}
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 185 | ▶ | if( defined( $args ) && ref( $args ) ne 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args and ref $args ne "HASH"
MC/DC0%0/2
defined $args and ref $args ne "HASH"
defined $args
ref $args ne "HASH"
Truth table33%1/3
A and B
A= defined $argsB= ref $args ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | return( $self->_on_error( "Arguments hash provided (", overload::StrVal( $args ), ") is not an hash reference." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 185 | ▶ | my $locale = $self->locale || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->locale || (return $self->pass_error)
MC/DC0%0/1
$self->locale || (return $self->pass_error)
$self->locale
Truth table50%1/2
A
A= $self->locale
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 185 | ▶ | my $is_am = defined( $args->{am_pm} ) && lc( $args->{am_pm} ) eq lc( $locale->am_pm_abbreviated->[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $args->{'am_pm'} && lc $args->{'am_pm'} eq lc $locale->am_pm_abbreviated->[0]
MC/DC100%2/2
defined $args->{'am_pm'} && lc $args->{'am_pm'} eq lc $locale->am_pm_abbreviated->[0]
defined $args->{'am_pm'}
lc $args->{'am_pm'} eq lc $locale->am_pm_abbreviated->[0]
Truth table100%3/3
A && B
A= defined $args->{'am_pm'}B= lc $args->{'am_pm'} eq lc $locale->am_pm_abbreviated->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 185 | ▶ | if( defined( $args->{hour} ) && defined( $args->{hour_12} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"hour"} and defined $args->{"hour_12"}
MC/DC100%2/2
defined $args->{"hour"} and defined $args->{"hour_12"}
defined $args->{"hour"}
defined $args->{"hour_12"}
Truth table100%3/3
A and B
A= defined $args->{"hour"}B= defined $args->{"hour_12"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 2 | ▶ | unless( ( $args->{hour} % 12 ) == $args->{hour_12} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 2 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 'Parsed an input with 24-hour and 12-hour time values that do not match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | . qq{ - "$args->{hour}" versus "$args->{hour_12}"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 183 | ▶ | if( defined( $args->{hour} ) && defined( $args->{am_pm} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"hour"} and defined $args->{"am_pm"}
MC/DC100%2/2
defined $args->{"hour"} and defined $args->{"am_pm"}
defined $args->{"hour"}
defined $args->{"am_pm"}
Truth table100%3/3
A and B
A= defined $args->{"hour"}B= defined $args->{"am_pm"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 4 | ▶ | if( ( $is_am && $args->{hour} >= 12 ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$is_am and $args->{"hour"} >= 12 or not $is_am and $args->{"hour"} < 12
$is_am and $args->{"hour"} >= 12
not $is_am and $args->{"hour"} < 12
MC/DC0%0/4
$is_am and $args->{"hour"} >= 12 or not $is_am and $args->{"hour"} < 12
$is_am
$args->{"hour"} >= 12
not $is_am
$args->{"hour"} < 12
Truth table28%2/7
A and B or not(C) and D
A= $is_amB= $args->{"hour"} >= 12C= not $is_amD= $args->{"hour"} < 12
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | ( !$is_am && $args->{hour} < 12 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 4 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 'Parsed an input with 24-hour and AM/PM values that do not match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | . qq{ - "$args->{hour}" versus "$args->{am_pm}"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 179 | ▶ | if( defined( $args->{year} ) && defined( $args->{century} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"year"} and defined $args->{"century"}
MC/DC100%2/2
defined $args->{"year"} and defined $args->{"century"}
defined $args->{"year"}
defined $args->{"century"}
Truth table100%3/3
A and B
A= defined $args->{"year"}B= defined $args->{"century"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 2 | ▶ | unless( int( $args->{year} / 100 ) == $args->{century} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 2 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 'Parsed an input with year and century values that do not match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | . qq{ - "$args->{year}" versus "$args->{century}"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 177 | ▶ | if( defined( $args->{year} ) && defined( $args->{year_100} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"year"} and defined $args->{"year_100"}
MC/DC100%2/2
defined $args->{"year"} and defined $args->{"year_100"}
defined $args->{"year"}
defined $args->{"year_100"}
Truth table100%3/3
A and B
A= defined $args->{"year"}B= defined $args->{"year_100"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 2 | ▶ | unless( ( $args->{year} % 100 ) == $args->{year_100} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 2 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 'Parsed an input with year and year-within-century values that do not match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | . qq{ - "$args->{year}" versus "$args->{year_100}"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 175 | ▶ | if( defined( $args->{time_zone_abbreviation} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $args->{"time_zone_abbreviation"} and defined $args->{"time_zone_offset"} and exists $self->zone_map->{$args->{"time_zone_abbreviation"}}
defined $args->{"time_zone_abbreviation"} and defined $args->{"time_zone_offset"}
MC/DC0%0/3
defined $args->{"time_zone_abbreviation"} and defined $args->{"time_zone_offset"} and exists $self->zone_map->{$args->{"time_zone_abbreviation"}}
defined $args->{"time_zone_abbreviation"}
defined $args->{"time_zone_offset"}
exists $self->zone_map->{$args->{"time_zone_abbreviation"}}
Truth table75%3/4
A and B and C
A= defined $args->{"time_zone_abbreviation"}B= defined $args->{"time_zone_offset"}C= exists $self->zone_map->{$args->{"time_zone_abbreviation"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | defined( $args->{time_zone_offset} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | exists( $self->zone_map->{ $args->{time_zone_abbreviation} } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | # Only cross-check when the abbreviation was explicitly mapped via zone_map. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | # When resolved via the DB (not in zone_map), _munge_args already used the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | # co-parsed offset as a filter, so there is no conflict to detect here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | my $mapped = $self->zone_map->{ $args->{time_zone_abbreviation} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | ▶ | unless( defined( $mapped ) && $mapped eq $args->{time_zone_offset} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $mapped and $mapped eq $args->{"time_zone_offset"}
MC/DC0%0/2
defined $mapped and $mapped eq $args->{"time_zone_offset"}
defined $mapped
$mapped eq $args->{"time_zone_offset"}
Truth table0%0/3
A and B
A= defined $mappedB= $mapped eq $args->{"time_zone_offset"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 'Parsed an input with time zone abbreviation and offset values that do not match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | . qq{ - "$args->{time_zone_abbreviation}" versus "$args->{time_zone_offset}"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 175 | ▶ | if( defined( $args->{epoch} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 19 | foreach my $key ( qw( year month day hour minute second hour_12 day_of_year ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 98 | ▶ | if( defined( $args->{ $key } ) && $dt->$key != $args->{ $key } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args->{$key} and $dt->$key != $args->{$key}
MC/DC50%1/2
defined $args->{$key} and $dt->$key != $args->{$key}
defined $args->{$key}
$dt->$key != $args->{$key}
Truth table66%2/3
A and B
A= defined $args->{$key}B= $dt->$key != $args->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 14 | ▶ | my $label = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | $key eq 'hour_12' ? 'hour (1-12)' : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | $key eq 'day_of_year' ? 'day of year' : $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 14 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | "Parsed an input with epoch and $label values that do not match" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | . qq{ - "$args->{epoch}" versus "$args->{$key}"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 161 | ▶ | if( defined( $args->{month} ) && defined( $args->{day_of_year} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"month"} and defined $args->{"day_of_year"}
MC/DC100%2/2
defined $args->{"month"} and defined $args->{"day_of_year"}
defined $args->{"month"}
defined $args->{"day_of_year"}
Truth table100%3/3
A and B
A= defined $args->{"month"}B= defined $args->{"day_of_year"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 2 | ▶ | unless( $dt->month == $args->{month} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 2 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 'Parsed an input with month and day of year values that do not match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | . qq{ - "$args->{month}" versus "$args->{day_of_year}"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 159 | ▶ | if( defined( $args->{day_name} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 37 | my $dow = $self->_locale_days->{ lc( $args->{day_name} ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 37 | ▶ | defined( $dow ) or return( $self->error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | "We somehow parsed a day name ($args->{day_name})" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | . ' that does not correspond to any day in this locale!' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 37 | ▶ | unless( $dt->day_of_week_0 == $dow ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 2 | return( $self->_on_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 'Parsed an input where the day name does not match the date' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | . qq{ - "$args->{day_name}" versus "} . $dt->ymd . q{"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 157 | return(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | sub _locale_days | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 265 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_locale_days: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 265 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 265 | ▶ | return( $self->{_locale_days} ) if( defined( $self->{_locale_days} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 228 | ▶ | my $locale = $self->locale || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->locale || (return $self->pass_error)
MC/DC0%0/1
$self->locale || (return $self->pass_error)
$self->locale
Truth table50%1/2
A
A= $self->locale
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 228 | my %days; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 228 | my @wide = @{$locale->day_format_wide}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 228 | my @abbr = @{$locale->day_format_abbreviated}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | # In DateTime::Lite: day_of_week_0 is 0=Monday .. 6=Sunday | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 228 | for my $i ( 0..6 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 1596 | ▶ | $days{ lc( $wide[ $i ] ) } = $i if( defined( $wide[ $i ] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 1596 | ▶ | $days{ lc( $abbr[ $i ] ) } = $i if( defined( $abbr[ $i ] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 228 | return( $self->{_locale_days} = \%days ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | sub _locale_months | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 297 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_locale_months: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 297 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 297 | ▶ | return( $self->{_locale_months} ) if( defined( $self->{_locale_months} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 228 | ▶ | my $locale = $self->locale || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->locale || (return $self->pass_error)
MC/DC0%0/1
$self->locale || (return $self->pass_error)
$self->locale
Truth table50%1/2
A
A= $self->locale
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 228 | my %months; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 228 | my @wide = @{$locale->month_format_wide}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 228 | my @abbr = @{$locale->month_format_abbreviated}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 228 | for my $i ( 0..11 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 2736 | ▶ | $months{ lc( $wide[ $i ] ) } = $i + 1 if( defined( $wide[ $i ] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 2736 | ▶ | $months{ lc( $abbr[ $i ] ) } = $i + 1 if( defined( $abbr[ $i ] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 228 | return( $self->{_locale_months} = \%months ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | sub _munge_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 197 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_munge_args: called CC=56 SCAR=44.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 197 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 197 | ▶ | my $args = shift( @_ ) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || {}
MC/DC0%0/1
shift @_ || {}
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 197 | ▶ | if( defined( $args ) && ref( $args ) ne 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args and ref $args ne "HASH"
MC/DC0%0/2
defined $args and ref $args ne "HASH"
defined $args
ref $args ne "HASH"
Truth table33%1/3
A and B
A= defined $argsB= ref $args ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | return( $self->_on_error( "Arguments hash provided (", overload::StrVal( $args ), ") is not an hash reference." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | # Resolve month name -> month number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 197 | ▶ | if( defined( $args->{month_name} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 69 | ▶ | my $num = $self->_locale_months->{ lc( $args->{month_name} ) } or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | return( $self->error( "We somehow parsed a month name ($args->{month_name}) that does not correspond to any month in this locale!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 69 | $args->{month} = $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | # Resolve 12-hour clock + AM/PM -> 24-hour | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 197 | ▶ | if( defined( $args->{am_pm} ) && defined( $args->{hour_12} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $args->{"am_pm"} and defined $args->{"hour_12"}
MC/DC100%2/2
defined $args->{"am_pm"} and defined $args->{"hour_12"}
defined $args->{"am_pm"}
defined $args->{"hour_12"}
Truth table100%3/3
A and B
A= defined $args->{"am_pm"}B= defined $args->{"hour_12"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 6 | ▶ | my $locale = $self->locale || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->locale || (return $self->pass_error)
MC/DC0%0/1
$self->locale || (return $self->pass_error)
$self->locale
Truth table50%1/2
A
A= $self->locale
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 6 | my( $am, $pm ) = @{$locale->am_pm_abbreviated}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 6 | $args->{hour} = $args->{hour_12}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 6 | ▶ | if( lc( $args->{am_pm} ) eq lc( $am ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 3 | ▶ | $args->{hour} = 0 if( $args->{hour} == 12 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 3 | ▶ | $args->{hour} += 12 unless( $args->{hour} == 12 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | elsif( defined( $args->{hour_12} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 2 | return( $self->_on_error( qq{Parsed a 12-hour based hour, "$args->{hour_12}", but the pattern does not include an AM/PM specifier.} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | # Resolve 2-digit year with optional century | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 195 | ▶ | if( defined( $args->{year_100} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 5 | ▶ | if( defined( $args->{century} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 0 | $args->{year} = $args->{year_100} + ( $args->{century} * 100 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 5 | ▶ | $args->{year} = $args->{year_100} + ( $args->{year_100} >= 69 ? 1900 : 2000 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | # Resolve numeric timezone offset string -> DateTime::Lite::TimeZone object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 195 | ▶ | if( defined( $args->{time_zone_offset} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 6 | my $offset = $args->{time_zone_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 6 | ▶ | $offset = '+0000' if( $offset eq 'Z' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 6 | ▶ | $offset .= '00' if( $offset =~ /^[+-][0-9]{2}$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 6 | my $tz = DateTime::Lite::TimeZone->new( name => $offset ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 6 | ▶ | unless( $tz ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 0 | return( $self->_on_error( qq{The time zone offset "$args->{time_zone_offset}" does not appear to be valid.} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 6 | $args->{time_zone} = $tz; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | # Resolve timezone abbreviation via zone_map then IANA SQLite DB. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | # When %z was also parsed, args->{time_zone} is already a fixed-offset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | # timezone built from the explicit offset - the abbreviation is then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | # purely informational and we skip DB resolution entirely. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 195 | ▶ | if( defined( $args->{time_zone_abbreviation} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"time_zone_abbreviation"} and not defined $args->{"time_zone"}
MC/DC100%2/2
defined $args->{"time_zone_abbreviation"} and not defined $args->{"time_zone"}
defined $args->{"time_zone_abbreviation"}
not defined $args->{"time_zone"}
Truth table100%3/3
A and not(B)
A= defined $args->{"time_zone_abbreviation"}B= not defined $args->{"time_zone"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | !defined( $args->{time_zone} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 20 | my $abbr = $args->{time_zone_abbreviation}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 20 | my $tz; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | # 1. Check caller-supplied zone_map first (explicit overrides) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 20 | ▶ | if( exists( $self->{zone_map}->{ $abbr } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 5 | ▶ | if( !defined( $self->{zone_map}->{ $abbr } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 0 | return( $self->_on_error( qq{The time zone abbreviation "$abbr" is marked ambiguous in zone_map.} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 5 | $tz = DateTime::Lite::TimeZone->new( name => $self->{zone_map}->{ $abbr } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | # Short-circuit for canonical zone names that also show up as %Z. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | # UTC, GMT, and Z (Zulu) are all IANA zone names, not abbreviations in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | # types table, so resolve_abbreviation() would fail. Any string with a '/' is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | # an IANA zone name and never an abbreviation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | ▶ | elsif( $abbr eq 'UTC' || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition91%11/12
$abbr eq "UTC" or $abbr eq "GMT" or $abbr eq "Z" or $abbr eq "floating" or index($abbr, "/") != -1
$abbr eq "UTC" or $abbr eq "GMT" or $abbr eq "Z" or $abbr eq "floating"
$abbr eq "UTC" or $abbr eq "GMT" or $abbr eq "Z"
$abbr eq "UTC" or $abbr eq "GMT"
MC/DC80%4/5
$abbr eq "UTC" or $abbr eq "GMT" or $abbr eq "Z" or $abbr eq "floating" or index($abbr, "/") != -1
$abbr eq "UTC"
$abbr eq "GMT"
$abbr eq "Z"
$abbr eq "floating"
index($abbr, "/") != -1
Truth table83%5/6
A or B or C or D or E
A= $abbr eq "UTC"B= $abbr eq "GMT"C= $abbr eq "Z"D= $abbr eq "floating"E= index($abbr, "/") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | $abbr eq 'GMT' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | $abbr eq 'Z' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | $abbr eq 'floating' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | index( $abbr, '/' ) >= 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 6 | $tz = DateTime::Lite::TimeZone->new( name => $abbr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 6 | ▶ | if( !defined( $tz ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 0 | return( $self->_on_error( qq{Cannot construct timezone "$abbr": } . DateTime::Lite::TimeZone->error ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | # 2. Query the IANA DB, optionally narrowing by co-parsed offset. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | # time_zone_offset is a parsed string like "-0800" or "+0900"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | # resolve_abbreviation expects integer seconds east of UTC. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 9 | my @resolve_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 9 | ▶ | if( defined( $args->{time_zone_offset} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | my $off_str = $args->{time_zone_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 0 | ▶ | $off_str = '+0000' if( $off_str eq 'Z' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | ▶ | $off_str .= '00' if( $off_str =~ /^[+-][0-9]{2}$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 0 | my( $sign, $hh, $mm ) = ( $off_str =~ /^([+-])([0-9]{2})([0-9]{2})$/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | ▶ | if( defined( $sign ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | my $secs = ( $hh * 3600 + $mm * 60 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | ▶ | $secs *= -1 if( $sign eq '-' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 0 | @resolve_args = ( $abbr, utc_offset => $secs ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 0 | @resolve_args = ( $abbr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 9 | @resolve_args = ( $abbr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 9 | my $candidates = DateTime::Lite::TimeZone->resolve_abbreviation( @resolve_args, extended => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 9 | ▶ | if( !defined( $candidates ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 2 | return( $self->_on_error( qq{Error resolving timezone abbreviation "$abbr": } . DateTime::Lite::TimeZone->error ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 7 | ▶ | if( $candidates->[0]->{ambiguous} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 4 | return( $self->_on_error( qq{The time zone abbreviation "$abbr" is ambiguous (maps to multiple UTC offsets). Use zone_map to specify which timezone is intended.} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | # When a co-parsed %z offset was used to filter candidates, all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | # results already have the correct offset - just take the first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | # When no offset filter was applied (e.g. bare %Z without %z), we pick | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | # the first zone whose CURRENT offset matches the abbreviation's offset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | # to avoid zones that only used the abbreviation historically | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | # (such as Asia/Hong_Kong for JST, which is now HKT +08:00). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 3 | my $chosen_zone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 3 | ▶ | if( @resolve_args > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | # utc_offset filter was applied: all candidates are already correct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | $chosen_zone = DateTime::Lite::TimeZone->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | name => $candidates->[0]->{zone_name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 3 | foreach my $candidate ( @$candidates ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | my $tz_candidate = DateTime::Lite::TimeZone->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | name => $candidate->{zone_name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 8 | ▶ | next unless( $tz_candidate ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | # Check the offset at the present moment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 8 | my $current_offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 8 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 8 | eval { $current_offset = $tz_candidate->offset_for_datetime( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | DateTime::Lite->from_epoch( epoch => time() ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 8 | ▶ | if( defined( $current_offset ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $current_offset and $current_offset == $candidate->{"utc_offset"}
MC/DC50%1/2
defined $current_offset and $current_offset == $candidate->{"utc_offset"}
defined $current_offset
$current_offset == $candidate->{"utc_offset"}
Truth table66%2/3
A and B
A= defined $current_offsetB= $current_offset == $candidate->{"utc_offset"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | $current_offset == $candidate->{utc_offset} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 3 | $chosen_zone = $tz_candidate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | # Fallback: keep first candidate even if current offset differs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 5 | ▶ | $chosen_zone //= $tz_candidate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$chosen_zone //= $tz_candidate
MC/DC0%0/2
$chosen_zone //= $tz_candidate
$chosen_zone
$tz_candidate
Truth table66%2/3
A //= B
A= $chosen_zoneB= $tz_candidate
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 3 | $tz = $chosen_zone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 14 | ▶ | unless( $tz ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | return( $self->_on_error( qq{Could not build a timezone object for abbreviation "$abbr".} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 14 | $args->{time_zone} = $tz; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 175 | ▶ | $args->{time_zone} ||= 'floating'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"time_zone"} ||= "floating"
MC/DC100%1/1
$args->{"time_zone"} ||= "floating"
$args->{"time_zone"}
Truth table100%2/2
A
A= $args->{"time_zone"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | # Resolve Olson/IANA timezone name (%O token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 189 | ▶ | if( defined( $args->{time_zone_name} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 9 | my $name = $args->{time_zone_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | # Normalise capitalisation unconditionally before lookup, because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | # DateTime::Lite::TimeZone->new may accept incorrect case and store it verbatim, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | # which would cause time_zone_long_name to return the un-normalised string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | # e.g. 'asia/tokyo' or 'ASIA/TOKYO' -> 'Asia/Tokyo' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 9 | ▶ | if( index( $name, '/' ) != -1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 9 | $name = lc( $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | 9 | $name =~ s{ (^|[/_]) (.) }{ $1 . uc($2) }xge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 9 | my $tz = DateTime::Lite::TimeZone->new( name => $name, extended => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 9 | ▶ | unless( $tz ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 2 | return( $self->_on_error( qq{The Olson timezone name "$args->{time_zone_name}" does not appear to be valid.} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 7 | $args->{time_zone} = $tz; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 187 | delete( @$args{ @NON_DT_KEYS } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 187 | $args->{locale} = $self->locale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | # Strip leading spaces from numeric fields (%e, %k, %l are space-padded) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 187 | foreach my $k ( grep{ defined( $args->{ $_ } ) } qw( month day hour minute second nanosecond ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 378 | $args->{ $k } =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | # Nanosecond scaling: "12345" -> 123450000, "000123456" -> 123456 ns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 187 | ▶ | if( defined( $args->{nanosecond} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 3 | ▶ | if( length( $args->{nanosecond} ) != 9 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 2 | $args->{nanosecond} *= 10 ** ( 9 - length( $args->{nanosecond} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 3 | $args->{nanosecond} += 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | # Supply defaults for the three required DateTime::Lite fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 187 | ▶ | $args->{ $_ } //= 1 for qw( year month day ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{$_} //= 1
MC/DC100%1/1
$args->{$_} //= 1
$args->{$_}
Truth table100%2/2
A
A= $args->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | # Choose the right DateTime::Lite constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 187 | ▶ | if( defined( $args->{epoch} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 19 | my $post_construct; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 19 | ▶ | if( my $nano = $args->{nanosecond} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | # epoch is truncated to integer by DateTime::Lite; set nanosecond afterwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 0 | ▶ | $post_construct = sub{ $_[0]->set( nanosecond => $nano ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 19 | delete( @$args{ qw( day_of_year year month day hour minute second nanosecond ) } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 19 | return( 'from_epoch', $args, $post_construct ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | elsif( $args->{day_of_year} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 3 | delete( @$args{ qw( epoch month day ) } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 3 | return( 'from_day_of_year', $args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 165 | return( 'new', $args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | sub _on_error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 52 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_on_error: called CC=5 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 52 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 52 | my $msg = join( '', @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 52 | ▶ | if( ref( $self->{on_error} ) eq 'CODE' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | 21 | $self->{on_error}->( $self, $msg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 21 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | ▶ | elsif( defined( $self->{on_error} ) && ( $self->{on_error} eq 'croak' || $self->{on_error} eq 'die' ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
defined $self->{"on_error"} and $self->{"on_error"} eq "croak" || $self->{"on_error"} eq "die"
$self->{"on_error"} eq "croak" or $self->{"on_error"} eq "die"
MC/DC0%0/3
defined $self->{"on_error"} and $self->{"on_error"} eq "croak" || $self->{"on_error"} eq "die"
defined $self->{"on_error"}
$self->{"on_error"} eq "croak"
$self->{"on_error"} eq "die"
Truth table25%1/4
A and B or C
A= defined $self->{"on_error"}B= $self->{"on_error"} eq "croak"C= $self->{"on_error"} eq "die"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 0 | die( $msg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | # Default 'undef': set the error object and return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 31 | return( $self->error( $msg ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | sub _parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 435 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parser: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 435 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 435 | ▶ | return( $self->{_parser} //= $self->_build_parser ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{"_parser"} //= $self->_build_parser
MC/DC100%2/2
$self->{"_parser"} //= $self->_build_parser
$self->{"_parser"}
$self->_build_parser
Truth table100%3/3
A //= B
A= $self->{"_parser"}B= $self->_build_parser
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | sub _parser_pieces | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 228 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parser_pieces: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 228 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 228 | my %replacements = %UNIVERSAL_REPLACEMENTS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 228 | ▶ | my $locale = $self->locale || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->locale || (return $self->pass_error)
MC/DC0%0/1
$self->locale || (return $self->pass_error)
$self->locale
Truth table50%1/2
A
A= $self->locale
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | # Locale-dependent compound expansions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | # DateTime::Locale::FromCLDR is CLDR-based and does not provide glibc-style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | # strptime strings (glibc_datetime_format etc. are explicitly not implemented). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | # We use fixed POSIX C-locale equivalents as a universal fallback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | # Users who need locale-specific datetime representations should use explicit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | # patterns instead of %c/%x/%X. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 228 | $replacements{c} = '%a %b %e %T %Y'; # e.g. "Mon Jan 3 15:04:05 2006" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 228 | $replacements{x} = '%m/%d/%y'; # e.g. "01/03/06" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 228 | $replacements{X} = '%T'; # e.g. "15:04:05" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 228 | my %patterns = %UNIVERSAL_PATTERNS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | # Locale-dependent: day names (%a/%A) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | $patterns{a} = $patterns{A} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | regex => do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 228 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | my $days = join( '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 3192 | map { quotemeta } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 8638 | ▶ | sort{ ( length( $b ) <=> length( $a ) ) || ( $a cmp $b ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
length $b <=> length $a || $a cmp $b
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a
$a cmp $b
Truth table66%2/3
A || B
A= length $b <=> length $aB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 228 | ▶ | keys( %{ $self->_locale_days || {} } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_locale_days || {}
MC/DC0%0/1
$self->_locale_days || {}
$self->_locale_days
Truth table50%1/2
A
A= $self->_locale_days
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 228 | qr/$days/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | field => 'day_name', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | # Locale-dependent: month names (%b/%B/%h) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | $patterns{b} = $patterns{B} = $patterns{h} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | regex => do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 228 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | my $months = join( '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 4881 | map { quotemeta } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 15957 | ▶ | sort{ ( length( $b ) <=> length( $a ) ) || ( $a cmp $b ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
length $b <=> length $a || $a cmp $b
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a
$a cmp $b
Truth table66%2/3
A || B
A= length $b <=> length $aB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 228 | ▶ | keys( %{ $self->_locale_months || {} } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_locale_months || {}
MC/DC0%0/1
$self->_locale_months || {}
$self->_locale_months
Truth table50%1/2
A
A= $self->_locale_months
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | 228 | qr/$months/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | field => 'month_name', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | # Locale-dependent: AM/PM (%p/%P) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | $patterns{p} = $patterns{P} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | regex => do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | 228 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | my $am_pm = join( '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 310 | map { quotemeta } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 155 | ▶ | sort{ ( length( $b ) <=> length( $a ) ) || ( $a cmp $b ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
length $b <=> length $a || $a cmp $b
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a
$a cmp $b
Truth table33%1/3
A || B
A= length $b <=> length $aB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 228 | @{$locale->am_pm_abbreviated} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 228 | qr/$am_pm/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | field => 'am_pm', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | return( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 228 | _token_re_for( keys( %replacements ) ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | \%replacements, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | _token_re_for( keys( %patterns ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | \%patterns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | # _restore_state(): common helper that populates $self from a plain hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | # previously produced by _serialise_state(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | sub _restore_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_state: called CC=7 SCAR=24.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | 6 | my( $self, $state ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 6 | ▶ | if( !defined( $state ) || ref( $state ) ne 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $state or ref $state ne "HASH"
MC/DC0%0/2
not defined $state or ref $state ne "HASH"
not defined $state
ref $state ne "HASH"
Truth table33%1/3
not(A) or B
A= not defined $stateB= ref $state ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 0 | return( $self->error( "_restore_state: state argument must be a HASH reference." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 6 | foreach my $param ( qw( pattern locale on_error strict debug time_zone zone_map ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 42 | ▶ | unless( exists( $state->{ $param } ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $state->{$param} and defined $state->{$param}
MC/DC0%0/2
exists $state->{$param} and defined $state->{$param}
exists $state->{$param}
defined $state->{$param}
Truth table33%1/3
A and B
A= exists $state->{$param}B= defined $state->{$param}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | defined( $state->{ $param } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 42 | ▶ | $self->$param( $state->{ $param } ) // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->$param($state->{$param}) // (return $self->pass_error)
MC/DC0%0/1
$self->$param($state->{$param}) // (return $self->pass_error)
$self->$param($state->{$param})
Truth table50%1/2
A
A= $self->$param($state->{$param})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 6 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | # _serialise_state(): common helper returning a plain hashref of the public object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | # state, with objects reduced to their string identifiers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | # Used by all serialisation methods to avoid duplication. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | sub _serialise_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_serialise_state: called CC=8 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 12 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | # on_error may be a coderef, which cannot be serialised. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | # Fall back to 'undef' and warn so the caller is not surprised. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | 12 | my $on_error = $self->{on_error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | 12 | ▶ | if( ref( $on_error ) eq 'CODE' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | 1 | ▶ | warn( "on_error is a CODE reference and cannot be serialised; storing 'undef' instead." ) if( warnings::enabled( 'DateTime::Format::Lite' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 1 | $on_error = 'undef'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | return({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | pattern => $self->{pattern}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | # Reduce objects to their string identifiers for portability | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | locale => ( defined( $self->{locale} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | ? $self->{locale}->as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | : 'en' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | time_zone => ( defined( $self->{time_zone} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | ? $self->{time_zone}->name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | : undef ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | on_error => $on_error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | strict => $self->{strict} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | debug => $self->{debug} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | zone_map => $self->{zone_map} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 12 | ▶ | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$self->{"strict"} // 0
$self->{"debug"} // 0
$self->{"zone_map"} // {}
MC/DC0%0/1
$self->{"strict"} // 0
$self->{"strict"}
MC/DC0%0/1
$self->{"debug"} // 0
$self->{"debug"}
MC/DC0%0/1
$self->{"zone_map"} // {}
$self->{"zone_map"}
Truth table50%1/2
A
A= $self->{"strict"}
Truth table50%1/2
A
A= $self->{"debug"}
Truth table50%1/2
A
A= $self->{"zone_map"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | sub _set_get_prop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 33 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_prop: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 33 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 33 | ▶ | my $prop = shift( @_ ) || die( "No object property was provided." ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || die('No object property was provided.')
MC/DC0%0/1
shift @_ || die('No object property was provided.')
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 33 | ▶ | $self->{ $prop } = shift( @_ ) if( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 33 | return( $self->{ $prop } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | sub _token_re_for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 456 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_token_re_for: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | 456 | ▶ | my $t = join( '|', sort{ ( length( $b ) <=> length( $a ) ) || ( $a cmp $b ) } @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
length $b <=> length $a || $a cmp $b
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a
$a cmp $b
Truth table33%1/3
A || B
A= length $b <=> length $aB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 456 | return( qr/$t/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | # NOTE: DateTime::Format::Lite::NullObject class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | DateTime::Format::Lite::NullObject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 12 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 0 | ▶ | '""' => sub{ '' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | 12 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 12 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 12 | ▶ | use Wanted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 1 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | 1 | ▶ | my $ref = @_ ? { @_ } : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | 1 | ▶ | return( bless( $ref => ( ref( $this ) || $this ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | sub AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | 2 | my( $method ) = our $AUTOLOAD =~ /([^:]+)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | 2 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 2 | ▶ | if( want( 'OBJECT' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 0 | rreturn( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | # Otherwise, we return undef; Empty return returns undef in scalar context and empty list in list context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||