lib/DateTime/Format/Unicode.pm

filter: Statementstmt 10.1% 84 / 826 Branchbran 0.0% 0 / 600 Conditioncond 0.0% 0 / 393 MC/DCmcdc 0.0% 0 / 221 Subroutinesub 23.5% 29 / 123 Podpod 57.1% 8 / 14 totaltotal 5.5% 121 / 2177 CC 457 SCAR 56.6
CC
457
Cov
5%
pass_error
1310.5
new
1056.0
_format_hour_allowed_preferred
756.0
CRAP 288.0
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## DateTime::Format::Unicode - ~/lib/DateTime/Format/Unicode.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2024/07/21
7 ## Modified 2025/10/16
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::Unicode;
15 BEGIN
16 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶ use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 $ERROR $VERSION $DEBUG $ON_ERROR
23 1 );
24 1 ▶ use Locale::Unicode;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶ use DateTime::Locale::FromCLDR;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶ use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 our $VERSION = 'v0.3.0';
30 };
31  
32 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 sub new
36 0 ▶{
Subroutine new: not called CC=32 SCAR=69.6
Pod documented
37 0 my $this = shift( @_ );
38 0 ▶ my $self = bless( {} => ( ref( $this ) || $this ) );
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
39 0 my @args = @_;
40 0 ▶ if( scalar( @args ) == 1 &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1 and defined $args[0] and ref $args[0] eq 'HASH') { } 0 0 0
elsif (scalar(@args) % 2) { } 0 0 0
Condition0%0/6
scalar @args == 1 and defined $args[0] and ref $args[0] eq "HASH"
!ll&&!rl&&r
000
scalar @args == 1 and defined $args[0]
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @args == 1 and defined $args[0] and ref $args[0] eq "HASH"
scalar @args == 1 defined $args[0] ref $args[0] eq "HASH"
Truth table0%0/4
A and B and C
A= scalar @args == 1B= defined $args[0]C= ref $args[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
41 defined( $args[0] ) &&
42 ref( $args[0] ) eq 'HASH' )
43 {
44 0 my $opts = shift( @args );
45 0 @args = %$opts;
46 }
47 elsif( ( scalar( @args ) % 2 ) )
48 {
49 0 return( $self->error( sprintf( "Uneven number of parameters provided (%d). Should receive key => value pairs. Parameters provided are: %s", scalar( @args ), join( ', ', @args ) ) ) );
50 }
51  
52 0 ▶ $self->{on_error} = $ON_ERROR if( defined( $ON_ERROR ) && ( ref( $ON_ERROR ) eq 'CODE' || $ON_ERROR eq 'fatal' ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $DateTime::Format::Unicode::ON_ERROR and ref $DateTime::Format::Unicode::ON_ERROR eq "CODE" || $DateTime::Format::Unicode::ON_ERROR eq "fatal" 0 0 0
Condition0%0/6
defined $DateTime::Format::Unicode::ON_ERROR and ref $DateTime::Format::Unicode::ON_ERROR eq "CODE" || $DateTime::Format::Unicode::ON_ERROR eq "fatal"
!ll&&!rl&&r
000
ref $DateTime::Format::Unicode::ON_ERROR eq "CODE" or $DateTime::Format::Unicode::ON_ERROR eq "fatal"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $DateTime::Format::Unicode::ON_ERROR and ref $DateTime::Format::Unicode::ON_ERROR eq "CODE" || $DateTime::Format::Unicode::ON_ERROR eq "fatal"
defined $DateTime::Format::Unicode::ON_ERROR ref $DateTime::Format::Unicode::ON_ERROR eq "CODE" $DateTime::Format::Unicode::ON_ERROR eq "fatal"
Truth table0%0/4
A and B or C
A= defined $DateTime::Format::Unicode::ON_ERRORB= ref $DateTime::Format::Unicode::ON_ERROR eq "CODE"C= $DateTime::Format::Unicode::ON_ERROR eq "fatal"
ABCresult
0XX0
1000
11X1
1011
53 0 ▶ for( my $i = 0; $i < scalar( @args ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 0 0 0
54 {
55 0 ▶ if( $args[$i] eq 'on_error' )
Branch: 1 branch
BranchTrueFalseTotal
if ($args[$i] eq "on_error") 0 0 0
56 {
57 0 my $v = $args[$i+1];
58 0 splice( @args, $i, 2 );
59 0 unshift( @args, 'on_error', $v );
60 0 last;
61 }
62 }
63 # Then, if the user provided with an hash or hash reference of options, we apply them
64 0 ▶ for( my $i = 0; $i < scalar( @args ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 0 0 0
65 {
66 0 my $name = $args[ $i ];
67 0 my $val = $args[ ++$i ];
68 0 my $meth = $self->can( $name );
69 0 ▶ if( !defined( $meth ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $meth) { } 0 0 0
elsif (not defined &$meth($self, $val)) { } 0 0 0
70 {
71 0 return( $self->error( "Unknown method \"${meth}\" provided." ) );
72 }
73 elsif( !defined( $meth->( $self, $val ) ) )
74 {
75 0 ▶ if( defined( $val ) && $self->error )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $self->error) 0 0 0
Condition0%0/3
defined $val and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $self->error
defined $val $self->error
Truth table0%0/3
A and B
A= defined $valB= $self->error
ABresult
0X0
100
111
76 {
77 0 return( $self->pass_error );
78 }
79 }
80 }
81 0 my $locale;
82 0 ▶ if( !( $locale = $self->{locale} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locale = $self->{"locale"}) 0 0 0
83 {
84 0 ▶ $locale = $self->locale( 'en' ) ||
Condition0%0/2
$self->locale('en') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->locale('en') || (return $self->pass_error)
$self->locale('en')
Truth table0%0/2
A
A= $self->locale('en')
Aresult
11
00
85 return( $self->pass_error );
86 }
87 0 my $unicode = $self->{_unicode};
88 0 ▶ if( !$self->{time_zone} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"time_zone"}) 0 0 0
89 {
90 0 ▶ $self->time_zone( 'floating' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->time_zone("floating") or return $self->pass_error 0 0 0
91 }
92 0 ▶ if( !$self->{pattern} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"pattern"}) 0 0 0
93 {
94 0 ▶ $self->{pattern} = $unicode->date_format_medium ||
Condition0%0/2
$unicode->date_format_medium || (return $self->error("No default pattern (medium date format) available for locale $locale in DateTime::Locale::FromCLDR"))
l!l
00
MC/DC0%0/1
$unicode->date_format_medium || (return $self->error("No default pattern (medium date format) available for locale $locale in DateTime::Locale::FromCLDR"))
$unicode->date_format_medium
Truth table0%0/2
A
A= $unicode->date_format_medium
Aresult
11
00
95 return( $self->error( "No default pattern (medium date format) available for locale ${locale} in DateTime::Locale::FromCLDR" ) );
96 }
97 0 my $ns_ref = $unicode->locale_number_system;
98 0 ▶ my $ns = $ns_ref->[0] || $unicode->number_system;
Condition0%0/3
$ns_ref->[0] || $unicode->number_system
l!l&&r!l&&!r
000
MC/DC0%0/2
$ns_ref->[0] || $unicode->number_system
$ns_ref->[0] $unicode->number_system
Truth table0%0/3
A || B
A= $ns_ref->[0]B= $unicode->number_system
ABresult
1X1
011
000
99 0 ▶ my $ns_digits = ( $ns_ref->[1] && ref( $ns_ref->[1] ) eq 'ARRAY' && scalar( @{$ns_ref->[1]} ) ) ? $ns_ref->[1] : [0..9];
Branch: 1 branch
BranchTrueFalseTotal
$ns_ref->[1] && ref $ns_ref->[1] eq 'ARRAY' && scalar @{$ns_ref->[1];} ? : 0 0 0
Condition0%0/5
$ns_ref->[1] and ref $ns_ref->[1] eq "ARRAY" and scalar @{$ns_ref->[1];}
!ll
00
$ns_ref->[1] and ref $ns_ref->[1] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$ns_ref->[1] and ref $ns_ref->[1] eq "ARRAY" and scalar @{$ns_ref->[1];}
$ns_ref->[1] ref $ns_ref->[1] eq "ARRAY"
Truth table0%0/3
A and B
A= $ns_ref->[1]B= ref $ns_ref->[1] eq "ARRAY"
ABresult
0X0
100
111
100 0 $self->{_number_system} = $ns;
101 0 $self->{_number_system_digits} = $ns_digits;
102 # Does the locale provided have a different numbering system and does this locale support it?
103 0 my $num_sys = $locale->number;
104 0 ▶ if( $num_sys && $num_sys ne $ns )
Branch: 1 branch
BranchTrueFalseTotal
if ($num_sys and $num_sys ne $ns) 0 0 0
Condition0%0/3
$num_sys and $num_sys ne $ns
!ll&&!rl&&r
000
MC/DC0%0/2
$num_sys and $num_sys ne $ns
$num_sys $num_sys ne $ns
Truth table0%0/3
A and B
A= $num_sysB= $num_sys ne $ns
ABresult
0X0
100
111
105 {
106 0 my $systems = $unicode->number_systems;
107 # 'latn' is always supported by all locale as per the LDML specifications
108 0 ▶ if( $num_sys eq 'latn' || scalar( grep( ( $systems->{ $_ } // '' ) eq $num_sys, qw( number_system native ) ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($num_sys eq "latn" or scalar grep((($systems->{$_} // "") eq $num_sys), ("number_system", "native"))) 0 0 0
Condition0%0/4
$num_sys eq "latn" or scalar grep((($systems->{$_} // "") eq $num_sys), ("number_system", "native"))
l!l
00
$systems->{$_} // ""
l!l
00
MC/DC0%0/1
$num_sys eq "latn" or scalar grep((($systems->{$_} // "") eq $num_sys), ("number_system", "native"))
$num_sys eq "latn"
MC/DC0%0/1
$systems->{$_} // ""
$systems->{$_}
Truth table0%0/2
A
A= $num_sys eq "latn"
Aresult
11
00
Truth table0%0/2
A
A= $systems->{$_}
Aresult
11
00
109 {
110 0 $self->{_number_system} = $num_sys;
111 0 ▶ my $digits = $unicode->number_system_digits( $num_sys ) ||
Condition0%0/2
$unicode->number_system_digits($num_sys) || (return $self->pass_error($unicode->error))
l!l
00
MC/DC0%0/1
$unicode->number_system_digits($num_sys) || (return $self->pass_error($unicode->error))
$unicode->number_system_digits($num_sys)
Truth table0%0/2
A
A= $unicode->number_system_digits($num_sys)
Aresult
11
00
112 return( $self->pass_error( $unicode->error ) );
113 0 $self->{_number_system_digits} = $digits;
114 }
115 }
116 0 return( $self );
117 }
118  
119 sub error
120 0 ▶{
Subroutine error: not called CC=9 SCAR=45.0
Pod documented
121 0 my $self = shift( @_ );
122 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
123 {
124 0 ▶ my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
125 0 $self->{error} = $ERROR = DateTime::Format::Unicode::Exception->new({
126 skip_frames => 1,
127 message => $msg,
128 });
129 0 ▶ warn( $msg ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
130 0 my $on_error = $self->{on_error};
131 0 ▶ if( $on_error )
Branch: 1 branch
BranchTrueFalseTotal
if ($on_error) 0 0 0
132 {
133 0 ▶ if( ref( $on_error ) eq 'CODE' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $on_error eq 'CODE') { } 0 0 0
elsif ($on_error eq 'fatal') { } 0 0 0
134 {
135 0 $on_error->( $self->{error} );
136 }
137 elsif( $on_error eq 'fatal' )
138 {
139 0 die( $self->{error} );
140 }
141 }
142 0 ▶ rreturn( DateTime::Format::Unicode::NullObject->new ) if( want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("OBJECT") 0 0 0
143 0 return;
144 }
145 0 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
146 }
147  
148 sub format_datetime
149 0 ▶{
Subroutine format_datetime: not called CC=15 SCAR=54.8
Pod documented
150 0 my $self = shift( @_ );
151 0 my $dt = shift( @_ );
152 0 my $opts = $self->_get_args_as_hash( @_ );
153 0 local $@;
154 0 ▶ if( defined( $dt ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dt) { } 0 0 0
155 {
156 0 ▶ unless( Scalar::Util::blessed( $dt ) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($dt) and $dt->isa("DateTime")) 0 0 0
Condition0%0/3
builtin::blessed($dt) and $dt->isa("DateTime")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($dt) and $dt->isa("DateTime")
builtin::blessed($dt) $dt->isa("DateTime")
Truth table0%0/3
A and B
A= builtin::blessed($dt)B= $dt->isa("DateTime")
ABresult
0X0
100
111
157 $dt->isa( 'DateTime' ) )
158 {
159 0 return( $self->error( "Value provided is not a DateTime object." ) );
160 }
161 0 $dt = $dt->clone;
162 }
163 else
164 {
165 # try-catch
166 eval
167 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DateTime } } or return $self->error("Unable to load the module DateTime: $@") 0 0 0
168 0 require DateTime;
169 } || return( $self->error( "Unable to load the module DateTime: $@" ) );
170 0 $dt = DateTime->now;
171 }
172  
173 0 ▶ my $locale = $self->{locale} || die( "Locale object value is gone!" );
Condition0%0/2
$self->{'locale'} || die('Locale object value is gone!')
l!l
00
MC/DC0%0/1
$self->{'locale'} || die('Locale object value is gone!')
$self->{'locale'}
Truth table0%0/2
A
A= $self->{'locale'}
Aresult
11
00
174 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
175 0 ▶ my $pat = $opts->{pattern} || $self->{pattern};
Condition0%0/3
$opts->{'pattern'} || $self->{'pattern'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'pattern'} || $self->{'pattern'}
$opts->{'pattern'} $self->{'pattern'}
Truth table0%0/3
A || B
A= $opts->{'pattern'}B= $self->{'pattern'}
ABresult
1X1
011
000
176 0 ▶ return( "No format pattern was provided." ) if( !length( $pat // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($pat // "") 0 0 0
Condition0%0/2
$pat // ""
l!l
00
MC/DC0%0/1
$pat // ""
$pat
Truth table0%0/2
A
A= $pat
Aresult
11
00
177 eval
178 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $dt->set_locale($unicode) } } or return $self->error("Error setting the locale value $unicode to the DateTime object: $@") 0 0 0
179 0 $dt->set_locale( $unicode );
180 } || return( $self->error( "Error setting the locale value ${unicode} to the DateTime object: $@" ) );
181  
182 0 my $map = $self->_get_helper_methods;
183  
184 my $cldr_pattern = sub
185 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
186 0 my $pattern = shift( @_ );
187 0 my $token = substr( $pattern, 0, 1 );
188 0 ▶ if( exists( $map->{ $token } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map->{$token}) { } 0 0 0
189 {
190 0 my $code = $map->{ $token };
191 0 my $str = $code->( $self, $token, length( $pattern ), $dt );
192 0 ▶ return( $str // '' );
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
193 }
194 # Unknown, we return the pattern as-is
195 else
196 {
197 0 return( $pattern );
198 }
199 0 };
200  
201 # try-catch
202 eval
203 0 {
204 0 $pat =~ s{
205 \G
206 (?:
207 '((?:[^']|'')*)' # quote escaped bit of text
208 # it needs to end with one
209 # quote not followed by
210 # another
211 |
212 (([a-zA-Z])\3*) # could be a pattern
213 |
214 (.) # anything else
215 )
216 }
217 {
218 0 ▶ if( defined( $1 ) )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $1) { } 0 0 0
elsif (defined $2) { } 0 0 0
elsif (defined $4) { } 0 0 0
219 {
220 0 $1;
221 }
222 elsif( defined( $2 ) )
223 {
224 0 $cldr_pattern->( $2 );
225 }
226 elsif( defined( $4 ) )
227 {
228 0 $4;
229 }
230 else
231 {
232 0 undef;
233 }
234 }sgex;
235 };
236 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
237 {
238 0 return( $self->error( "Error formatting CLDR pattern for locale $locale: $@" ) );
239 }
240 0 $pat =~ s/\'\'/\'/g;
241 0 return( $pat );
242 }
243  
244 sub format_interval
245 0 ▶{
Subroutine format_interval: not called CC=21 SCAR=61.4
Pod documented
246 0 my $self = shift( @_ );
247 0 my( $dt1, $dt2 ) = @_;
248 0 ▶ if( !defined( $dt1 ) )
Branch: 6 branches
BranchTrueFalseTotal
if (not defined $dt1) { } 0 0 0
elsif (not defined $dt2) { } 0 0 0
elsif (not builtin::blessed($dt1)) { } 0 0 0
elsif (not builtin::blessed($dt2)) { } 0 0 0
elsif (not $dt1->isa('DateTime')) { } 0 0 0
elsif (not $dt2->isa('DateTime')) { } 0 0 0
249 {
250 0 return( $self->error( "No DateTime object provided for the first argument" ) );
251 }
252 elsif( !defined( $dt2 ) )
253 {
254 0 return( $self->error( "No DateTime object provided for the second argument" ) );
255 }
256 elsif( !Scalar::Util::blessed( $dt1 ) )
257 {
258 0 return( $self->error( "First DateTime value provided is not an object." ) );
259 }
260 elsif( !Scalar::Util::blessed( $dt2 ) )
261 {
262 0 return( $self->error( "Second DateTime value provided is not an object." ) );
263 }
264 elsif( !$dt1->isa( 'DateTime' ) )
265 {
266 0 return( $self->error( "First DateTime value provided is not a DateTime object." ) );
267 }
268 elsif( !$dt2->isa( 'DateTime' ) )
269 {
270 0 return( $self->error( "Second DateTime value provided is not a DateTime object." ) );
271 }
272 0 splice( @_, 0, 2 );
273 0 my $opts = $self->_get_args_as_hash( @_ );
274 0 ▶ my $locale = $self->{locale} || die( "Locale object value is gone!" );
Condition0%0/2
$self->{'locale'} || die('Locale object value is gone!')
l!l
00
MC/DC0%0/1
$self->{'locale'} || die('Locale object value is gone!')
$self->{'locale'}
Truth table0%0/2
A
A= $self->{'locale'}
Aresult
11
00
275 my $unicode = $self->{_unicode} ||
276 0 ▶ return( $self->error( "The DateTime::Locale::FromCLDR object is gone!" ) );
Condition0%0/2
$self->{'_unicode'} || (return $self->error('The DateTime::Locale::FromCLDR object is gone!'))
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || (return $self->error('The DateTime::Locale::FromCLDR object is gone!'))
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
277 0 my $diff = $unicode->interval_greatest_diff( $dt1, $dt2 );
278 0 ▶ if( !defined( $diff ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $diff) { } 0 0 0
elsif (not length $diff) { } 0 0 0
279 {
280 0 return( $self->pass_error( $unicode->error ) );
281 }
282 elsif( !length( $diff ) )
283 {
284 0 ▶ warn( "Warning only: both DateTime object are equal." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
285 0 $diff = 'd';
286 }
287 0 ▶ my $pattern = $opts->{pattern} || $self->pattern;
Condition0%0/3
$opts->{'pattern'} || $self->pattern
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'pattern'} || $self->pattern
$opts->{'pattern'} $self->pattern
Truth table0%0/3
A || B
A= $opts->{'pattern'}B= $self->pattern
ABresult
1X1
011
000
288 0 ▶ if( !length( $pattern // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($pattern // "")) 0 0 0
Condition0%0/2
$pattern // ""
l!l
00
MC/DC0%0/1
$pattern // ""
$pattern
Truth table0%0/2
A
A= $pattern
Aresult
11
00
289 {
290 0 return( $self->error( "No pattern or pattern ID is set." ) );
291 }
292 # $ref is [$part1, $separator, $part2, $full_pattern]
293 0 ▶ my $ref = $unicode->interval_format( $pattern, $diff ) ||
Condition0%0/2
$unicode->interval_format($pattern, $diff) || (return $self->pass_error($unicode->error))
l!l
00
MC/DC0%0/1
$unicode->interval_format($pattern, $diff) || (return $self->pass_error($unicode->error))
$unicode->interval_format($pattern, $diff)
Truth table0%0/2
A
A= $unicode->interval_format($pattern, $diff)
Aresult
11
00
294 return( $self->pass_error( $unicode->error ) );
295 # Unable to find an interval pattern for this greatest difference token
296 # Maybe the user has provided us with a custom pattern?
297 # Let's try to break it down
298 0 ▶ if( !scalar( @$ref ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$ref) 0 0 0
299 {
300 0 ▶ $ref = $unicode->split_interval( pattern => $pattern, greatest_diff => $diff ) ||
Condition0%0/2
$unicode->split_interval('pattern', $pattern, 'greatest_diff', $diff) || (return $self->pass_error($unicode->error))
l!l
00
MC/DC0%0/1
$unicode->split_interval('pattern', $pattern, 'greatest_diff', $diff) || (return $self->pass_error($unicode->error))
$unicode->split_interval('pattern', $pattern, 'greatest_diff', $diff)
Truth table0%0/2
A
A= $unicode->split_interval('pattern', $pattern, 'greatest_diff', $diff)
Aresult
11
00
301 return( $self->pass_error( $unicode->error ) );
302 }
303 0 ▶ if( !scalar( @$ref ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$ref) 0 0 0
304 {
305 0 return( $self->error( "The pattern provided '${pattern}' does not appear to be a valid interval pattern or pattern ID." ) );
306 }
307 0 my $part1 = $self->format_datetime( $dt1, pattern => $ref->[0] );
308 0 ▶ return( $self->pass_error ) if( !defined( $part1 ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $part1 0 0 0
309 0 my $part2 = $self->format_datetime( $dt2, pattern => $ref->[2] );
310 0 ▶ return( $self->pass_error ) if( !defined( $part1 ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $part1 0 0 0
311 0 return( join( $ref->[1], $part1, $part2 ) );
312 }
313  
314 sub locale
315 0 ▶{
Subroutine locale: not called CC=6 SCAR=37.4
Pod documented
316 0 my $self = shift( @_ );
317 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
318 {
319 0 my $locale = shift( @_ );
320 0 ▶ unless( Scalar::Util::blessed( $locale ) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($locale) and $locale->isa("Locale::Unicode")) 0 0 0
Condition0%0/3
builtin::blessed($locale) and $locale->isa("Locale::Unicode")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($locale) and $locale->isa("Locale::Unicode")
builtin::blessed($locale) $locale->isa("Locale::Unicode")
Truth table0%0/3
A and B
A= builtin::blessed($locale)B= $locale->isa("Locale::Unicode")
ABresult
0X0
100
111
321 $locale->isa( 'Locale::Unicode' ) )
322 {
323 0 ▶ $locale = Locale::Unicode->new( "$locale" ) ||
Condition0%0/2
'Locale::Unicode'->new("$locale") || (return $self->pass_error('Locale::Unicode'->error))
l!l
00
MC/DC0%0/1
'Locale::Unicode'->new("$locale") || (return $self->pass_error('Locale::Unicode'->error))
'Locale::Unicode'->new("$locale")
Truth table0%0/2
A
A= 'Locale::Unicode'->new("$locale")
Aresult
11
00
324 return( $self->pass_error( Locale::Unicode->error ) );
325 }
326 0 $self->{locale} = $locale;
327 0 ▶ $self->{_unicode} = DateTime::Locale::FromCLDR->new( $locale ) ||
Condition0%0/2
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
l!l
00
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
'DateTime::Locale::FromCLDR'->new($locale)
Truth table0%0/2
A
A= 'DateTime::Locale::FromCLDR'->new($locale)
Aresult
11
00
328 return( $self->pass_error( DateTime::Locale::FromCLDR->error ) );
329 }
330 0 return( $self->{locale} );
331 }
332  
333 sub on_error
334 0 ▶{
Subroutine on_error: not called CC=5 SCAR=34.0
Pod documented
335 0 my $self = shift( @_ );
336 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
337 {
338 0 my $on_error = shift( @_ );
339 0 ▶ if( defined( $on_error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $on_error) { } 0 0 0
340 {
341 0 ▶ unless( ref( $on_error ) eq 'CODE' ||
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $on_error eq "CODE" or $on_error eq "fatal") 0 0 0
Condition0%0/3
ref $on_error eq "CODE" or $on_error eq "fatal"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $on_error eq "CODE" or $on_error eq "fatal"
ref $on_error eq "CODE" $on_error eq "fatal"
Truth table0%0/3
A or B
A= ref $on_error eq "CODE"B= $on_error eq "fatal"
ABresult
1X1
011
000
342 $on_error eq 'fatal' )
343 {
344 0 return( $self->error( "The value for 'on_error' can only be either a code reference, such as an ananonymous subroutine or a reference to an existing subroutine, or the string 'fatal', or an undefined value." ) );
345 }
346 0 $self->{on_error} = $on_error;
347 }
348 else
349 {
350 0 delete( $self->{on_error} );
351 }
352 }
353 0 return( $self->{on_error} );
354 }
355  
356 sub pass_error
357 0 ▶{
Subroutine pass_error: not called CC=37 SCAR=71.8
Pod undocumented
358 0 my $self = shift( @_ );
359 0 ▶ my $pack = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
360 0 my $opts = {};
361 0 my( $err, $class, $code );
362 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
363 0 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 0 0
364 {
365 # Either an hash defining a new error and this will be passed along to error(); or
366 # an hash with a single property: { class => 'Some::ExceptionClass' }
367 0 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
368 {
369 0 $opts = $_[0];
370 }
371 else
372 {
373 0 ▶ if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH") 0 0 0
Condition0%0/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1 ref $_[-1] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
374 {
375 0 $opts = pop( @_ );
376 }
377 0 $err = $_[0];
378 }
379 }
380 0 ▶ $err = $opts->{error} if( !defined( $err ) && CORE::exists( $opts->{error} ) && defined( $opts->{error} ) && CORE::length( $opts->{error} ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"} 0 0 0
Condition0%0/9
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
!ll&&!rl&&r
000
not defined $err and exists $opts->{"error"} and defined $opts->{"error"}
!ll&&!rl&&r
000
not defined $err and exists $opts->{"error"}
!ll&&!rl&&r
000
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 table0%0/5
not(A) and B and C and D
A= not defined $errB= exists $opts->{"error"}C= defined $opts->{"error"}D= length $opts->{"error"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
381 # We set $class only if the hash provided is a one-element hash and not an error-defining hash
382 0 ▶ $class = $opts->{class} if( CORE::exists( $opts->{class} ) && defined( $opts->{class} ) && CORE::length( $opts->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"} 0 0 0
Condition0%0/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
!ll&&!rl&&r
000
exists $opts->{"class"} and defined $opts->{"class"}
!ll&&!rl&&r
000
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 table0%0/4
A and B and C
A= exists $opts->{"class"}B= defined $opts->{"class"}C= length $opts->{"class"}
ABCresult
0XX0
10X0
1100
1111
383 0 ▶ $code = $opts->{code} if( CORE::exists( $opts->{code} ) && defined( $opts->{code} ) && CORE::length( $opts->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"} 0 0 0
Condition0%0/6
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
!ll&&!rl&&r
000
exists $opts->{"code"} and defined $opts->{"code"}
!ll&&!rl&&r
000
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 table0%0/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length $opts->{"code"}
ABCresult
0XX0
10X0
1100
1111
384
385 # called with no argument, most likely from the same class to pass on an error
386 # set up earlier by another method; or
387 # with an hash containing just one argument class => 'Some::ExceptionClass'
388 0 ▶ if( !defined( $err ) && ( !scalar( @_ ) || defined( $class ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $err and !scalar(@_) || defined $class) { } 0 0 0
elsif (defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class) { } 0 0 0
Condition0%0/6
not defined $err and !scalar(@_) || defined $class
!ll&&!rl&&r
000
not scalar @_ or defined $class
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $err and !scalar(@_) || defined $class
not defined $err not scalar @_ defined $class
Truth table0%0/4
not(A) and not(B) or C
A= not defined $errB= not scalar @_C= defined $class
ABCresult
0XX0
1000
11X1
1011
389 {
390 # $error is a previous erro robject
391 0 ▶ my $error = ref( $self ) ? $self->{error} : length( ${ $pack . '::ERROR' } ) ? ${ $pack . '::ERROR' } : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $self ? : 0 0 0
length ${$pack . '::ERROR';} ? : 0 0 0
392 0 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 0 0
393 {
394 0 warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef" );
395 }
396 else
397 {
398 0 ▶ $err = ( defined( $class ) ? bless( $error => $class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 0 0
399 0 ▶ $err->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 0 0
400 }
401 }
402 ▶ elsif( defined( $err ) &&
Condition0%0/12
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class
!ll&&!rl&&r
000
defined $err and builtin::blessed($err)
!ll&&!rl&&r
000
scalar @_ == 1 or scalar @_ == 2 and defined $class
l!l&&r!l&&!r
000
scalar @_ == 2 and defined $class
!ll&&!rl&&r
000
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 table0%0/6
A and B and C or D and E
A= defined $errB= builtin::blessed($err)C= scalar @_ == 1D= scalar @_ == 2E= defined $class
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
403 Scalar::Util::blessed( $err ) &&
404 ( scalar( @_ ) == 1 ||
405 ( scalar( @_ ) == 2 && defined( $class ) )
406 ) )
407 {
408 0 ▶ $self->{error} = ${ $pack . '::ERROR' } = ( defined( $class ) ? bless( $err => $class ) : $err );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 0 0
409 0 ▶ $self->{error}->code( $code ) if( defined( $code ) && $self->{error}->can( 'code' ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code and $self->{"error"}->can("code") 0 0 0
Condition0%0/3
defined $code and $self->{"error"}->can("code")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $code and $self->{"error"}->can("code")
defined $code $self->{"error"}->can("code")
Truth table0%0/3
A and B
A= defined $codeB= $self->{"error"}->can("code")
ABresult
0X0
100
111
410
411 0 ▶ if( $self->{fatal} || ( defined( ${"${class}\::FATAL_EXCEPTIONS"} ) && ${"${class}\::FATAL_EXCEPTIONS"} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fatal"} or defined ${"${class}::FATAL_EXCEPTIONS";} and ${"${class}::FATAL_EXCEPTIONS";}) 0 0 0
Condition0%0/6
$self->{"fatal"} or defined ${"${class}::FATAL_EXCEPTIONS";} and ${"${class}::FATAL_EXCEPTIONS";}
l!l&&r!l&&!r
000
defined ${"${class}::FATAL_EXCEPTIONS";} and ${"${class}::FATAL_EXCEPTIONS";}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"fatal"} or defined ${"${class}::FATAL_EXCEPTIONS";} and ${"${class}::FATAL_EXCEPTIONS";}
$self->{"fatal"} defined ${"${class}::FATAL_EXCEPTIONS";} ${"${class}::FATAL_EXCEPTIONS";}
Truth table0%0/4
A or B and C
A= $self->{"fatal"}B= defined ${"${class}::FATAL_EXCEPTIONS";}C= ${"${class}::FATAL_EXCEPTIONS";}
ABCresult
1XX1
0111
00X0
0100
412 {
413 0 die( $self->{error} );
414 }
415 }
416 # If the error provided is not an object, we call error to create one
417 else
418 {
419 0 return( $self->error( @_ ) );
420 }
421
422 0 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 0 0
423 {
424 0 rreturn( DateTime::Format::Unicode::NullObject->new );
425 }
426 0 return;
427 }
428  
429 sub pattern
430 0 ▶{
Subroutine pattern: not called CC=3 SCAR=24.8
Pod documented
431 0 my $self = shift( @_ );
432 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
433 {
434 0 my $pattern = shift( @_ );
435 0 ▶ defined( $pattern ) || return( $self->error( "Pattern provided is empty." ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $pattern or return $self->error("Pattern provided is empty.") 0 0 0
436 0 $self->{pattern} = $pattern;
437 }
438 0 return( $self->{pattern} );
439 }
440  
441 sub time_zone
442 0 ▶{
Subroutine time_zone: not called CC=7 SCAR=40.3
Pod documented
443 0 my $self = shift( @_ );
444 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
445 {
446 0 my $tz = shift( @_ );
447 0 local $@;
448 0 ▶ unless( Scalar::Util::blessed( $tz ) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($tz) and $tz->isa("DateTime::TimeZone")) 0 0 0
Condition0%0/3
builtin::blessed($tz) and $tz->isa("DateTime::TimeZone")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($tz) and $tz->isa("DateTime::TimeZone")
builtin::blessed($tz) $tz->isa("DateTime::TimeZone")
Truth table0%0/3
A and B
A= builtin::blessed($tz)B= $tz->isa("DateTime::TimeZone")
ABresult
0X0
100
111
449 $tz->isa( 'DateTime::TimeZone' ) )
450 {
451 # try-catch
452 eval
453 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DateTime::TimeZone } } or return $self->error("Unable to load the module DateTime::TimeZone: $@") 0 0 0
454 0 require DateTime::TimeZone;
455 } || return( $self->error( "Unable to load the module DateTime::TimeZone: $@" ) );
456  
457 # try-catch
458 $tz = eval
459 0 ▶ {
Condition0%0/2
eval { do { 'DateTime::TimeZone'->new('name', "$tz") } } || (return $self->error("Unable to instantiate a new DateTime::TimeZone object from '${tz}': ", $@ || 'unknown error'))
l!l
00
MC/DC0%0/1
eval { do { 'DateTime::TimeZone'->new('name', "$tz") } } || (return $self->error("Unable to instantiate a new DateTime::TimeZone object from '${tz}': ", $@ || 'unknown error'))
eval { do { 'DateTime::TimeZone'->new('name', "$tz") } }
Truth table0%0/2
A
A= eval { do { 'DateTime::TimeZone'->new('name', "$tz") } }
Aresult
11
00
460 0 ▶ DateTime::TimeZone->new( name => "${tz}" );
Condition0%0/2
$@ || 'unknown error'
l!l
00
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
461 } || return( $self->error( "Unable to instantiate a new DateTime::TimeZone object from '${tz}': ", ( $@ || 'unknown error' ) ) );
462 }
463 0 $self->{time_zone} = $tz;
464 }
465 0 return( $self->{time_zone} );
466 }
467  
468 # NOTE: pattern a
469 # AM/PM
470 sub _format_am_pm
471 0 ▶{
Subroutine _format_am_pm: not called CC=10 SCAR=47.0
472 0 my( $self, $token, $len, $dt ) = @_;
473 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
474 # "a..aaa" (Abbreviated)
475 # Example: am. [e.g. 12 am.]
476 0 ▶ if( $len >= 1 && $len <= 3 )
Branch: 3 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 3
$len >= 1 $len <= 3
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 3
ABresult
0X0
100
111
477 {
478 0 ▶ return( $unicode->am_pm_format_abbreviated->[ $dt->hour < 12 ? 0 : 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
$dt->hour < 12 ? : 0 0 0
479 }
480 # "aaaa" (Wide)
481 # Example: am. [e.g. 12 am.]
482 elsif( $len == 4 )
483 {
484 0 ▶ return( $unicode->am_pm_format_wide->[ $dt->hour < 12 ? 0 : 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
$dt->hour < 12 ? : 0 0 0
485 }
486 # "aaaaa" (Narrow)
487 # Example: a [e.g. 12a]
488 elsif( $len == 5 )
489 {
490 0 ▶ return( $unicode->am_pm_format_narrow->[ $dt->hour < 12 ? 0 : 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
$dt->hour < 12 ? : 0 0 0
491 }
492 else
493 {
494 0 ▶ warn( "Unknown length '${len}' to format am/pm" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
495 0 return( $token x $len );
496 }
497 }
498  
499 # NOTE: pattern U
500 # Missing in DateTime
501 # "If the calendar does not provide cyclic year name data, or if the year value to be formatted is out of the range of years for which cyclic name data is provided, then numeric formatting is used (behaves like 'y')."
502 sub _format_cyclic_year_name
503 0 ▶{
Subroutine _format_cyclic_year_name: not called CC=16 SCAR=56.1
504 0 my( $self, $token, $len, $dt ) = @_;
505 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
506 0 my $year = $dt->year;
507 # Abbreviated
508 0 ▶ if( $len >= 1 && $len <= 3 )
Branch: 3 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 3
$len >= 1 $len <= 3
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 3
ABresult
0X0
100
111
509 {
510 0 ▶ my $era = $unicode->era_abbreviated->[ $year < 0 ? 0 : 1 ];
Branch: 1 branch
BranchTrueFalseTotal
$year < 0 ? : 0 0 0
511 0 ▶ $era = $year if( !length( $era // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($era // "") 0 0 0
Condition0%0/2
$era // ""
l!l
00
MC/DC0%0/1
$era // ""
$era
Truth table0%0/2
A
A= $era
Aresult
11
00
512 0 return( $era );
513 }
514 # Wide
515 elsif( $len == 4 )
516 {
517 0 ▶ my $era = $unicode->era_wide->[ $year < 0 ? 0 : 1 ];
Branch: 1 branch
BranchTrueFalseTotal
$year < 0 ? : 0 0 0
518 0 ▶ $era = $year if( !length( $era // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($era // "") 0 0 0
Condition0%0/2
$era // ""
l!l
00
MC/DC0%0/1
$era // ""
$era
Truth table0%0/2
A
A= $era
Aresult
11
00
519 0 return( $era );
520 }
521 # Narrow
522 elsif( $len == 5 )
523 {
524 0 ▶ my $era = $unicode->era_narrow->[ $year < 0 ? 0 : 1 ];
Branch: 1 branch
BranchTrueFalseTotal
$year < 0 ? : 0 0 0
525 0 ▶ $era = $year if( !length( $era // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($era // "") 0 0 0
Condition0%0/2
$era // ""
l!l
00
MC/DC0%0/1
$era // ""
$era
Truth table0%0/2
A
A= $era
Aresult
11
00
526 0 return( $era );
527 }
528 else
529 {
530 0 ▶ warn( "Unknown length '${len}' to format era name" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
531 0 return( $token x $len );
532 }
533 }
534  
535 # NOTE: pattern g
536 sub _format_day_julian
537 0 ▶{
Subroutine _format_day_julian: not called CC=4 SCAR=30.0
538 0 my( $self, $token, $len, $dt ) = @_;
539 0 ▶ if( $len >= 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1) { } 0 0 0
540 {
541 0 my $rv = sprintf( '%0*d', $len, $dt->mjd );
542 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
543 0 return( $rv );
544 }
545 else
546 {
547 0 ▶ warn( "Unknown length '${len}' to format julian day" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
548 0 return( $token x $len );
549 }
550 }
551  
552 # NOTE: pattern d
553 sub _format_day_of_month
554 0 ▶{
Subroutine _format_day_of_month: not called CC=5 SCAR=34.0
555 0 my( $self, $token, $len, $dt ) = @_;
556 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
557 {
558 0 my $rv = sprintf( '%0*d', $len, $dt->day_of_month );
559 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
560 0 return( $rv );
561 }
562 else
563 {
564 0 ▶ warn( "Unknown length '${len}' to format day of month" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
565 0 return( $token x $len );
566 }
567 }
568  
569 # NOTE: pattern E or e
570 # E: Day of week name, format style.
571 # Same as 'e', but no numeric day
572 # The short format is left out in DateTime->format_cldr and DateTime::Locale::FromData
573 #
574 # e: Local day of week number/name. Same as 'E' except adds a numeric value
575 # The short format is left out in DateTime->format_cldr and DateTime::Locale::FromData
576 sub _format_day_of_week
577 0 ▶{
Subroutine _format_day_of_week: not called CC=14 SCAR=53.5
578 0 my( $self, $token, $len, $dt ) = @_;
579 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
580 0 ▶ if( $len >= 1 && $len <= 3 && $token eq 'E' )
Branch: 6 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 3 and $token eq 'E') { } 0 0 0
elsif ($len >= 1 and $len <= 2 and $token eq 'e') { } 0 0 0
elsif ($len == 3 and $token eq 'e') { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
elsif ($len == 6) { } 0 0 0
Condition0%0/6
$len >= 1 and $len <= 3 and $token eq "E"
!ll&&!rl&&r
000
$len >= 1 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/3
$len >= 1 and $len <= 3 and $token eq "E"
$len >= 1 $len <= 3 $token eq "E"
Truth table0%0/4
A and B and C
A= $len >= 1B= $len <= 3C= $token eq "E"
ABCresult
0XX0
10X0
1100
1111
581 {
582 0 return( $unicode->day_format_abbreviated->[ $dt->day_of_week_0 ] );
583 }
584 ▶ elsif( $len >= 1 && $len <= 2 && $token eq 'e' )
Condition0%0/6
$len >= 1 and $len <= 2 and $token eq "e"
!ll&&!rl&&r
000
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/3
$len >= 1 and $len <= 2 and $token eq "e"
$len >= 1 $len <= 2 $token eq "e"
Truth table0%0/4
A and B and C
A= $len >= 1B= $len <= 2C= $token eq "e"
ABCresult
0XX0
10X0
1100
1111
585 {
586 0 return( sprintf( '%0*d', $len, $dt->local_day_of_week ) );
587 }
588 ▶ elsif( $len == 3 && $token eq 'e' )
Condition0%0/3
$len == 3 and $token eq "e"
!ll&&!rl&&r
000
MC/DC0%0/2
$len == 3 and $token eq "e"
$len == 3 $token eq "e"
Truth table0%0/3
A and B
A= $len == 3B= $token eq "e"
ABresult
0X0
100
111
589 {
590 0 return( $unicode->day_format_abbreviated->[ $dt->day_of_week_0 ] );
591 }
592 # Works for both E and e
593 elsif( $len == 4 )
594 {
595 0 return( $unicode->day_format_wide->[ $dt->day_of_week_0 ] );
596 }
597 # Works for both E and e
598 elsif( $len == 5 )
599 {
600 0 return( $unicode->day_format_narrow->[ $dt->day_of_week_0 ] );
601 }
602 # Works for both E and e
603 elsif( $len == 6 )
604 {
605 0 return( $unicode->day_format_short->[ $dt->day_of_week_0 ] );
606 }
607 else
608 {
609 0 ▶ warn( "Unknown length '${len}' to format day of week" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
610 0 return( $token x $len );
611 }
612 }
613  
614 # NOTE: pattern F
615 # Day of Week in Month (numeric)
616 # DateTime: "Returns a number from 1..5 indicating which week day of the month this is. For example, June 9, 2003 is the second Monday of the month, and so this method returns 2 for that date."
617 sub _format_day_of_week_in_month
618 0 ▶{
Subroutine _format_day_of_week_in_month: not called CC=3 SCAR=19.2
619 0 my( $self, $token, $len, $dt ) = @_;
620 0 ▶ if( $len == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len == 1) { } 0 0 0
621 {
622 1 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
623 0 return( ( ( $dt->day - 1 ) / 7 ) + 1 );
624 }
625 else
626 {
627 0 ▶ warn( "Unknown length '${len}' to format day of week in month" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
628 0 return( $token x $len );
629 }
630 }
631  
632 # NOTE: pattern D
633 sub _format_day_of_year
634 0 ▶{
Subroutine _format_day_of_year: not called CC=5 SCAR=34.0
635 0 my( $self, $token, $len, $dt ) = @_;
636 0 ▶ if( $len >= 1 && $len <= 3 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1 and $len <= 3) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 3
$len >= 1 $len <= 3
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 3
ABresult
0X0
100
111
637 {
638 0 my $rv = sprintf( '%0*d', $len, $dt->day_of_year );
639 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
640 0 return( $rv );
641 }
642 else
643 {
644 0 ▶ warn( "Unknown length '${len}' to format day of year" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
645 0 return( $token x $len );
646 }
647 }
648  
649 # NOTE: pattern b or B -> day period
650 # Day period: am, pm, noon, midnight, etc
651 # Missing in DateTime and DateTime::Locale::FromData
652 sub _format_day_period
653 0 ▶{
Subroutine _format_day_period: not called CC=10 SCAR=47.0
654 0 my( $self, $token, $len, $dt ) = @_;
655 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
656 # "b..bbb" (Abbreviated)
657 # Example: mid. [e.g. 12 mid.]
658 # "B..BBB" (Abbreviated)
659 # Example: at night -> [e.g. 3:00 at night]
660 0 ▶ if( $len >= 1 && $len <= 3 )
Branch: 3 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 3
$len >= 1 $len <= 3
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 3
ABresult
0X0
100
111
661 {
662 0 ▶ if( $token eq 'B' )
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq 'B') { } 0 0 0
663 {
664 0 return( $unicode->day_period_format_abbreviated( $dt ) );
665 }
666 # b
667 else
668 {
669 0 return( $unicode->day_period_stand_alone_abbreviated( $dt ) );
670 }
671 }
672 # "bbbb" (Wide)
673 # Example: midnight
674 # "BBBB" (Wide)
675 # Example: at night -> [e.g. 3:00 at night]
676 elsif( $len == 4 )
677 {
678 0 ▶ if( $token eq 'B' )
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq 'B') { } 0 0 0
679 {
680 0 return( $unicode->day_period_format_wide( $dt ) );
681 }
682 else
683 {
684 0 return( $unicode->day_period_stand_alone_wide( $dt ) );
685 }
686 }
687 # "bbbbb" (Narrow)
688 # Example: md [e.g. 12 md]
689 # "BBBBB" (Narrow)
690 # Example: at night -> [e.g. 3:00 at night]
691 elsif( $len == 5 )
692 {
693 0 ▶ if( $token eq 'B' )
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq 'B') { } 0 0 0
694 {
695 0 return( $unicode->day_period_format_narrow( $dt ) );
696 }
697 else
698 {
699 0 return( $unicode->day_period_stand_alone_narrow( $dt ) );
700 }
701 }
702 else
703 {
704 0 ▶ warn( "Unknown length '${len}' to format day period" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
705 0 return( $token x $len );
706 }
707 }
708  
709 # NOTE: pattern G
710 sub _format_era
711 0 ▶{
Subroutine _format_era: not called CC=8 SCAR=42.8
712 0 my( $self, $token, $len, $dt ) = @_;
713 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
714 0 ▶ if( $len > 0 && $len <= 3 )
Branch: 2 branches
BranchTrueFalseTotal
if ($len > 0 and $len <= 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
Condition0%0/3
$len > 0 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$len > 0 and $len <= 3
$len > 0 $len <= 3
Truth table0%0/3
A and B
A= $len > 0B= $len <= 3
ABresult
0X0
100
111
715 {
716 0 ▶ return( $unicode->era_abbreviated->[ $dt->year < 0 ? 0 : 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
$dt->year < 0 ? : 0 0 0
717 }
718 elsif( $len == 4 )
719 {
720 0 ▶ return( $unicode->era_wide->[ $dt->year < 0 ? 0 : 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
$dt->year < 0 ? : 0 0 0
721 }
722 # >= 5
723 else
724 {
725 0 ▶ return( $unicode->era_narrow->[ $dt->year < 0 ? 0 : 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
$dt->year < 0 ? : 0 0 0
726 }
727 }
728  
729 # NOTE: pattern K -> hour (0-11)
730 sub _format_hour_0_11
731 0 ▶{
Subroutine _format_hour_0_11: not called CC=3 SCAR=24.8
732 0 my( $self, $token, $len, $dt ) = @_;
733 0 ▶ $len = 2 if( $len > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $len > 2 0 0 0
734 0 my $rv = sprintf( '%0*d', $len, $dt->hour_12_0 );
735 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
736 0 return( $rv );
737 }
738  
739 # NOTE: pattern H -> hour (0-23)
740 sub _format_hour_0_23
741 0 ▶{
Subroutine _format_hour_0_23: not called CC=3 SCAR=24.8
742 0 my( $self, $token, $len, $dt ) = @_;
743 0 ▶ $len = 2 if( $len > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $len > 2 0 0 0
744 0 my $rv = sprintf( '%0*d', $len, $dt->hour );
745 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
746 0 return( $rv );
747 }
748  
749 # NOTE: pattern h -> hour (1-12)
750 sub _format_hour_1_12
751 0 ▶{
Subroutine _format_hour_1_12: not called CC=3 SCAR=24.8
752 0 my( $self, $token, $len, $dt ) = @_;
753 0 ▶ $len = 2 if( $len > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $len > 2 0 0 0
754 0 my $rv = sprintf( '%0*d', $len, $dt->hour_12 );
755 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
756 0 return( $rv );
757 }
758  
759 # NOTE: pattern k -> hour (1-24)
760 sub _format_hour_1_24
761 0 ▶{
Subroutine _format_hour_1_24: not called CC=3 SCAR=24.8
762 0 my( $self, $token, $len, $dt ) = @_;
763 0 ▶ $len = 2 if( $len > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $len > 2 0 0 0
764 0 my $rv = sprintf( '%0*d', $len, $dt->hour_1 );
765 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
766 0 return( $rv );
767 }
768  
769 # NOTE: pattern C -> hour (allowed, first match)
770 0 ▶sub _format_hour_allowed { return( shift->_format_hour_allowed_preferred( 'allowed', @_) ); }
Subroutine _format_hour_allowed: not called CC=1 SCAR=6.9
771  
772 sub _format_hour_allowed_preferred
773 0 ▶{
Subroutine _format_hour_allowed_preferred: not called CC=27 SCAR=66.3
774 0 my( $self, $type, $token, $len, $dt ) = @_;
775 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
776 0 my $ref;
777 0 ▶ if( $type eq 'allowed' )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'allowed') { } 0 0 0
elsif ($type eq 'preferred') { } 0 0 0
778 {
779 0 $ref = $unicode->time_format_allowed;
780 0 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $ref ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $unicode->error 0 0 0
Condition0%0/3
not defined $ref and $unicode->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $unicode->error
not defined $ref $unicode->error
Truth table0%0/3
not(A) and B
A= not defined $refB= $unicode->error
ABresult
0X0
100
111
781 }
782 elsif( $type eq 'preferred' )
783 {
784 0 my $this = $unicode->time_format_preferred;
785 0 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $this ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $this and $unicode->error 0 0 0
Condition0%0/3
not defined $this and $unicode->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $this and $unicode->error
not defined $this $unicode->error
Truth table0%0/3
not(A) and B
A= not defined $thisB= $unicode->error
ABresult
0X0
100
111
786 0 $ref = [$this];
787 }
788 else
789 {
790 0 die( "Unknown type '${type}'. Choose either 'allowed' or 'preferred'." );
791 }
792 0 my $pat = $ref->[0];
793 # Possible tokens: H, h, K, k, B, b
794 0 ▶ my $time_tokens = [split( //, ( $pat // '' ) )];
Condition0%0/2
$pat // ""
l!l
00
MC/DC0%0/1
$pat // ""
$pat
Truth table0%0/2
A
A= $pat
Aresult
11
00
795 0 my $res = [];
796 my $map =
797 {
798 # "C"
799 # Example: 8
800 # 8 (morning)
801 # Numeric hour (minimum digits), abbreviated dayPeriod if used
802 0 ▶ 1 => { digits => 1, B => sub{ $unicode->day_period_format_abbreviated( $dt ) }, b => sub{ $unicode->day_period_stand_alone_abbreviated } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
803 # "CC"
804 # Example: 08
805 # 08 (morning)
806 # Numeric hour (2 digits, zero pad if needed), abbreviated dayPeriod if used
807 0 ▶ 2 => { digits => 2, B => sub{ $unicode->day_period_format_abbreviated( $dt ) }, b => sub{ $unicode->day_period_stand_alone_abbreviated( $dt ) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
808 0 ▶ 3 => { digits => 1, B => sub{ $unicode->day_period_format_wide( $dt ) }, b => sub{ $unicode->day_period_stand_alone_wide( $dt ) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
809 0 ▶ 4 => { digits => 2, B => sub{ $unicode->day_period_format_wide( $dt ) }, b => sub{ $unicode->day_period_stand_alone_wide( $dt ) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
810 0 ▶ 5 => { digits => 1, B => sub{ $unicode->day_period_format_narrow( $dt ) }, b => sub{ $unicode->day_period_stand_alone_narrow( $dt ) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
811 0 ▶ 6 => { digits => 2, B => sub{ $unicode->day_period_format_narrow( $dt ) }, b => sub{ $unicode->day_period_stand_alone_narrow( $dt ) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
812 0 };
813  
814 # 'J' has only up to 2 characters
815 0 ▶ if( $token eq 'J' )
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "J") 0 0 0
816 {
817 0 delete( $map->{ $_ } ) for( 3..6 );
818 }
819  
820 0 foreach my $tok ( @$time_tokens )
821 {
822 0 ▶ my $def = $map->{ $len } || die( "Unknown length '${len}' to format hour allowed" );
Condition0%0/2
$map->{$len} || die("Unknown length '${len}' to format hour allowed")
l!l
00
MC/DC0%0/1
$map->{$len} || die("Unknown length '${len}' to format hour allowed")
$map->{$len}
Truth table0%0/2
A
A= $map->{$len}
Aresult
11
00
823 0 ▶ if( $tok eq 'H' )
Branch: 5 branches
BranchTrueFalseTotal
if ($tok eq 'H') { } 0 0 0
elsif ($tok eq 'h') { } 0 0 0
elsif ($tok eq 'K') { } 0 0 0
elsif ($tok eq 'k') { } 0 0 0
elsif ($tok eq 'B' || $tok eq 'b' and $token ne 'J') { } 0 0 0
824 {
825 0 my $rv = sprintf( '%0*d', $def->{digits}, $dt->hour );
826 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
827 0 push( @$res, $rv );
828 }
829 elsif( $tok eq 'h' )
830 {
831 0 my $rv = sprintf( '%0*d', $def->{digits}, $dt->hour_12 );
832 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
833 0 push( @$res, $rv );
834 }
835 elsif( $tok eq 'K' )
836 {
837 0 my $rv = sprintf( '%0*d', $def->{digits}, $dt->hour_12_0 );
838 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
839 0 push( @$res, $rv );
840 }
841 elsif( $tok eq 'k' )
842 {
843 0 my $rv = sprintf( '%0*d', $def->{digits}, $dt->hour_1 );
844 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
845 0 push( @$res, $rv );
846 }
847 # J is the flexible "preferred hour format for the locale", except "it requests no dayPeriod marker such as “am/pm”"
848 # <https://unicode.org/reports/tr35/tr35-dates.html#dfst-hour>
849 ▶ elsif( ( $tok eq 'B' || $tok eq 'b' ) && $token ne 'J' )
Condition0%0/6
$tok eq "B" || $tok eq "b" and $token ne "J"
!ll&&!rl&&r
000
$tok eq "B" or $tok eq "b"
l!l&&r!l&&!r
000
MC/DC0%0/3
$tok eq "B" || $tok eq "b" and $token ne "J"
$tok eq "B" $tok eq "b" $token ne "J"
Truth table0%0/5
A or B and C
A= $tok eq "B"B= $tok eq "b"C= $token ne "J"
ABCresult
00X0
1X00
0100
1X11
0111
850 {
851 0 my $str = $def->{ $tok }->();
852 0 ▶ push( @$res, $str ) if( length( $str // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if length($str // "") 0 0 0
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
853 }
854 else
855 {
856 0 ▶ warn( "Unsupported time format token '${tok}'" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
857 }
858 }
859 0 return( join( ' ', @$res ) );
860 }
861  
862 # NOTE: pattern j -> hour (flexible)
863 # Flexible hour format depending on the preferred hour format for the locale (h, H, K, or k)
864 0 ▶sub _format_hour_flexible { return( shift->_format_hour_allowed_preferred( 'preferred', @_ ) ); }
Subroutine _format_hour_flexible: not called CC=1 SCAR=6.9
865  
866 # NOTE: pattern J -> hour (preferred)
867 # "like 'j', it requests the preferred hour format for the locale (h, H, K, or k), as determined by the preferred attribute of the hours element. However, unlike 'j', it requests no dayPeriod marker such as “am/pm” (it is typically used where there is enough context that that is not necessary). For example, with "jmm", 18:00 could appear as “6:00 PM”, while with "Jmm", it would appear as “6:00” (no PM)."
868 0 ▶sub _format_hour_preferred { return( shift->_format_hour_allowed_preferred( 'preferred', @_) ); }
Subroutine _format_hour_preferred: not called CC=1 SCAR=6.9
869  
870 # NOTE: pattern A -> milliseconds
871 # Milliseconds in day (numeric)
872 sub _format_millisecond
873 0 ▶{
Subroutine _format_millisecond: not called CC=4 SCAR=30.0
874 0 my( $self, $token, $len, $dt ) = @_;
875 # "A+"
876 # Example: 69540000
877 0 ▶ if( $len >= 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1) { } 0 0 0
878 {
879 # local_rd_days, local_rd_secs, rd_nanosecs
880 0 my @rd_values = $dt->local_rd_values;
881 0 my $rv = ( $rd_values[1] * 1000 ) + $dt->millisecond;
882 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
883 0 return( $rv );
884 }
885 else
886 {
887 0 ▶ warn( "Unknown length '${len}' to format milliseconds" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
888 0 return( $token x $len );
889 }
890 }
891  
892 # NOTE: pattern m
893 # Minute (numeric). Truncated, not rounded.
894 sub _format_minute
895 0 ▶{
Subroutine _format_minute: not called CC=5 SCAR=34.0
896 0 my( $self, $token, $len, $dt ) = @_;
897 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
898 {
899 0 my $rv = sprintf( '%0*d', $len, $dt->minute );
900 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
901 0 return( $rv );
902 }
903 else
904 {
905 0 ▶ warn( "Unknown length '${len}' to format minute (numeric)" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
906 0 return( $token x $len );
907 }
908 }
909  
910 # NOTE: pattern M
911 # Numeric: minimum digits Format style month number/name
912 sub _format_month
913 0 ▶{
Subroutine _format_month: not called CC=9 SCAR=45.0
914 0 my( $self, $token, $len, $dt ) = @_;
915 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
916 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 4 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
elsif ($len == 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
917 {
918 0 my $rv = sprintf( '%0*d', $len, $dt->month );
919 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
920 0 return( $rv );
921 }
922 elsif( $len == 3 )
923 {
924 0 return( $unicode->month_format_abbreviated->[ $dt->month_0 ] );
925 }
926 elsif( $len == 4 )
927 {
928 0 return( $unicode->month_format_wide->[ $dt->month_0 ] );
929 }
930 elsif( $len == 5 )
931 {
932 0 return( $unicode->month_format_narrow->[ $dt->month_0 ] );
933 }
934 else
935 {
936 0 ▶ warn( "Unknown length '${len}' to format month" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
937 0 return( $token x $len );
938 }
939 }
940  
941 sub _format_offset
942 0 ▶{
Subroutine _format_offset: not called CC=7 SCAR=40.3
943 0 my $self = shift( @_ );
944 0 my $offset = shift( @_ );
945 0 ▶ my $sep = shift( @_ ) || '';
Condition0%0/2
shift @_ || ''
l!l
00
MC/DC0%0/1
shift @_ || ''
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
946 0 ▶ return( $self->error( "No offset was provided." ) ) unless( defined( $offset ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 0 0
947 0 ▶ return( $self->error( "Offset provided (${offset}) is out of bound." ) ) unless( $offset >= -359999 && $offset <= 359999 );
Branch: 1 branch
BranchTrueFalseTotal
unless $offset >= -359999 and $offset <= 359999 0 0 0
Condition0%0/3
$offset >= -359999 and $offset <= 359999
!ll&&!rl&&r
000
MC/DC0%0/2
$offset >= -359999 and $offset <= 359999
$offset >= -359999 $offset <= 359999
Truth table0%0/3
A and B
A= $offset >= -359999B= $offset <= 359999
ABresult
0X0
100
111
948  
949 0 ▶ my $sign = $offset < 0 ? '-' : '+';
Branch: 1 branch
BranchTrueFalseTotal
$offset < 0 ? : 0 0 0
950  
951 0 $offset = abs( $offset );
952  
953 0 my $hours = int( $offset / 3600 );
954 0 $offset %= 3600;
955 0 my $mins = int( $offset / 60 );
956 0 $offset %= 60;
957 0 my $secs = int($offset);
958  
959 return(
960 0 ▶ $secs
Branch: 1 branch
BranchTrueFalseTotal
$secs ? : 0 0 0
961 ? sprintf(
962 '%s%02d%s%02d%s%02d', $sign, $hours, $sep, $mins, $sep, $secs
963 )
964 : sprintf( '%s%02d%s%02d', $sign, $hours, $sep, $mins )
965 );
966 }
967  
968 # NOTE: pattern L
969 # Stand-Alone month number/name
970 sub _format_month_standalone
971 0 ▶{
Subroutine _format_month_standalone: not called CC=9 SCAR=45.0
972 0 my( $self, $token, $len, $dt ) = @_;
973 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
974 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 4 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
elsif ($len == 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
975 {
976 0 my $rv = sprintf( '%0*d', $len, $dt->month );
977 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
978 0 return( $rv );
979 }
980 elsif( $len == 3 )
981 {
982 0 return( $unicode->month_stand_alone_abbreviated->[ $dt->month_0 ] );
983 }
984 elsif( $len == 4 )
985 {
986 0 return( $unicode->month_stand_alone_wide->[ $dt->month_0 ] );
987 }
988 elsif( $len == 5 )
989 {
990 0 return( $unicode->month_stand_alone_narrow->[ $dt->month_0 ] );
991 }
992 else
993 {
994 0 ▶ warn( "Unknown length '${len}' to format month in stand-alone" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
995 0 return( $token x $len );
996 }
997 }
998  
999 # NOTE: pattern Q
1000 sub _format_quarter
1001 0 ▶{
Subroutine _format_quarter: not called CC=9 SCAR=45.0
1002 0 my( $self, $token, $len, $dt ) = @_;
1003 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1004 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 4 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
elsif ($len == 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
1005 {
1006 0 my $rv = sprintf( '%0*d', $len, $dt->quarter );
1007 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1008 0 return( $rv );
1009 }
1010 # Abbreviated
1011 elsif( $len == 3 )
1012 {
1013 0 return( $unicode->quarter_format_abbreviated->[ $dt->quarter_0 ] );
1014 }
1015 # Wide
1016 elsif( $len == 4 )
1017 {
1018 0 return( $unicode->quarter_format_wide->[ $dt->quarter_0 ] );
1019 }
1020 # Narrow
1021 elsif( $len == 5 )
1022 {
1023 # return( $unicode->quarter );
1024 0 return( $unicode->quarter_format_narrow->[ $dt->quarter_0 ] );
1025 }
1026 else
1027 {
1028 0 ▶ warn( "Unknown length '${len}' to format quarter" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1029 0 return( $token x $len );
1030 }
1031 }
1032  
1033 # NOTE: pattern q
1034 # Missing in DateTime
1035 sub _format_quarter_standalone
1036 0 ▶{
Subroutine _format_quarter_standalone: not called CC=9 SCAR=45.0
1037 0 my( $self, $token, $len, $dt ) = @_;
1038 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1039 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 4 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
elsif ($len == 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
1040 {
1041 0 my $rv = sprintf( '%0*d', $len, $dt->quarter );
1042 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1043 0 return( $rv );
1044 }
1045 elsif( $len == 3 )
1046 {
1047 0 return( $unicode->quarter_stand_alone_abbreviated->[ $dt->quarter_0 ] );
1048 }
1049 elsif( $len == 4 )
1050 {
1051 0 return( $unicode->quarter_stand_alone_wide->[ $dt->quarter_0 ] );
1052 }
1053 elsif( $len == 5 )
1054 {
1055 0 return( $unicode->quarter_stand_alone_narrow->[ $dt->quarter_0 ] );
1056 }
1057 else
1058 {
1059 0 ▶ warn( "Unknown length '${len}' to format quarter (standalone)" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1060 0 return( $token x $len );
1061 }
1062 }
1063  
1064 # NOTE: pattern s -> second
1065 sub _format_second
1066 0 ▶{
Subroutine _format_second: not called CC=5 SCAR=34.0
1067 0 my( $self, $token, $len, $dt ) = @_;
1068 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
1069 {
1070 0 my $rv = sprintf( '%0*d', $len, $dt->second );
1071 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1072 0 return( $rv );
1073 }
1074 else
1075 {
1076 0 ▶ warn( "Unknown length '${len}' to format seconds" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1077 0 return( $token x $len );
1078 }
1079 }
1080  
1081 # NOTE: pattern S -> Fractional Second (numeric)
1082 # "Fractional Second (numeric). Truncates, like other numeric time fields, but in this case to the number of digits specified by the field length. (Example shows display using pattern SSSS for seconds value 12.34567)"
1083 sub _format_second_fractional
1084 0 ▶{
Subroutine _format_second_fractional: not called CC=5 SCAR=34.0
1085 0 my( $self, $token, $len, $dt ) = @_;
1086 0 ▶ if( $len >= 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1) { } 0 0 0
1087 {
1088 0 my $nanosecond = $dt->nanosecond;
1089 # Ensure we are working with a full 9-digit number by padding with zeros if necessary
1090 0 my $full_nanosecond = $nanosecond * 10**(9 - length($nanosecond));
1091 0 my $exponent = 9 - $len;
1092 # Borrowed from DateTime
1093 0 ▶ my $formatted_ns = POSIX::floor(
Branch: 1 branch
BranchTrueFalseTotal
$exponent < 0 ? : 0 0 0
1094 (
1095 $exponent < 0
1096 ? $full_nanosecond * 10**-$exponent
1097 : $full_nanosecond / 10**$exponent
1098 )
1099 );
1100 # return( sprintf( '%0*u', $len, $formatted_ns ) );
1101 0 my $rv = sprintf( '%0*u', $len, $formatted_ns );
1102 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1103 0 return( $rv );
1104 }
1105 else
1106 {
1107 0 ▶ warn( "Unknown length '${len}' to format fractional seconds" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1108 0 return( $token x $len );
1109 }
1110 }
1111  
1112 # NOTE: pattern z
1113 sub _format_timezone
1114 0 ▶{
Subroutine _format_timezone: not called CC=13 SCAR=52.0
1115 0 my( $self, $token, $len, $dt ) = @_;
1116 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1117 0 my $tz = $dt->time_zone->name;
1118 # Handle this edge case.
1119 0 ▶ $tz = 'UTC' if( $tz eq 'floating' );
Branch: 1 branch
BranchTrueFalseTotal
if $tz eq "floating" 0 0 0
1120 # The short specific non-location format. Where that is unavailable, falls back to the short localized GMT format ("O").
1121 # Example:
1122 # PDT
1123 0 ▶ if( $len >= 1 && $len <= 3 )
Branch: 2 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 3
$len >= 1 $len <= 3
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 3
ABresult
0X0
100
111
1124 {
1125 0 ▶ my $str = $unicode->format_timezone_non_location(
Branch: 1 branch
BranchTrueFalseTotal
$unicode->is_dst($dt) ? : 0 0 0
1126 timezone => $tz,
1127 # type => [($unicode->is_dst( $dt ) ? 'daylight' : 'standard'), 'generic'],
1128 type => ($unicode->is_dst( $dt ) ? 'daylight' : 'standard'),
1129 width => 'short',
1130 );
1131 0 ▶ if( !length( $str // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($str // "")) 0 0 0
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
1132 {
1133 0 $str = $unicode->format_gmt(
1134 offset => $dt->offset,
1135 width => 'short',
1136 );
1137 }
1138 0 return( $str );
1139 }
1140 # The long specific non-location format. Where that is unavailable, falls back to the long localized GMT format ("OOOO").
1141 # Example:
1142 # Pacific Daylight Time
1143 elsif( $len == 4 )
1144 {
1145 0 ▶ my $str = $unicode->format_timezone_non_location(
Branch: 1 branch
BranchTrueFalseTotal
$unicode->is_dst($dt) ? : 0 0 0
1146 timezone => $tz,
1147 # type => [($unicode->is_dst( $dt ) ? 'daylight' : 'standard'), 'generic'],
1148 type => ($unicode->is_dst( $dt ) ? 'daylight' : 'standard'),
1149 width => 'long',
1150 );
1151 0 ▶ if( !length( $str // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($str // "")) 0 0 0
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
1152 {
1153 0 $str = $unicode->format_gmt(
1154 offset => $dt->offset,
1155 width => 'long',
1156 );
1157 }
1158 0 return( $str );
1159 }
1160 else
1161 {
1162 0 ▶ warn( "Unknown length '${len}' to format short specific non-location time zone." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1163 0 return( $token x $len );
1164 }
1165 }
1166  
1167 # NOTE: pattern V
1168 sub _format_timezone_location
1169 0 ▶{
Subroutine _format_timezone_location: not called CC=24 SCAR=64.0
1170 0 my( $self, $token, $len, $dt ) = @_;
1171 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1172 # Example: Asia/Tokyo
1173 0 my $tz = $dt->time_zone_long_name;
1174 0 my $str;
1175 # The short time zone ID (the BCP47 time zone ID)
1176 # As of CLDR 35, all time zone have a unique short ID
1177 # Example: America/Los_Angeles -> uslax
1178 0 ▶ if( $len == 1 )
Branch: 4 branches
BranchTrueFalseTotal
if ($len == 1) { } 0 0 0
elsif ($len == 2) { } 0 0 0
elsif ($len == 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
1179 {
1180 # Shortcut
1181 0 ▶ return( 'unk' ) if( $tz eq 'floating' );
Branch: 1 branch
BranchTrueFalseTotal
if $tz eq "floating" 0 0 0
1182 # The short generic non-location format
1183 # Where that is unavailable, falls back to the generic location format ("VVVV"),
1184 # then the short localized GMT format as the final fallback
1185 0 $str = $unicode->timezone_id(
1186 timezone => $tz,
1187 );
1188 0 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $str ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $str and $unicode->error 0 0 0
Condition0%0/3
not defined $str and $unicode->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $str and $unicode->error
not defined $str $unicode->error
Truth table0%0/3
not(A) and B
A= not defined $strB= $unicode->error
ABresult
0X0
100
111
1189 0 ▶ $str ||= 'unk';
Condition0%0/2
$str ||= "unk"
l!l
00
MC/DC0%0/1
$str ||= "unk"
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
1190 0 return( $str );
1191 }
1192 # The long time zone ID
1193 # Example: America/Los_Angeles
1194 elsif( $len == 2 )
1195 {
1196 # Etc/Unknown
1197 0 ▶ return( 'unk' ) if( $tz eq 'floating' );
Branch: 1 branch
BranchTrueFalseTotal
if $tz eq "floating" 0 0 0
1198 0 return( "$tz" );
1199 }
1200 # The exemplar city (location) for the time zone
1201 # Example: America/Los_Angeles -> Los Angeles
1202 elsif( $len == 3 )
1203 {
1204 # The exemplar city (location) for the time zone.
1205 # Where that is unavailable, the localized exemplar city name for the special zone Etc/Unknown is used as the fallback (for example, "Unknown City").
1206 # With the Locale::Unicode::Data extended timezones cities data, there are 89 localised versions for each of the 421 time zones exemplar cities
1207 0 ▶ $str = $unicode->timezone_city(
Branch: 1 branch
BranchTrueFalseTotal
unless $tz eq "floating" 0 0 0
1208 timezone => $tz,
1209 ) unless( $tz eq 'floating' );
1210 0 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $str ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $str and $unicode->error 0 0 0
Condition0%0/3
not defined $str and $unicode->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $str and $unicode->error
not defined $str $unicode->error
Truth table0%0/3
not(A) and B
A= not defined $strB= $unicode->error
ABresult
0X0
100
111
1211 0 ▶ if( !length( $str // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($str // "")) 0 0 0
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
1212 {
1213 # Etc/Unknown is guaranteed to exist in each locale
1214 0 $str = $unicode->timezone_city(
1215 timezone => 'Etc/Unknown',
1216 );
1217 0 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $str ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $str and $unicode->error 0 0 0
Condition0%0/3
not defined $str and $unicode->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $str and $unicode->error
not defined $str $unicode->error
Truth table0%0/3
not(A) and B
A= not defined $strB= $unicode->error
ABresult
0X0
100
111
1218 }
1219 0 return( $str );
1220 }
1221 # Example: Los Angeles Time
1222 elsif( $len == 4 )
1223 {
1224 # The generic location format.
1225 # Where that is unavailable, falls back to the long localized GMT format
1226 # ("OOOO"; Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)
1227 0 ▶ $str = $unicode->format_timezone_location(
Branch: 1 branch
BranchTrueFalseTotal
unless $tz eq "floating" 0 0 0
1228 timezone => $tz,
1229 ) unless( $tz eq 'floating' );
1230 0 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $str ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $str and $unicode->error 0 0 0
Condition0%0/3
not defined $str and $unicode->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $str and $unicode->error
not defined $str $unicode->error
Truth table0%0/3
not(A) and B
A= not defined $strB= $unicode->error
ABresult
0X0
100
111
1231 0 ▶ if( !length( $str // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($str // "")) 0 0 0
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
1232 {
1233 0 my $offset = $dt->offset;
1234 0 $str = $unicode->format_gmt(
1235 offset => $offset,
1236 width => 'long',
1237 );
1238 }
1239 0 return( $str );
1240 }
1241 else
1242 {
1243 0 ▶ warn( "Unknown length '${len}' to format time zone" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1244 0 return( $token x $len );
1245 }
1246 }
1247  
1248 # NOTE: pattern v
1249 sub _format_timezone_non_location
1250 0 ▶{
Subroutine _format_timezone_non_location: not called CC=9 SCAR=45.0
1251 0 my( $self, $token, $len, $dt ) = @_;
1252 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1253 0 my $tz = $dt->time_zone->name;
1254 # Handle this edge case.
1255 0 ▶ $tz = 'UTC' if( $tz eq 'floating' );
Branch: 1 branch
BranchTrueFalseTotal
if $tz eq "floating" 0 0 0
1256 0 ▶ if( $len == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if ($len == 1) { } 0 0 0
elsif ($len == 4) { } 0 0 0
1257 {
1258 # The short generic non-location format
1259 # Where that is unavailable, falls back to the generic location format ("VVVV"),
1260 # then the short localized GMT format as the final fallback
1261 0 my $str = $unicode->format_timezone_non_location(
1262 timezone => $tz,
1263 type => 'generic',
1264 width => 'short',
1265 );
1266 0 ▶ if( !$str )
Branch: 1 branch
BranchTrueFalseTotal
unless ($str) 0 0 0
1267 {
1268 0 $str = $unicode->format_timezone_location(
1269 timezone => $tz,
1270 );
1271 }
1272 0 ▶ if( !$str )
Branch: 1 branch
BranchTrueFalseTotal
unless ($str) 0 0 0
1273 {
1274 0 my $offset = $dt->offset;
1275 0 $str = $unicode->format_gmt(
1276 offset => $offset,
1277 width => 'short',
1278 );
1279 }
1280 # return( $dt->time_zone_short_name );
1281 0 return( $str );
1282 }
1283 elsif( $len == 4 )
1284 {
1285 # The long generic non-location format.
1286 # Where that is unavailable, falls back to generic location format ("VVVV")
1287 0 my $str = $unicode->format_timezone_non_location(
1288 timezone => $tz,
1289 type => 'generic',
1290 width => 'long',
1291 );
1292 0 ▶ if( !$str )
Branch: 1 branch
BranchTrueFalseTotal
unless ($str) 0 0 0
1293 {
1294 0 $str = $unicode->format_timezone_location(
1295 timezone => $tz,
1296 );
1297 }
1298 # return( $dt->time_zone_long_name );
1299 0 return( $str );
1300 }
1301 else
1302 {
1303 0 ▶ warn( "Unknown length '${len}' to format time zone" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1304 0 return( $token x $len );
1305 }
1306 }
1307  
1308 # NOTE: pattern O -> zone, e.g. GMT-08:00, or GMT-8
1309 # Missing in DateTime
1310 sub _format_timezone_gmt_offset
1311 0 ▶{
Subroutine _format_timezone_gmt_offset: not called CC=5 SCAR=34.0
1312 0 my( $self, $token, $len, $dt ) = @_;
1313 0 ▶ if( $len == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if ($len == 1) { } 0 0 0
elsif ($len == 4) { } 0 0 0
1314 {
1315 0 my $offset = $dt->offset;
1316 0 ▶ my $sign = $offset < 0 ? '-' : '+';
Branch: 1 branch
BranchTrueFalseTotal
$offset < 0 ? : 0 0 0
1317 0 $offset = abs( $offset );
1318 0 my $hours = int( $offset / 3600 );
1319 0 return( 'GMT' . $sign . $hours );
1320 }
1321 elsif( $len == 4 )
1322 {
1323 0 return( 'GMT' . $self->_format_offset( $dt->offset, ':' ) );
1324 }
1325 else
1326 {
1327 0 ▶ warn( "Unknown length '${len}' to format GMT time zone" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1328 0 return( $token x $len );
1329 }
1330 }
1331  
1332 # NOTE: pattern Z
1333 # Example: +09:00
1334 sub _format_timezone_offset
1335 0 ▶{
Subroutine _format_timezone_offset: not called CC=8 SCAR=42.8
1336 0 my( $self, $token, $len, $dt ) = @_;
1337 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1338 0 my $offset = $dt->offset;
1339 # Example: +0900
1340 0 ▶ if( $len >= 1 && $len <= 3 )
Branch: 3 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 3
$len >= 1 $len <= 3
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 3
ABresult
0X0
100
111
1341 {
1342 0 return( $self->_format_offset( $offset ) );
1343 }
1344 # Example: GMT+0900
1345 elsif( $len == 4 )
1346 {
1347 0 my $str = $unicode->format_gmt(
1348 offset => $offset,
1349 width => 'long',
1350 );
1351 }
1352 # Example: +09:00
1353 # -07:52:58
1354 # "The ISO8601 UTC indicator "Z" is used when local time offset is 0."
1355 elsif( $len == 5 )
1356 {
1357 0 ▶ if( $offset == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == 0) { } 0 0 0
1358 {
1359 0 return( 'Z' );
1360 }
1361 else
1362 {
1363 0 return( $self->_format_offset( $offset, ':' ) );
1364 }
1365 }
1366 else
1367 {
1368 0 ▶ warn( "Unknown length '${len}' to format time zone offset" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1369 0 return( $token x $len );
1370 }
1371 }
1372  
1373 # NOTE: pattern c -> week day
1374 # Stand-Alone local day of week number/name
1375 sub _format_week_day
1376 0 ▶{
Subroutine _format_week_day: not called CC=10 SCAR=47.0
1377 0 my( $self, $token, $len, $dt ) = @_;
1378 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1379 # Not sure the value needs to be padded
1380 # "c..cc"
1381 # Example: 2 (numeric, 1 digit)
1382 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 5 branches
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
elsif ($len == 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
elsif ($len == 6) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
1383 {
1384 0 my $rv = sprintf( '%0*d', $len, $dt->day_of_week );
1385 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1386 0 return( $rv );
1387 }
1388 # "ccc" (Abbreviated)
1389 # Example: Tue
1390 elsif( $len == 3 )
1391 {
1392 0 return( $unicode->day_stand_alone_abbreviated->[ $dt->day_of_week_0 ] );
1393 }
1394 # "cccc" (Wide)
1395 # Example: Tuesday
1396 elsif( $len == 4 )
1397 {
1398 0 return( $unicode->day_stand_alone_wide->[ $dt->day_of_week_0 ] );
1399 }
1400 # "ccccc" (Narrow)
1401 # Example: T
1402 elsif( $len == 5 )
1403 {
1404 0 return( $unicode->day_stand_alone_narrow->[ $dt->day_of_week_0 ] );
1405 }
1406 # "cccccc" (Short)
1407 # Example: Tu
1408 # This is missing in DateTime
1409 elsif( $len == 6 )
1410 {
1411 0 return( $unicode->day_stand_alone_short->[ $dt->day_of_week_0 ] );
1412 }
1413 else
1414 {
1415 0 ▶ warn( "Unknown length '${len}' to format week day" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1416 0 return( $token x $len );
1417 }
1418 }
1419  
1420 # NOTE: pattern w
1421 sub _format_week_number
1422 0 ▶{
Subroutine _format_week_number: not called CC=6 SCAR=37.4
1423 0 my( $self, $token, $len, $dt ) = @_;
1424 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1425 0 ▶ if( $len >= 1 && $len <= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 1 and $len <= 2) { } 0 0 0
Condition0%0/3
$len >= 1 and $len <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$len >= 1 and $len <= 2
$len >= 1 $len <= 2
Truth table0%0/3
A and B
A= $len >= 1B= $len <= 2
ABresult
0X0
100
111
1426 {
1427 0 my $rv = sprintf( '%0*d', $len, $dt->week_number );
1428 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1429 0 return( $rv );
1430 }
1431 else
1432 {
1433 0 ▶ warn( "Unknown length '${len}' to format week number" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1434 0 return( $token x $len );
1435 }
1436 }
1437  
1438 # NOTE: pattern W
1439 sub _format_week_of_month
1440 0 ▶{
Subroutine _format_week_of_month: not called CC=5 SCAR=34.0
1441 0 my( $self, $token, $len, $dt ) = @_;
1442 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1443 0 ▶ if( $len == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len == 1) { } 0 0 0
1444 {
1445 # return( $dt->week_of_month );
1446 0 my $rv = $dt->week_of_month;
1447 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1448 0 return( $rv );
1449 }
1450 else
1451 {
1452 0 ▶ warn( "Unknown length '${len}' to format week of month" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1453 0 return( $token x $len );
1454 }
1455 }
1456  
1457 # NOTE: pattern Y
1458 sub _format_week_year
1459 0 ▶{
Subroutine _format_week_year: not called CC=3 SCAR=24.8
1460 0 my( $self, $token, $len, $dt ) = @_;
1461 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1462 0 my $rv = sprintf( '%0*d', $len, $dt->week_year );
1463 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1464 0 return( $rv );
1465 }
1466  
1467 # NOTE: pattern y
1468 sub _format_year
1469 0 ▶{
Subroutine _format_year: not called CC=11 SCAR=48.8
1470 0 my( $self, $token, $len, $dt ) = @_;
1471 0 ▶ my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
Condition0%0/2
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
l!l
00
MC/DC0%0/1
$self->{'_unicode'} || die('DateTime::Locale::FromCLDR object is gone!')
$self->{'_unicode'}
Truth table0%0/2
A
A= $self->{'_unicode'}
Aresult
11
00
1472 0 my $year = $dt->year;
1473 0 ▶ if( $len == 1 )
Branch: 3 branches
BranchTrueFalseTotal
if ($len == 1) { } 0 0 0
elsif ($len == 2) { } 0 0 0
elsif ($len >= 3) { } 0 0 0
1474 {
1475 0 ▶ $year = $self->_localise_digits( $year ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1476 0 return( $year );
1477 }
1478 elsif( $len == 2 )
1479 {
1480 0 ▶ my $y2 = length( $year > 2 ) ? substr( $year, -2, 2 ) : $year;
Branch: 1 branch
BranchTrueFalseTotal
length($year > 2) ? : 0 0 0
1481 0 ▶ $y2 *= -1 if( $year < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $year < 0 0 0 0
1482 0 my $rv = sprintf( '%02d', $y2 );
1483 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1484 0 return( $rv );
1485 }
1486 # In the CLDR, there is no upper limit
1487 elsif( $len >= 3 )
1488 {
1489 0 my $rv = sprintf( '%0*d', $len, $year );
1490 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1491 0 return( $rv );
1492 }
1493 # < 0 ??
1494 else
1495 {
1496 0 ▶ warn( "Unknown length '${len}' to format year" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1497 0 return( $token x $len );
1498 }
1499 }
1500  
1501 # NOTE: pattern u
1502 sub _format_year_extended
1503 0 ▶{
Subroutine _format_year_extended: not called CC=2 SCAR=17.9
1504 0 my( $self, $token, $len, $dt ) = @_;
1505 0 my $year = $dt->year;
1506 0 my $rv = sprintf( '%0*d', $len, $year );
1507 0 ▶ $rv = $self->_localise_digits( $rv ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1508 0 return( $rv );
1509 }
1510  
1511 # NOTE: pattern r
1512 sub _format_year_related
1513 0 ▶{
Subroutine _format_year_related: not called CC=2 SCAR=17.9
1514 0 my( $self, $token, $len, $dt ) = @_;
1515 0 my $year = $dt->year;
1516 0 $year = sprintf( '%0*d', $len, $year );
1517 0 ▶ $year = $self->_localise_digits( $year ) if( $self->{_number_system} ne 'latn' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_number_system"} ne "latn" 0 0 0
1518 0 return( $year );
1519 }
1520  
1521 # NOTE: pattern x, or X if $has_z is true
1522 sub _format_zone_offset
1523 0 ▶{
Subroutine _format_zone_offset: not called CC=18 SCAR=58.3
1524 0 my( $self, $token, $len, $dt, $has_z ) = @_;
1525 0 ▶ if( $len < 1 || $len > 5 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len < 1 or $len > 5) 0 0 0
Condition0%0/3
$len < 1 or $len > 5
l!l&&r!l&&!r
000
MC/DC0%0/2
$len < 1 or $len > 5
$len < 1 $len > 5
Truth table0%0/3
A or B
A= $len < 1B= $len > 5
ABresult
1X1
011
000
1526 {
1527 0 ▶ warn( "Unknown length '${len}' to format time zone offset" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1528 0 return( $token x $len );
1529 }
1530 0 my $offset = $dt->offset;
1531 # Borrowed from DateTime::TimeZone
1532 0 ▶ return( '' ) unless( defined( $offset ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 0 0
1533 0 ▶ return( '' ) unless( $offset >= -359999 && $offset <= 359999 );
Branch: 1 branch
BranchTrueFalseTotal
unless $offset >= -359999 and $offset <= 359999 0 0 0
Condition0%0/3
$offset >= -359999 and $offset <= 359999
!ll&&!rl&&r
000
MC/DC0%0/2
$offset >= -359999 and $offset <= 359999
$offset >= -359999 $offset <= 359999
Truth table0%0/3
A and B
A= $offset >= -359999B= $offset <= 359999
ABresult
0X0
100
111
1534 # For X format patterns
1535 0 ▶ return( 'Z' ) if( $offset == 0 && $has_z );
Branch: 1 branch
BranchTrueFalseTotal
if $offset == 0 and $has_z 0 0 0
Condition0%0/3
$offset == 0 and $has_z
!ll&&!rl&&r
000
MC/DC0%0/2
$offset == 0 and $has_z
$offset == 0 $has_z
Truth table0%0/3
A and B
A= $offset == 0B= $has_z
ABresult
0X0
100
111
1536 0 ▶ my $sign = ( $offset < 0 ? '-' : '+' );
Branch: 1 branch
BranchTrueFalseTotal
$offset < 0 ? : 0 0 0
1537 0 $offset = abs($offset);
1538 0 my $hours = int( $offset / 3600 );
1539 0 $offset %= 3600;
1540 0 my $mins = int( $offset / 60 );
1541 0 $offset %= 60;
1542 0 my $secs = int( $offset );
1543 # ISO8601 basic format.
1544 # Hours and optional minutes value.
1545 # Same as X, but without the Z
1546 # Example:
1547 # -08
1548 # +0530
1549 # +00
1550 0 ▶ if( $len == 1 )
Branch: 5 branches
BranchTrueFalseTotal
if ($len == 1) { } 0 0 0
elsif ($len == 2) { } 0 0 0
elsif ($len == 3) { } 0 0 0
elsif ($len == 4) { } 0 0 0
elsif ($len == 5) { } 0 0 0
1551 {
1552 0 ▶ return( $mins ? sprintf( '%s%02d%02d', $sign, $hours, $mins ) : sprintf( '%s%02d', $sign, $hours ) );
Branch: 1 branch
BranchTrueFalseTotal
$mins ? : 0 0 0
1553 }
1554 # ISO8601 basic format.
1555 # Hours and minutes values.
1556 # Same as XX, but without the Z
1557 # Example:
1558 # -0800
1559 # +0000
1560 elsif( $len == 2 )
1561 {
1562 0 return( sprintf( '%s%02d%02d', $sign, $hours, $mins ) );
1563 }
1564 # ISO8601 extended format.
1565 # Hours and minutes values.
1566 # Same as XXX, but without the Z
1567 # Example:
1568 # -08:00
1569 # +00:00
1570 elsif( $len == 3 )
1571 {
1572 0 return( sprintf( '%s%02d:%02d', $sign, $hours, $mins ) );
1573 }
1574 # ISO8601 basic format, although the seconds field is not supported by the ISO8601 specification
1575 # Hours, minutes and optional seconds value.
1576 # Same as XXXX, but without the Z
1577 # Example:
1578 # -0800
1579 # -075258
1580 # +0000
1581 elsif( $len == 4 )
1582 {
1583 0 ▶ return( $secs ? sprintf( '%s%02d%02d%02d', $sign, $hours, $mins, $secs ) : sprintf( '%s%02d%02d', $sign, $hours, $mins ) );
Branch: 1 branch
BranchTrueFalseTotal
$secs ? : 0 0 0
1584 }
1585 # ISO8601 extended format, although the seconds field is not supported by the ISO8601 specification
1586 # Hours, minutes and optional seconds value.
1587 # Same as XXXXX, but without the Z
1588 # Example:
1589 # -08:00
1590 # -07:52:58
1591 # +00:00
1592 elsif( $len == 5 )
1593 {
1594 0 ▶ return( $secs ? sprintf( '%s%02d:%02d:%02d', $sign, $hours, $mins, $secs ) : sprintf( '%s%02d:%02d', $sign, $hours, $mins ) );
Branch: 1 branch
BranchTrueFalseTotal
$secs ? : 0 0 0
1595 }
1596 }
1597  
1598 0 ▶sub _format_zone_offset_gmt { return( shift->_format_zone_offset( @_, 1 ) ); }
Subroutine _format_zone_offset_gmt: not called CC=1 SCAR=6.9
1599  
1600 sub _get_helper_methods
1601 0 ▶{
Subroutine _get_helper_methods: not called CC=1 SCAR=6.9
1602 0 my $self = shift( @_ );
1603 0 my $map =
1604 {
1605 'a' => \&_format_am_pm,
1606 'A' => \&_format_millisecond,
1607 'b' => \&_format_day_period,
1608 'B' => \&_format_day_period,
1609 'c' => \&_format_week_day,
1610 'C' => \&_format_hour_allowed,
1611 'd' => \&_format_day_of_month,
1612 'D' => \&_format_day_of_year,
1613 'e' => \&_format_day_of_week,
1614 'E' => \&_format_day_of_week,
1615 'F' => \&_format_day_of_week_in_month,
1616 'g' => \&_format_day_julian,
1617 'G' => \&_format_era,
1618 'h' => \&_format_hour_1_12,
1619 'H' => \&_format_hour_0_23,
1620 'j' => \&_format_hour_flexible,
1621 'J' => \&_format_hour_preferred,
1622 'k' => \&_format_hour_1_24,
1623 'K' => \&_format_hour_0_11,
1624 'L' => \&_format_month_standalone,
1625 'm' => \&_format_minute,
1626 'M' => \&_format_month,
1627 'O' => \&_format_timezone_gmt_offset,
1628 'q' => \&_format_quarter_standalone,
1629 'Q' => \&_format_quarter,
1630 'r' => \&_format_year_related,
1631 's' => \&_format_second,
1632 'S' => \&_format_second_fractional,
1633 'u' => \&_format_year_extended,
1634 'U' => \&_format_cyclic_year_name,
1635 'v' => \&_format_timezone_non_location,
1636 'V' => \&_format_timezone_location,
1637 'w' => \&_format_week_number,
1638 'W' => \&_format_week_of_month,
1639 'x' => \&_format_zone_offset,
1640 'X' => \&_format_zone_offset_gmt,
1641 'y' => \&_format_year,
1642 'Y' => \&_format_week_year,
1643 'z' => \&_format_timezone,
1644 'Z' => \&_format_timezone_offset,
1645 };
1646 0 return( $map );
1647 }
1648  
1649 sub _get_args_as_hash
1650 0 ▶{
Subroutine _get_args_as_hash: not called CC=6 SCAR=37.4
1651 0 my $self = shift( @_ );
1652 0 my $ref = {};
1653 0 ▶ if( scalar( @_ ) == 1 &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and (ref $_[0] || '') eq 'HASH') { } 0 0 0
elsif (not scalar(@_) % 2) { } 0 0 0
Condition0%0/8
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
!ll&&!rl&&r
000
scalar @_ == 1 and defined $_[0]
!ll&&!rl&&r
000
ref $_[0] || ''
l!l
00
MC/DC0%0/3
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
scalar @_ == 1 defined $_[0] ref $_[0]
Truth table0%0/4
A and B and C
A= scalar @_ == 1B= defined $_[0]C= ref $_[0]
ABCresult
0XX0
10X0
1100
1111
1654 defined( $_[0] ) &&
1655 ( ref( $_[0] ) || '' ) eq 'HASH' )
1656 {
1657 0 $ref = shift( @_ );
1658 }
1659 elsif( !( scalar( @_ ) % 2 ) )
1660 {
1661 0 $ref = { @_ };
1662 }
1663 else
1664 {
1665 0 die( "Uneven number of parameters provided." );
1666 }
1667 0 return( $ref );
1668 }
1669  
1670 # We localise the numerals
1671 # "The digits should be whatever are appropriate for the locale used to format the time zone, not necessarily from the western digits, 0..9. For example, they might be from ०..९."
1672 # <https://unicode.org/reports/tr35/tr35-dates.html#Using_Time_Zone_Names>
1673 sub _localise_digits
1674 0 ▶{
Subroutine _localise_digits: not called CC=6 SCAR=37.4
1675 0 my $self = shift( @_ );
1676 0 my $num = shift( @_ );
1677 0 my $digits = $self->{_number_system_digits};
1678 0 ▶ die( "Number systems digits are gone!" ) if( !$digits || ref( $digits ) ne 'ARRAY' || ( ref( $digits ) eq 'ARRAY' && !scalar( @$digits ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $digits or ref $digits ne "ARRAY" or ref $digits eq "ARRAY" and not scalar @$digits 0 0 0
Condition0%0/9
not $digits or ref $digits ne "ARRAY" or ref $digits eq "ARRAY" and not scalar @$digits
l!l&&r!l&&!r
000
not $digits or ref $digits ne "ARRAY"
l!l&&r!l&&!r
000
ref $digits eq "ARRAY" and not scalar @$digits
!ll&&!rl&&r
000
MC/DC0%0/4
not $digits or ref $digits ne "ARRAY" or ref $digits eq "ARRAY" and not scalar @$digits
not $digits ref $digits ne "ARRAY" ref $digits eq "ARRAY" not scalar @$digits
Truth table0%0/5
not(A) or B or C and not(D)
A= not $digitsB= ref $digits ne "ARRAY"C= ref $digits eq "ARRAY"D= not scalar @$digits
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1679 0 my @parts = split( //, $num );
1680 0 ▶ for( my $i = 0; $i < scalar( @parts ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @parts) 0 0 0
1681 {
1682 0 $parts[$i] = $digits->[ $parts[$i] ];
1683 }
1684 0 return( join( '', @parts ) );
1685 }
1686  
1687 sub FREEZE
1688 0 ▶{
Subroutine FREEZE: not called CC=9 SCAR=45.0
Pod undocumented
1689 0 my $self = CORE::shift( @_ );
1690 0 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1691 0 my $class = CORE::ref( $self );
1692 0 my @keys = qw( locale time_zone pattern );
1693 0 my $hash = {};
1694 0 @$hash{ @keys } = @$self{ @keys };
1695 0 ▶ $hash->{on_error} = $self->{on_error} if( exists( $self->{on_error} ) && !ref( $self->{on_error} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"on_error"} and not ref $self->{"on_error"} 0 0 0
Condition0%0/3
exists $self->{"on_error"} and not ref $self->{"on_error"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"on_error"} and not ref $self->{"on_error"}
exists $self->{"on_error"} not ref $self->{"on_error"}
Truth table0%0/3
A and not(B)
A= exists $self->{"on_error"}B= not ref $self->{"on_error"}
ABresult
0X0
100
111
1696 0 ▶ $hash->{time_zone} = $hash->{time_zone}->name if( Scalar::Util::blessed( $hash->{time_zone} ) && $hash->{time_zone}->isa( 'DateTime::TimeZone' ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($hash->{"time_zone"}) and $hash->{"time_zone"}->isa("DateTime::TimeZone") 0 0 0
Condition0%0/3
builtin::blessed($hash->{"time_zone"}) and $hash->{"time_zone"}->isa("DateTime::TimeZone")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($hash->{"time_zone"}) and $hash->{"time_zone"}->isa("DateTime::TimeZone")
builtin::blessed($hash->{"time_zone"}) $hash->{"time_zone"}->isa("DateTime::TimeZone")
Truth table0%0/3
A and B
A= builtin::blessed($hash->{"time_zone"})B= $hash->{"time_zone"}->isa("DateTime::TimeZone")
ABresult
0X0
100
111
1697 0 ▶ $hash->{locale} = "$hash->{locale}" if( defined( $hash->{locale} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash->{"locale"} 0 0 0
1698 # Return an array reference rather than a list so this works with Sereal and CBOR
1699 # On or before Sereal version 4.023, Sereal did not support multiple values returned
1700 0 ▶ CORE::return( [$class, $hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023") 0 0 0
Condition0%0/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
!ll&&!rl&&r
000
MC/DC0%0/2
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table0%0/3
A and B
A= $serialiser eq "Sereal"B= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
ABresult
0X0
100
111
1701 # But Storable want a list with the first element being the serialised element
1702 0 CORE::return( $class, $hash );
1703 }
1704  
1705 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
1706  
1707 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
1708  
1709 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
1710 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
1711 sub THAW
1712 0 ▶{
Subroutine THAW: not called CC=12 SCAR=50.5
Pod undocumented
1713 0 my( $self, undef, @args ) = @_;
1714 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
1715 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
1716 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
1717 0 ▶ if( $hash->{locale} )
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{"locale"}) 0 0 0
1718 {
1719 0 $hash->{locale} = Locale::Unicode->new( $hash->{locale} );
1720 0 $hash->{_unicode} = DateTime::Locale::FromCLDR->new( $hash->{locale} );
1721 }
1722 0 ▶ if( $hash->{time_zone} )
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{"time_zone"}) 0 0 0
1723 {
1724 0 local $@;
1725 # try-catch
1726 $hash->{time_zone} = eval
1727 0 {
1728 0 require DateTime::TimeZone;
1729 0 DateTime::TimeZone->new( name => $hash->{time_zone} );
1730 };
1731 }
1732 0 my $new;
1733 # Storable pattern requires to modify the object it created rather than returning a new one
1734 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
1735 {
1736 0 foreach( CORE::keys( %$hash ) )
1737 {
1738 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
1739 }
1740 0 $new = $self;
1741 }
1742 else
1743 {
1744 0 $new = CORE::bless( $hash => $class );
1745 }
1746 0 CORE::return( $new );
1747 }
1748  
1749 sub TO_JSON
1750 0 ▶{
Subroutine TO_JSON: not called CC=5 SCAR=34.0
Pod undocumented
1751 0 my $self = CORE::shift( @_ );
1752 0 my @keys = qw( locale time_zone pattern );
1753 0 my $hash = {};
1754 0 @$hash{ @keys } = @$self{ @keys };
1755 0 ▶ $hash->{on_error} = $self->{on_error} if( exists( $self->{on_error} ) && !ref( $self->{on_error} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"on_error"} and not ref $self->{"on_error"} 0 0 0
Condition0%0/3
exists $self->{"on_error"} and not ref $self->{"on_error"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"on_error"} and not ref $self->{"on_error"}
exists $self->{"on_error"} not ref $self->{"on_error"}
Truth table0%0/3
A and not(B)
A= exists $self->{"on_error"}B= not ref $self->{"on_error"}
ABresult
0X0
100
111
1756 0 ▶ $hash->{time_zone} = $hash->{time_zone}->name if( Scalar::Util::blessed( $hash->{time_zone} ) && $hash->{time_zone}->isa( 'DateTime::TimeZone' ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($hash->{"time_zone"}) and $hash->{"time_zone"}->isa("DateTime::TimeZone") 0 0 0
Condition0%0/3
builtin::blessed($hash->{"time_zone"}) and $hash->{"time_zone"}->isa("DateTime::TimeZone")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($hash->{"time_zone"}) and $hash->{"time_zone"}->isa("DateTime::TimeZone")
builtin::blessed($hash->{"time_zone"}) $hash->{"time_zone"}->isa("DateTime::TimeZone")
Truth table0%0/3
A and B
A= builtin::blessed($hash->{"time_zone"})B= $hash->{"time_zone"}->isa("DateTime::TimeZone")
ABresult
0X0
100
111
1757 0 return( $hash );
1758 }
1759  
1760 # NOTE: DateTime::Format::Unicode::Exception class
1761 package DateTime::Format::Unicode::Exception;
1762 BEGIN
1763 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
1764 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1765 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1766 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
1767 1 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
1768 '""' => 'as_string',
1769 0 ▶ bool => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1770 1 fallback => 1,
1771 1 );
1772 1 our $VERSION = 'v0.1.0';
1773 };
1774 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1775 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1776  
1777 sub new
1778 0 ▶{
Subroutine new: not called CC=12 SCAR=50.5
1779 0 my $this = shift( @_ );
1780 0 ▶ my $self = bless( {} => ( ref( $this ) || $this ) );
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1781 0 my @info = caller;
1782 0 @$self{ qw( package file line ) } = @info[0..2];
1783 0 my $args = {};
1784 0 ▶ if( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 0 0 0
1785 {
1786 0 ▶ if( ( ref( $_[0] ) || '' ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if ((ref $_[0] || '') eq 'HASH') { } 0 0 0
elsif (ref $_[0] and $_[0]->isa('DateTime::Format::Unicode::Exception')) { } 0 0 0
Condition0%0/2
ref $_[0] || ''
l!l
00
MC/DC0%0/1
ref $_[0] || ''
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
Aresult
11
00
1787 {
1788 0 $args = shift( @_ );
1789 0 ▶ if( $args->{skip_frames} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"skip_frames"}) 0 0 0
1790 {
1791 0 @info = caller( int( $args->{skip_frames} ) );
1792 0 @$self{ qw( package file line ) } = @info[0..2];
1793 }
1794 0 ▶ $args->{message} ||= '';
Condition0%0/2
$args->{"message"} ||= ""
l!l
00
MC/DC0%0/1
$args->{"message"} ||= ""
$args->{"message"}
Truth table0%0/2
A
A= $args->{"message"}
Aresult
11
00
1795 0 foreach my $k ( qw( package file line message code type retry_after ) )
1796 {
1797 0 ▶ $self->{ $k } = $args->{ $k } if( CORE::exists( $args->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{$k} 0 0 0
1798 }
1799 }
1800 ▶ elsif( ref( $_[0] ) && $_[0]->isa( 'DateTime::Format::Unicode::Exception' ) )
Condition0%0/3
ref $_[0] and $_[0]->isa("DateTime::Format::Unicode::Exception")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and $_[0]->isa("DateTime::Format::Unicode::Exception")
ref $_[0] $_[0]->isa("DateTime::Format::Unicode::Exception")
Truth table0%0/3
A and B
A= ref $_[0]B= $_[0]->isa("DateTime::Format::Unicode::Exception")
ABresult
0X0
100
111
1801 {
1802 0 my $o = $args->{object} = shift( @_ );
1803 0 $self->{message} = $o->message;
1804 0 $self->{code} = $o->code;
1805 0 $self->{type} = $o->type;
1806 0 $self->{retry_after} = $o->retry_after;
1807 }
1808 else
1809 {
1810 0 die( "Unknown argument provided: '", overload::StrVal( $_[0] ), "'" );
1811 }
1812 }
1813 else
1814 {
1815 0 ▶ $args->{message} = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
1816 }
1817 0 return( $self );
1818 }
1819  
1820 # This is important as stringification is called by die, so as per the manual page, we need to end with new line
1821 # And will add the stack trace
1822 sub as_string
1823 0 ▶{
Subroutine as_string: not called CC=6 SCAR=33.9
1824 1 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1825 0 my $self = shift( @_ );
1826 0 ▶ return( $self->{_cache_value} ) if( $self->{_cache_value} && !CORE::length( $self->{_reset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_value"} and not length $self->{"_reset"} 0 0 0
Condition0%0/3
$self->{"_cache_value"} and not length $self->{"_reset"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_cache_value"} and not length $self->{"_reset"}
$self->{"_cache_value"} not length $self->{"_reset"}
Truth table0%0/3
A and not(B)
A= $self->{"_cache_value"}B= not length $self->{"_reset"}
ABresult
0X0
100
111
1827 0 my $str = $self->message;
1828 0 $str = "$str";
1829 0 $str =~ s/\r?\n$//g;
1830 0 ▶ $str .= sprintf( " within package %s at line %d in file %s", ( $self->{package} // 'undef' ), ( $self->{line} // 'undef' ), ( $self->{file} // 'undef' ) );
Condition0%0/6
$self->{"package"} // "undef"
l!l
00
$self->{"line"} // "undef"
l!l
00
$self->{"file"} // "undef"
l!l
00
MC/DC0%0/1
$self->{"package"} // "undef"
$self->{"package"}
MC/DC0%0/1
$self->{"line"} // "undef"
$self->{"line"}
MC/DC0%0/1
$self->{"file"} // "undef"
$self->{"file"}
Truth table0%0/2
A
A= $self->{"package"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"line"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"file"}
Aresult
11
00
1831 0 $self->{_cache_value} = $str;
1832 0 CORE::delete( $self->{_reset} );
1833 0 return( $str );
1834 }
1835  
1836 0 ▶sub code { return( shift->reset(@_)->_set_get_prop( 'code', @_ ) ); }
Subroutine code: not called CC=1 SCAR=6.9
1837  
1838 0 ▶sub file { return( shift->reset(@_)->_set_get_prop( 'file', @_ ) ); }
Subroutine file: not called CC=1 SCAR=6.9
1839  
1840 0 ▶sub line { return( shift->reset(@_)->_set_get_prop( 'line', @_ ) ); }
Subroutine line: not called CC=1 SCAR=6.9
1841  
1842 0 ▶sub message { return( shift->reset(@_)->_set_get_prop( 'message', @_ ) ); }
Subroutine message: not called CC=1 SCAR=6.9
1843  
1844 0 ▶sub package { return( shift->reset(@_)->_set_get_prop( 'package', @_ ) ); }
Subroutine package: not called CC=1 SCAR=6.9
1845  
1846 # From perlfunc docmentation on "die":
1847 # "If LIST was empty or made an empty string, and $@ contains an
1848 # object reference that has a "PROPAGATE" method, that method will
1849 # be called with additional file and line number parameters. The
1850 # return value replaces the value in $@; i.e., as if "$@ = eval {
1851 # $@->PROPAGATE(__FILE__, __LINE__) };" were called."
1852 sub PROPAGATE
1853 0 ▶{
Subroutine PROPAGATE: not called CC=3 SCAR=24.8
1854 0 my( $self, $file, $line ) = @_;
1855 0 ▶ if( defined( $file ) && defined( $line ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and defined $line) 0 0 0
Condition0%0/3
defined $file and defined $line
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and defined $line
defined $file defined $line
Truth table0%0/3
A and B
A= defined $fileB= defined $line
ABresult
0X0
100
111
1856 {
1857 0 my $clone = $self->clone;
1858 0 $clone->file( $file );
1859 0 $clone->line( $line );
1860 0 return( $clone );
1861 }
1862 0 return( $self );
1863 }
1864  
1865 sub reset
1866 0 ▶{
Subroutine reset: not called CC=3 SCAR=24.8
1867 0 my $self = shift( @_ );
1868 0 ▶ if( !CORE::length( $self->{_reset} ) && scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length $self->{"_reset"} and scalar @_) 0 0 0
Condition0%0/2
not length $self->{"_reset"} and scalar @_
!ll
00
MC/DC0%0/1
not length $self->{"_reset"} and scalar @_
not length $self->{"_reset"}
Truth table0%0/2
not(A)
A= not length $self->{"_reset"}
Aresult
00
11
1869 {
1870 0 $self->{_reset} = scalar( @_ );
1871 }
1872 0 return( $self );
1873 }
1874  
1875 sub rethrow
1876 0 ▶{
Subroutine rethrow: not called CC=2 SCAR=17.9
1877 0 my $self = shift( @_ );
1878 0 ▶ return if( !ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
1879 0 die( $self );
1880 }
1881  
1882 0 ▶sub retry_after { return( shift->_set_get_prop( 'retry_after', @_ ) ); }
Subroutine retry_after: not called CC=1 SCAR=6.9
1883  
1884 sub throw
1885 0 ▶{
Subroutine throw: not called CC=2 SCAR=17.9
1886 0 my $self = shift( @_ );
1887 0 my $e;
1888 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1889 {
1890 0 my $msg = shift( @_ );
1891 0 $e = $self->new({
1892 skip_frames => 1,
1893 message => $msg,
1894 });
1895 }
1896 else
1897 {
1898 0 $e = $self;
1899 }
1900 0 die( $e );
1901 }
1902  
1903 0 ▶sub type { return( shift->reset(@_)->_set_get_prop( 'type', @_ ) ); }
Subroutine type: not called CC=1 SCAR=6.9
1904  
1905 sub _set_get_prop
1906 0 ▶{
Subroutine _set_get_prop: not called CC=3 SCAR=24.8
1907 0 my $self = shift( @_ );
1908 0 ▶ my $prop = shift( @_ ) || die( "No object property was provided." );
Condition0%0/2
shift @_ || die('No object property was provided.')
l!l
00
MC/DC0%0/1
shift @_ || die('No object property was provided.')
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1909 0 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1910 0 return( $self->{ $prop } );
1911 }
1912  
1913 sub FREEZE
1914 0 ▶{
Subroutine FREEZE: not called CC=4 SCAR=30.0
1915 0 my $self = CORE::shift( @_ );
1916 0 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1917 0 my $class = CORE::ref( $self );
1918 0 my %hash = %$self;
1919 # Return an array reference rather than a list so this works with Sereal and CBOR
1920 # On or before Sereal version 4.023, Sereal did not support multiple values returned
1921 0 ▶ CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023") 0 0 0
Condition0%0/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
!ll&&!rl&&r
000
MC/DC0%0/2
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table0%0/3
A and B
A= $serialiser eq "Sereal"B= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
ABresult
0X0
100
111
1922 # But Storable want a list with the first element being the serialised element
1923 0 CORE::return( $class, \%hash );
1924 }
1925  
1926 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
1927  
1928 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
1929  
1930 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
1931 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
1932 sub THAW
1933 0 ▶{
Subroutine THAW: not called CC=10 SCAR=47.0
1934 0 my( $self, undef, @args ) = @_;
1935 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
1936 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
1937 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
1938 0 my $new;
1939 # Storable pattern requires to modify the object it created rather than returning a new one
1940 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
1941 {
1942 0 foreach( CORE::keys( %$hash ) )
1943 {
1944 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
1945 }
1946 0 $new = $self;
1947 }
1948 else
1949 {
1950 0 $new = CORE::bless( $hash => $class );
1951 }
1952 0 CORE::return( $new );
1953 }
1954  
1955 0 ▶sub TO_JSON { return( shift->as_string ); }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
1956  
1957 {
1958 # NOTE: DateTime::Format::Unicode::NullObject class
1959 package
1960 DateTime::Format::Unicode::NullObject;
1961 BEGIN
1962 {
1963 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1964 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1965 1 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
1966 0 ▶ '""' => sub{ '' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1967 1 fallback => 1,
1968 1 );
1969 1 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
1970 };
1971 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1972 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1973  
1974 sub new
1975 0 ▶ {
Subroutine new: not called CC=3 SCAR=24.8
1976 0 my $this = shift( @_ );
1977 0 ▶ my $ref = @_ ? { @_ } : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
1978 0 ▶ return( bless( $ref => ( ref( $this ) || $this ) ) );
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1979 }
1980  
1981 sub AUTOLOAD
1982 0 ▶ {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
1983 0 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
1984 0 my $self = shift( @_ );
1985 0 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 0 0
1986 {
1987 0 rreturn( $self );
1988 }
1989 # Otherwise, we return undef; Empty return returns undef in scalar context and empty list in list context
1990 0 return;
1991 };
1992 }
1993  
1994 1 1;
1995 # NOTE: POD
1996 __END__
↑ Summary