lib/DateTime/Format/Intl.pm

filter: Statementstmt 73.9% 1055 / 1426 Branchbran 55.4% 415 / 748 Conditioncond 45.4% 420 / 925 MC/DCmcdc 14.4% 68 / 472 Subroutinesub 70.4% 112 / 159 Podpod 94.4% 17 / 18 totaltotal 55.6% 2087 / 3748 CC 790 SCAR 60.2
CC
790
Cov
61%
new
1877.5
_adjust_pattern
290.5
pass_error
200.1
CRAP 411.4
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## DateTime Format Intl - ~/lib/DateTime/Format/Intl.pm
3 ## Version v0.1.10
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2024/09/16
7 ## Modified 2026/06/23
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package DateTime::Format::Intl;
15 BEGIN
16 11 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶ use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 $VERSION $DEBUG $ERROR $FATAL_EXCEPTIONS
23 $CACHE $LAST_CACHE_CLEAR $MAX_CACHE_SIZE $BROWSER_DEFAULTS
24 11 );
25 11 ▶ use DateTime::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 11 ▶ use DateTime::Locale::FromCLDR;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 11 ▶ use DateTime::Format::Unicode;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶ use Locale::Intl;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶ use Locale::Unicode::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 11 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 11 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 11 our $VERSION = 'v0.1.10';
33 11 our $CACHE = {};
34 11 our $LAST_CACHE_CLEAR = time();
35 11 our $MAX_CACHE_SIZE = 30;
36 };
37  
38 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 sub new
42 437 ▶{
Subroutine new: called CC=180 SCAR=75.4
Pod documented
43 437 my $that = shift( @_ );
44 437 ▶ my $self = bless( {} => ( ref( $that ) || $that ) );
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
04370
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
45 437 my $this = shift( @_ );
46 437 my $opts = $self->_get_args_as_hash( @_ );
47 437 $opts = {%$opts};
48 437 ▶ $self->{debug} = delete( $opts->{debug} ) if( exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"debug"} 0 437 437
49 437 ▶ $self->{fatal} = ( delete( $opts->{fatal} ) // $FATAL_EXCEPTIONS // 0 );
Condition40%2/5
(delete $opts->{"fatal"} // $DateTime::Format::Intl::FATAL_EXCEPTIONS) // 0
l!l
0437
delete $opts->{"fatal"} // $DateTime::Format::Intl::FATAL_EXCEPTIONS
l!l&&r!l&&!r
00437
MC/DC0%0/2
(delete $opts->{"fatal"} // $DateTime::Format::Intl::FATAL_EXCEPTIONS) // 0
delete $opts->{"fatal"} $DateTime::Format::Intl::FATAL_EXCEPTIONS
Truth table33%1/3
A // B
A= delete $opts->{"fatal"}B= $DateTime::Format::Intl::FATAL_EXCEPTIONS
ABresult
1X1
011
000
50 437 ▶ return( $self->error( "No locale was provided." ) ) if( !defined( $this ) || !length( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and length $this 0 437 437
Condition33%1/3
defined $this and length $this
!ll&&!rl&&r
00437
MC/DC0%0/2
defined $this and length $this
defined $this length $this
Truth table33%1/3
A and B
A= defined $thisB= length $this
ABresult
0X0
100
111
51 437 ▶ my $cldr = $self->{_cldr} = Locale::Unicode::Data->new ||
Condition50%1/2
'Locale::Unicode::Data'->new || (return $self->pass_error('Locale::Unicode::Data'->error))
l!l
4370
MC/DC0%0/1
'Locale::Unicode::Data'->new || (return $self->pass_error('Locale::Unicode::Data'->error))
'Locale::Unicode::Data'->new
Truth table50%1/2
A
A= 'Locale::Unicode::Data'->new
Aresult
11
00
52 return( $self->pass_error( Locale::Unicode::Data->error ) );
53 437 ▶ my $test_locales = ( Scalar::Util::reftype( $this ) // '' ) eq 'ARRAY' ? $this : [$this];
Branch: 1 branch
BranchTrueFalseTotal
(builtin::reftype($this) // '') eq 'ARRAY' ? : 1 436 437
Condition100%2/2
builtin::reftype($this) // ""
l!l
1436
MC/DC100%1/1
builtin::reftype($this) // ""
builtin::reftype($this)
Truth table100%2/2
A
A= builtin::reftype($this)
Aresult
11
00
54 437 my $locale;
55 # Test for the locale data availability
56 437 LOCALE_AVAILABILITY: foreach my $loc ( @$test_locales )
57 {
58 437 ▶ my $tree = $cldr->make_inheritance_tree( $loc ) ||
Condition50%1/2
$cldr->make_inheritance_tree($loc) || (return $self->pass_error($cldr->error))
l!l
4370
MC/DC0%0/1
$cldr->make_inheritance_tree($loc) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($loc)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($loc)
Aresult
11
00
59 return( $self->pass_error( $cldr->error ) );
60 # We remove the last 'und' special fallback locale
61 437 pop( @$tree );
62 437 foreach my $l ( @$tree )
63 {
64 437 my $ref = $cldr->calendar_formats_l10n(
65 locale => $l,
66 calendar => 'gregorian',
67 );
68 437 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $ref ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $cldr->error 0 437 437
Condition33%1/3
not defined $ref and $cldr->error
!ll&&!rl&&r
43700
MC/DC0%0/2
not defined $ref and $cldr->error
not defined $ref $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $refB= $cldr->error
ABresult
0X0
100
111
69 437 ▶ if( $ref )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 437 0 437
70 {
71 437 ▶ if( Scalar::Util::blessed( $loc ) && ref( $loc ) eq 'Locale::Intl' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($loc) and ref $loc eq 'Locale::Intl') { } 0 437 437
Condition33%1/3
builtin::blessed($loc) and ref $loc eq "Locale::Intl"
!ll&&!rl&&r
43700
MC/DC0%0/2
builtin::blessed($loc) and ref $loc eq "Locale::Intl"
builtin::blessed($loc) ref $loc eq "Locale::Intl"
Truth table33%1/3
A and B
A= builtin::blessed($loc)B= ref $loc eq "Locale::Intl"
ABresult
0X0
100
111
72 {
73 0 $locale = $loc;
74 }
75 else
76 {
77 437 ▶ $locale = Locale::Intl->new( $loc ) ||
Condition50%1/2
'Locale::Intl'->new($loc) || (return $self->pass_error('Locale::Intl'->error))
l!l
4370
MC/DC0%0/1
'Locale::Intl'->new($loc) || (return $self->pass_error('Locale::Intl'->error))
'Locale::Intl'->new($loc)
Truth table50%1/2
A
A= 'Locale::Intl'->new($loc)
Aresult
11
00
78 return( $self->pass_error( Locale::Intl->error ) );
79 }
80 437 last LOCALE_AVAILABILITY;
81 }
82 }
83 }
84 # Choice of locales provided do not have a supported match, so we fall back to the default 'en'
85 437 ▶ $locale = Locale::Intl->new( 'en' ) if( !defined( $locale ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $locale 0 437 437
86 437 ▶ my $unicode = $self->{_unicode} = DateTime::Locale::FromCLDR->new( $locale ) ||
Condition50%1/2
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
l!l
4370
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
'DateTime::Locale::FromCLDR'->new($locale)
Truth table50%1/2
A
A= 'DateTime::Locale::FromCLDR'->new($locale)
Aresult
11
00
87 return( $self->pass_error( DateTime::Locale::FromCLDR->error ) );
88 437 $self->{locale} = $locale;
89  
90 437 my @component_options = qw( weekday era year month day dayPeriod hour minute second fractionalSecondDigits timeZoneName timeStyle dateStyle );
91 437 my @core_options = grep{ exists( $opts->{ $_ } ) } @component_options;
92 437 my $check = {};
93 437 @$check{ @core_options } = (1) x scalar( @core_options );
94  
95 # Default values if no options was provided.
96 437 ▶ if( !scalar( keys( %$check ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar keys %$check) { } 7 430 437
97 {
98 # The Mozilla documentation states that "The default value for each date-time component option is undefined, but if all component properties are undefined, then year, month, and day default to "numeric"."
99 # However, in reality, this is more nuanced.
100 7 ▶ my $defaults = $self->_get_default_options_for_locale ||
Condition50%1/2
$self->_get_default_options_for_locale || (return $self->pass_error)
l!l
70
MC/DC0%0/1
$self->_get_default_options_for_locale || (return $self->pass_error)
$self->_get_default_options_for_locale
Truth table50%1/2
A
A= $self->_get_default_options_for_locale
Aresult
11
00
101 return( $self->pass_error );
102 7 @core_options = qw( day month year );
103 7 @$opts{ @core_options } = @$defaults{ @core_options };
104 7 undef( $defaults );
105 }
106 else
107 {
108 # RangeError: invalid value "plop" for option month
109 430 my %valid_options =
110 (
111 localeMatcher => ['lookup', 'best fit'],
112 # calendar is processed separately
113 # numberingSystem is processed separately
114 calendar => qr/[a-zA-Z][a-zA-Z0-9]+(?:\-[a-zA-Z][a-zA-Z0-9]+)*/,
115 numberingSystem => qr/[a-zA-Z][a-zA-Z0-9]+/,
116 timeZone => qr/[a-zA-Z0-9\/\_\-\+]+/,
117 year => [qw( numeric 2-digit )],
118 month => [qw( numeric 2-digit long short narrow )],
119 day => [qw( numeric 2-digit )],
120 hour => [qw( numeric 2-digit )],
121 minute => [qw( numeric 2-digit )],
122 second => [qw( numeric 2-digit )],
123 hour12 => [qw( 1 0 ), undef],
124 # short: 12/20/2012, GMT+9
125 # 12/19/2012, PST
126 # long: 12/20/2012, Japan Standard Time
127 # 12/19/2012, Pacific Standard Time
128 # shortOffset: 12/20/2012, GMT+9
129 # 12/19/2012, GMT-8
130 # longOffset: 12/20/2012, GMT+09:00
131 # 12/19/2012, GMT-08:00
132 # shortGeneric: 12/20/2012, Japan Time
133 # 12/19/2012, PT
134 # longGeneric: 12/20/2012, Japan Standard Time
135 # 12/19/2012, Pacific Time
136 timeZoneName => [qw( short long shortOffset longOffset shortGeneric longGeneric )],
137 era => [qw( narrow short long )],
138 weekday => [qw( narrow short long )],
139 hourCycle => [qw( h11 h12 h23 h24)],
140 # timeZone is processed separately
141 dayPeriod => [qw( narrow short long )],
142 fractionalSecondDigits => [0..3], # 0, 1, 2, or 3 digits
143 dateStyle => [qw( full long medium short )],
144 timeStyle => [qw( full long medium short )],
145 );
146
147 430 foreach my $key ( keys( %$opts ) )
148 {
149 1640 ▶ unless( exists( $valid_options{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $valid_options{$key}) 0 1640 1640
150 {
151 0 return( $self->error({
152 type => 'RangeError',
153 message => "Invalid option \"${key}\"",
154 }) );
155 }
156 1640 my $value = $opts->{ $key };
157 1640 ▶ if( ref( $valid_options{ $key} ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $valid_options{$key} eq 'ARRAY') { } 1350 290 1640
elsif (ref $valid_options{$key} eq 'Regexp') { } 290 0 290
158 {
159 1350 ▶ if( !scalar( grep { ( $_ // '' ) eq ( $value // '' ) } @{$valid_options{ $key }} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep({($_ // "") eq ($value // "");} @{$valid_options{$key};})) 0 1350 1350
Condition75%3/4
$_ // ""
l!l
397554
$value // ""
l!l
40290
MC/DC100%1/1
$_ // ""
$_
MC/DC0%0/1
$value // ""
$value
Truth table100%2/2
A
A= $_
Aresult
11
00
Truth table50%1/2
A
A= $value
Aresult
11
00
160 {
161 0 ▶ if( $key eq 'fractionalSecondDigits' )
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'fractionalSecondDigits') { } 0 0 0
162 {
163 0 return( $self->error({
164 type => 'RangeError',
165 message => "Invalid value \"${value}\" for option ${key}. Expected an integer between 0 and 3.",
166 }) );
167 }
168 else
169 {
170 return( $self->error({
171 type => 'RangeError',
172 0 message => "Invalid value \"${value}\" for option ${key}. Expected one of: " . @{$valid_options{ $key }},
173 }) );
174 }
175 }
176 }
177 elsif( ref( $valid_options{ $key} ) eq 'Regexp' )
178 {
179 290 ▶ if( $value !~ /^$valid_options{ $key}$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /^$valid_options{$key}$/) 0 290 290
180 {
181 0 return( $self->error({
182 type => 'RangeError',
183 message => "Invalid value \"${value}\" for option ${key}.",
184 }) );
185 }
186 }
187 }
188 }
189  
190 437 ▶ my $has_style = ( $opts->{dateStyle} || $opts->{timeStyle} );
Condition100%3/3
$opts->{'dateStyle'} || $opts->{'timeStyle'}
l!l&&r!l&&!r
11435
MC/DC100%2/2
$opts->{'dateStyle'} || $opts->{'timeStyle'}
$opts->{'dateStyle'} $opts->{'timeStyle'}
Truth table100%3/3
A || B
A= $opts->{'dateStyle'}B= $opts->{'timeStyle'}
ABresult
1X1
011
000
191 # my $other_options = scalar( grep{ $opts->{ $_ } } grep{ !/^(date|time)Style$/ } @component_options );
192 437 ▶ if( $has_style && (
Branch: 1 branch
BranchTrueFalseTotal
if ($has_style and $opts->{"weekday"} || $opts->{"era"} || $opts->{"year"} || $opts->{"month"} || $opts->{"day"} || $opts->{"hour"} || $opts->{"minute"} || $opts->{"second"} || $opts->{"fractionalSecondDigits"} || $opts->{"timeZoneName"}) 0 437 437
Condition36%11/30
$has_style and $opts->{"weekday"} || $opts->{"era"} || $opts->{"year"} || $opts->{"month"} || $opts->{"day"} || $opts->{"hour"} || $opts->{"minute"} || $opts->{"second"} || $opts->{"fractionalSecondDigits"} || $opts->{"timeZoneName"}
!ll&&!rl&&r
43520
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"} or $opts->{"month"} or $opts->{"day"} or $opts->{"hour"} or $opts->{"minute"} or $opts->{"second"} or $opts->{"fractionalSecondDigits"} or $opts->{"timeZoneName"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"} or $opts->{"month"} or $opts->{"day"} or $opts->{"hour"} or $opts->{"minute"} or $opts->{"second"} or $opts->{"fractionalSecondDigits"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"} or $opts->{"month"} or $opts->{"day"} or $opts->{"hour"} or $opts->{"minute"} or $opts->{"second"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"} or $opts->{"month"} or $opts->{"day"} or $opts->{"hour"} or $opts->{"minute"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"} or $opts->{"month"} or $opts->{"day"} or $opts->{"hour"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"} or $opts->{"month"} or $opts->{"day"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"} or $opts->{"month"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"} or $opts->{"year"}
l!l&&r!l&&!r
002
$opts->{"weekday"} or $opts->{"era"}
l!l&&r!l&&!r
002
MC/DC0%0/11
$has_style and $opts->{"weekday"} || $opts->{"era"} || $opts->{"year"} || $opts->{"month"} || $opts->{"day"} || $opts->{"hour"} || $opts->{"minute"} || $opts->{"second"} || $opts->{"fractionalSecondDigits"} || $opts->{"timeZoneName"}
$has_style $opts->{"weekday"} $opts->{"era"} $opts->{"year"} $opts->{"month"} $opts->{"day"} $opts->{"hour"} $opts->{"minute"} $opts->{"second"} $opts->{"fractionalSecondDigits"} $opts->{"timeZoneName"}
Truth table16%2/12
A and B or C or D or E or F or G or H or I or J or K
A= $has_styleB= $opts->{"weekday"}C= $opts->{"era"}D= $opts->{"year"}E= $opts->{"month"}F= $opts->{"day"}G= $opts->{"hour"}H= $opts->{"minute"}I= $opts->{"second"}J= $opts->{"fractionalSecondDigits"}K= $opts->{"timeZoneName"}
ABCDEFGHIJKresult
0XXXXXXXXXX0
100000000000
11XXXXXXXXX1
101XXXXXXXX1
1001XXXXXXX1
10001XXXXXX1
100001XXXXX1
1000001XXXX1
10000001XXX1
100000001XX1
1000000001X1
100000000011
193 $opts->{weekday} ||
194 $opts->{era} ||
195 $opts->{year} ||
196 $opts->{month} ||
197 $opts->{day} ||
198 $opts->{hour} ||
199 $opts->{minute} ||
200 $opts->{second} ||
201 $opts->{fractionalSecondDigits} ||
202 $opts->{timeZoneName}
203 ) )
204 {
205 0 return( $self->error( "You cannot specify any date-time option while using either dateStyle or timeStyle" ) );
206 }
207  
208 437 my $resolved =
209 {
210 locale => $locale,
211 };
212 437 @$resolved{ @core_options } = @$opts{ @core_options };
213 437 my $calendar = $opts->{calendar};
214 437 my $tz = $opts->{timeZone};
215 437 my $tzNameOpt = $opts->{timeZoneName};
216 437 my $date_style = $opts->{dateStyle};
217 437 my $time_style = $opts->{timeStyle};
218  
219 437 my $hc = $opts->{hourCycle};
220 437 my $h12 = $opts->{hour12};
221 437 my $pattern;
222  
223 437 my $num_sys = $opts->{numberingSystem};
224  
225 437 ▶ if( !$calendar )
Branch: 1 branch
BranchTrueFalseTotal
unless ($calendar) 287 150 437
226 {
227 287 ▶ if( $calendar = $locale->calendar )
Branch: 1 branch
BranchTrueFalseTotal
if ($calendar = $locale->calendar) { } 3 284 287
228 {
229 3 $opts->{calendar} = $calendar;
230 }
231 else
232 {
233 284 $opts->{calendar} = $calendar = 'gregorian';
234 }
235 }
236 437 ▶ $calendar = 'gregorian' if( $calendar eq 'gregory' );
Branch: 1 branch
BranchTrueFalseTotal
if $calendar eq "gregory" 3 434 437
237 437 ▶ if( lc( $calendar ) ne 'gregory' &&
Branch: 1 branch
BranchTrueFalseTotal
if (lc $calendar ne "gregory" and lc $calendar ne "gregorian") 0 437 437
Condition33%1/3
lc $calendar ne "gregory" and lc $calendar ne "gregorian"
!ll&&!rl&&r
04370
MC/DC0%0/2
lc $calendar ne "gregory" and lc $calendar ne "gregorian"
lc $calendar ne "gregory" lc $calendar ne "gregorian"
Truth table33%1/3
A and B
A= lc $calendar ne "gregory"B= lc $calendar ne "gregorian"
ABresult
0X0
100
111
238 lc( $calendar ) ne 'gregorian' )
239 {
240 0 ▶ warn( "The local provided has the calendar attribute set to \"${calendar}\", but this API only supports \"gregory\" or \"gregorian\"." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
241 0 $calendar = 'gregorian';
242 }
243 437 $resolved->{calendar} = $calendar;
244  
245 # NOTE: timeStyle or hour is define, we do some check and processing for interdependency
246 437 ▶ if( length( $time_style // '' ) || $opts->{hour} )
Branch: 1 branch
BranchTrueFalseTotal
if (length($time_style // "") or $opts->{"hour"}) 159 278 437
Condition100%5/5
length($time_style // "") or $opts->{"hour"}
l!l&&r!l&&!r
1158278
$time_style // ""
l!l
1436
MC/DC100%2/2
length($time_style // "") or $opts->{"hour"}
$time_style $opts->{"hour"}
Truth table100%3/3
A or B
A= $time_styleB= $opts->{"hour"}
ABresult
1X1
011
000
247 {
248 # Surprisingly, the 'hour12' option takes precedence over the 'hourCycle' even though the latter is more specific.
249 # I tried it in browser console:
250 # const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
251 # hour12: true, hour: "numeric", hourCycle: "h24"
252 # console.log( new Intl.DateTimeFormat('en-US', { hour12: true, hour: "numeric", hourCycle: "h24" }).resolvedOptions() );
253 # results in the following resolvedOptions:
254 # {
255 # calendar: "gregory",
256 # hour: "2-digit",
257 # hour12: false,
258 # hourCycle: "h23",
259 # locale: "en-US",
260 # numberingSystem: "latn",
261 # timeZone: "Asia/Tokyo
262 # }
263 # "When true, this option sets hourCycle to either "h11" or "h12", depending on the locale. When false, it sets hourCycle to "h23". hour12 overrides both the hc locale extension tag and the hourCycle option, should either or both of those be present." (Mozilla documentation)
264 159 ▶ if( defined( $h12 ) )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $h12) { } 54 105 159
elsif ($hc) { } 48 57 105
elsif ($hc = $locale->hc) { } 0 57 57
265 {
266 # There are 156 occurrences of 'H', and 115 occurrences of 'h', so we default to 'H'
267 54 ▶ my $pref_hour_cycle = $unicode->time_format_preferred || 'H';
Condition50%1/2
$unicode->time_format_preferred || 'H'
l!l
540
MC/DC0%0/1
$unicode->time_format_preferred || 'H'
$unicode->time_format_preferred
Truth table50%1/2
A
A= $unicode->time_format_preferred
Aresult
11
00
268 54 $resolved->{hour12} = $h12;
269 # Our implementation is more locale sensitive than the browsers' one where the browser would simply revert to h23 if h12 is false, and h12 if hour12 is true
270 54 ▶ $resolved->{hourCycle} = $h12
Branch: 3 branches
BranchTrueFalseTotal
$h12 ? : 33 21 54
$pref_hour_cycle eq 'H' || $pref_hour_cycle eq 'K' ? : 0 33 33
$pref_hour_cycle eq 'h' || $pref_hour_cycle eq 'k' ? : 21 0 21
Condition33%2/6
$pref_hour_cycle eq "H" or $pref_hour_cycle eq "K"
l!l&&r!l&&!r
0033
$pref_hour_cycle eq "h" or $pref_hour_cycle eq "k"
l!l&&r!l&&!r
2100
MC/DC0%0/2
$pref_hour_cycle eq "H" or $pref_hour_cycle eq "K"
$pref_hour_cycle eq "H" $pref_hour_cycle eq "K"
MC/DC0%0/2
$pref_hour_cycle eq "h" or $pref_hour_cycle eq "k"
$pref_hour_cycle eq "h" $pref_hour_cycle eq "k"
Truth table33%1/3
A or B
A= $pref_hour_cycle eq "H"B= $pref_hour_cycle eq "K"
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $pref_hour_cycle eq "h"B= $pref_hour_cycle eq "k"
ABresult
1X1
011
000
271 ? ( ( $pref_hour_cycle eq 'H' || $pref_hour_cycle eq 'K' ) ? 'h11' : 'h12' )
272 : ( ( $pref_hour_cycle eq 'h' || $pref_hour_cycle eq 'k' ) ? 'h24' : 'h23' );
273 }
274 # "The hour cycle to use. Possible values are "h11", "h12", "h23", and "h24". This option can also be set through the hc Unicode extension key; if both are provided, this options property takes precedence." (Mozilla documentation)
275 elsif( $hc )
276 {
277 48 $resolved->{hourCycle} = $hc;
278 48 ▶ $resolved->{hour12} = ( $hc eq 'h12' || $hc eq 'h11' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$hc eq 'h12' || $hc eq 'h11' ? : 30 18 48
Condition66%2/3
$hc eq "h12" or $hc eq "h11"
l!l&&r!l&&!r
30018
MC/DC50%1/2
$hc eq "h12" or $hc eq "h11"
$hc eq "h12" $hc eq "h11"
Truth table66%2/3
A or B
A= $hc eq "h12"B= $hc eq "h11"
ABresult
1X1
011
000
279 }
280 elsif( $hc = $locale->hc )
281 {
282 0 $resolved->{hourCycle} = $hc;
283 0 ▶ $resolved->{hour12} = ( $hc eq 'h12' || $hc eq 'h11' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$hc eq 'h12' || $hc eq 'h11' ? : 0 0 0
Condition0%0/3
$hc eq "h12" or $hc eq "h11"
l!l&&r!l&&!r
000
MC/DC0%0/2
$hc eq "h12" or $hc eq "h11"
$hc eq "h12" $hc eq "h11"
Truth table0%0/3
A or B
A= $hc eq "h12"B= $hc eq "h11"
ABresult
1X1
011
000
284 }
285 else
286 {
287 57 ▶ my $pref_hour_cycle = $unicode->time_format_preferred || 'H';
Condition50%1/2
$unicode->time_format_preferred || 'H'
l!l
570
MC/DC0%0/1
$unicode->time_format_preferred || 'H'
$unicode->time_format_preferred
Truth table50%1/2
A
A= $unicode->time_format_preferred
Aresult
11
00
288 57 ▶ if( $pref_hour_cycle eq 'h' )
Branch: 4 branches
BranchTrueFalseTotal
if ($pref_hour_cycle eq 'h') { } 55 2 57
elsif ($pref_hour_cycle eq 'H') { } 2 0 2
elsif ($pref_hour_cycle eq 'k') { } 0 0 0
elsif ($pref_hour_cycle eq 'K') { } 0 0 0
289 {
290 55 $resolved->{hourCycle} = 'h12';
291 55 $resolved->{hour12} = 1;
292 }
293 elsif( $pref_hour_cycle eq 'H' )
294 {
295 2 $resolved->{hourCycle} = 'h23';
296 2 $resolved->{hour12} = 0;
297 }
298 # Although in the Unicode CLDR data for preferred time format, the 'k', or 'K' value is never used, we put it just in case in the future it might be.
299 elsif( $pref_hour_cycle eq 'k' )
300 {
301 0 $resolved->{hourCycle} = 'h24';
302 0 $resolved->{hour12} = 0;
303 }
304 elsif( $pref_hour_cycle eq 'K' )
305 {
306 0 $resolved->{hourCycle} = 'h11';
307 0 $resolved->{hour12} = 1;
308 }
309 }
310 # 2-digit is more specific than 'numeric', and if it is specified, we do not override it. However, if it is 'numeric', we may override it.
311 159 ▶ if( $opts->{hour} && $opts->{hour} ne '2-digit' )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"hour"} and $opts->{"hour"} ne "2-digit") 144 15 159
Condition100%3/3
$opts->{"hour"} and $opts->{"hour"} ne "2-digit"
!ll&&!rl&&r
114144
MC/DC100%2/2
$opts->{"hour"} and $opts->{"hour"} ne "2-digit"
$opts->{"hour"} $opts->{"hour"} ne "2-digit"
Truth table100%3/3
A and B
A= $opts->{"hour"}B= $opts->{"hour"} ne "2-digit"
ABresult
0X0
100
111
312 {
313 144 ▶ $resolved->{hour} = ( $resolved->{hourCycle} eq 'h23' || $resolved->{hourCycle} eq 'h24' ) ? '2-digit' : 'numeric';
Branch: 1 branch
BranchTrueFalseTotal
$resolved->{'hourCycle'} eq 'h23' || $resolved->{'hourCycle'} eq 'h24' ? : 40 104 144
Condition100%3/3
$resolved->{"hourCycle"} eq "h23" or $resolved->{"hourCycle"} eq "h24"
l!l&&r!l&&!r
139104
MC/DC100%2/2
$resolved->{"hourCycle"} eq "h23" or $resolved->{"hourCycle"} eq "h24"
$resolved->{"hourCycle"} eq "h23" $resolved->{"hourCycle"} eq "h24"
Truth table100%3/3
A or B
A= $resolved->{"hourCycle"} eq "h23"B= $resolved->{"hourCycle"} eq "h24"
ABresult
1X1
011
000
314 }
315 }
316  
317 437 my $systems = $unicode->number_systems;
318 437 my $ns_default = $unicode->number_system;
319 437 ▶ my $ns_default_def = $cldr->number_system( number_system => $ns_default ) ||
Condition50%1/2
$cldr->number_system('number_system', $ns_default) || (return $self->pass_error($cldr->error))
l!l
4370
MC/DC0%0/1
$cldr->number_system('number_system', $ns_default) || (return $self->pass_error($cldr->error))
$cldr->number_system('number_system', $ns_default)
Truth table50%1/2
A
A= $cldr->number_system('number_system', $ns_default)
Aresult
11
00
320 return( $self->pass_error( $cldr->error ) );
321 437 ▶ undef( $ns_default ) unless( $ns_default_def->{type} eq 'numeric' );
Branch: 1 branch
BranchTrueFalseTotal
unless $ns_default_def->{"type"} eq "numeric" 0 437 437
322 # NOTE: number system check
323 437 ▶ if( $num_sys )
Branch: 1 branch
BranchTrueFalseTotal
if ($num_sys) 0 437 437
324 {
325 0 my $num_sys_def = $cldr->number_system( number_system => $num_sys );
326 0 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $num_sys_def ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $num_sys_def and $cldr->error 0 0 0
Condition0%0/3
not defined $num_sys_def and $cldr->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $num_sys_def and $cldr->error
not defined $num_sys_def $cldr->error
Truth table0%0/3
not(A) and B
A= not defined $num_sys_defB= $cldr->error
ABresult
0X0
100
111
327 # The proper behaviour is to ignore bad value and fall back to 'latn'
328 0 ▶ if( !$num_sys_def )
Branch: 1 branch
BranchTrueFalseTotal
unless ($num_sys_def) 0 0 0
329 {
330 0 ▶ warn( "Warning only: invalid numbering system provided \"${num_sys}\"." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
331 0 undef( $num_sys );
332 0 $num_sys_def = {};
333 }
334 # 'latn' is always supported by all locale as per the LDML specifications
335 # We reject the specified if it is not among the locale's default, and if it is not 'numeric' (e.g. if it is algorithmic)
336 0 ▶ if( !( $num_sys eq 'latn' || scalar( grep( ( $systems->{ $_ } // '' ) eq $num_sys, qw( number_system native ) ) ) ) && $num_sys_def->{type} ne 'numeric' )
Branch: 1 branch
BranchTrueFalseTotal
if (not $num_sys eq "latn" || scalar grep((($systems->{$_} // "") eq $num_sys), ("number_system", "native")) and $num_sys_def->{"type"} ne "numeric") 0 0 0
Condition0%0/7
not $num_sys eq "latn" || scalar grep((($systems->{$_} // "") eq $num_sys), ("number_system", "native")) and $num_sys_def->{"type"} ne "numeric"
!ll&&!rl&&r
000
$num_sys eq 'latn' || scalar grep((($systems->{$_} // '') eq $num_sys), ('number_system', 'native'))
l!l
00
$systems->{$_} // ""
l!l
00
MC/DC0%0/2
not $num_sys eq "latn" || scalar grep((($systems->{$_} // "") eq $num_sys), ("number_system", "native")) and $num_sys_def->{"type"} ne "numeric"
$num_sys eq 'latn' $num_sys_def->{"type"} ne "numeric"
MC/DC0%0/1
$systems->{$_} // ""
$systems->{$_}
Truth table0%0/3
not(A) and B
A= $num_sys eq 'latn'B= $num_sys_def->{"type"} ne "numeric"
ABresult
1X0
000
011
Truth table0%0/2
A
A= $systems->{$_}
Aresult
11
00
337 {
338 0 ▶ warn( "Warning only: unsupported numbering system provided \"${num_sys}\" for locale \"${locale}\"." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
339 0 undef( $num_sys );
340 }
341 }
342 437 ▶ if( !defined( $num_sys ) && ( my $locale_num_sys = $locale->number ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $num_sys and my $locale_num_sys = $locale->number) 3 434 437
Condition66%2/3
not defined $num_sys and my $locale_num_sys = $locale->number
!ll&&!rl&&r
04343
MC/DC50%1/2
not defined $num_sys and my $locale_num_sys = $locale->number
not defined $num_sys my $locale_num_sys = $locale->number
Truth table66%2/3
not(A) and B
A= not defined $num_sysB= my $locale_num_sys = $locale->number
ABresult
0X0
100
111
343 {
344 3 my $num_sys_def = $cldr->number_system( number_system => $locale_num_sys );
345 3 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $num_sys_def ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $num_sys_def and $cldr->error 0 3 3
Condition33%1/3
not defined $num_sys_def and $cldr->error
!ll&&!rl&&r
300
MC/DC0%0/2
not defined $num_sys_def and $cldr->error
not defined $num_sys_def $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $num_sys_defB= $cldr->error
ABresult
0X0
100
111
346 3 ▶ $num_sys_def ||= {};
Condition50%1/2
$num_sys_def ||= {}
l!l
30
MC/DC0%0/1
$num_sys_def ||= {}
$num_sys_def
Truth table50%1/2
A
A= $num_sys_def
Aresult
11
00
347 3 ▶ if( $locale_num_sys eq 'latn' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($locale_num_sys eq 'latn' or scalar grep((($systems->{$_} // '') eq $locale_num_sys), ('number_system', 'native')) and $num_sys_def->{'type'} ne 'numeric') { } 0 3 3
Condition62%5/8
$locale_num_sys eq "latn" or scalar grep((($systems->{$_} // "") eq $locale_num_sys), ("number_system", "native")) and $num_sys_def->{"type"} ne "numeric"
l!l&&r!l&&!r
003
scalar grep((($systems->{$_} // "") eq $locale_num_sys), ("number_system", "native")) and $num_sys_def->{"type"} ne "numeric"
!ll&&!rl&&r
210
$systems->{$_} // ""
l!l
15
MC/DC0%0/3
$locale_num_sys eq "latn" or scalar grep((($systems->{$_} // "") eq $locale_num_sys), ("number_system", "native")) and $num_sys_def->{"type"} ne "numeric"
$locale_num_sys eq "latn" scalar grep((($systems->{$_} // "") eq $locale_num_sys), ("number_system", "native")) $num_sys_def->{"type"} ne "numeric"
MC/DC100%1/1
$systems->{$_} // ""
$systems->{$_}
Truth table50%2/4
A or B and C
A= $locale_num_sys eq "latn"B= scalar grep((($systems->{$_} // "") eq $locale_num_sys), ("number_system", "native"))C= $num_sys_def->{"type"} ne "numeric"
ABCresult
1XX1
0111
00X0
0100
Truth table100%2/2
A
A= $systems->{$_}
Aresult
11
00
348 (
349 scalar( grep( ( $systems->{ $_ } // '' ) eq $locale_num_sys, qw( number_system native ) ) ) &&
350 $num_sys_def->{type} ne 'numeric'
351 ) )
352 {
353 0 $num_sys = $locale_num_sys;
354 }
355 else
356 {
357 3 ▶ warn( "Warning only: unsupported numbering system provided (${locale_num_sys}) via the locale extension \"nu\" (${locale})." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 3 0 3
358 }
359 }
360 # Still have not found anything
361 437 ▶ if( !length( $num_sys // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($num_sys // "")) 437 0 437
Condition50%1/2
$num_sys // ""
l!l
0437
MC/DC0%0/1
$num_sys // ""
$num_sys
Truth table50%1/2
A
A= $num_sys
Aresult
11
00
362 {
363 437 ▶ $num_sys //= $ns_default || 'latn';
Condition50%2/4
$num_sys //= $ns_default || "latn"
l!l
0437
$ns_default || 'latn'
l!l
4370
MC/DC0%0/1
$num_sys //= $ns_default || "latn"
$num_sys
Truth table50%1/2
A
A= $num_sys
Aresult
11
00
364 }
365 437 $resolved->{numberingSystem} = $num_sys;
366  
367 # NOTE: time zone check
368 437 ▶ if( length( $tz // '' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (length($tz // '')) { } 141 296 437
elsif (my $bcp47_tz = $locale->timezone) { } 2 294 296
Condition100%2/2
$tz // ""
l!l
141296
MC/DC100%1/1
$tz // ""
$tz
Truth table100%2/2
A
A= $tz
Aresult
11
00
369 {
370 141 ▶ my $actual = $cldr->timezone_canonical( $tz ) ||
Condition50%1/2
$cldr->timezone_canonical($tz) || (return $self->pass_error($cldr->error))
l!l
1410
MC/DC0%0/1
$cldr->timezone_canonical($tz) || (return $self->pass_error($cldr->error))
$cldr->timezone_canonical($tz)
Truth table50%1/2
A
A= $cldr->timezone_canonical($tz)
Aresult
11
00
371 return( $self->pass_error( $cldr->error ) );
372 141 my $ref = $cldr->timezones( timezone => $actual );
373 141 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $ref ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $cldr->error 0 141 141
Condition33%1/3
not defined $ref and $cldr->error
!ll&&!rl&&r
14100
MC/DC0%0/2
not defined $ref and $cldr->error
not defined $ref $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $refB= $cldr->error
ABresult
0X0
100
111
374 141 ▶ if( !$ref )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref) 0 141 141
375 {
376 0 return( $self->error({
377 message => "Invalid time zone in " . ref( $self ) . ": ${tz}",
378 type => 'RangeError',
379 }) );
380 }
381 # elsif( lc( $tz ) ne lc( $actual ) )
382 # {
383 # $tz = $actual;
384 # }
385 }
386 elsif( my $bcp47_tz = $locale->timezone )
387 {
388 2 my $all = $cldr->timezones( tz_bcpid => $bcp47_tz );
389 2 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $all ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $all and $cldr->error 0 2 2
Condition33%1/3
not defined $all and $cldr->error
!ll&&!rl&&r
200
MC/DC0%0/2
not defined $all and $cldr->error
not defined $all $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $allB= $cldr->error
ABresult
0X0
100
111
390 2 ▶ if( $all &&
Branch: 1 branch
BranchTrueFalseTotal
if ($all and scalar @$all and $all->[0]{'timezone'}) { } 2 0 2
Condition40%2/5
$all and scalar @$all and $all->[0]{"timezone"}
!ll&&!rl&&r
002
$all and scalar @$all
!ll
02
MC/DC0%0/2
$all and scalar @$all and $all->[0]{"timezone"}
$all $all->[0]{"timezone"}
Truth table33%1/3
A and B
A= $allB= $all->[0]{"timezone"}
ABresult
0X0
100
111
391 scalar( @$all ) &&
392 $all->[0]->{timezone} )
393 {
394 2 $tz = $all->[0]->{timezone};
395 }
396 else
397 {
398 0 warn( "No time zone could be found for the locale's time zone extension value '${bcp47_tz}'" );
399 }
400 }
401 # If we still have not a time zone defined, as a last resort
402 437 ▶ if( !length( $tz // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($tz // "")) 294 143 437
Condition100%2/2
$tz // ""
l!l
143294
MC/DC100%1/1
$tz // ""
$tz
Truth table100%2/2
A
A= $tz
Aresult
11
00
403 {
404 # Calling DateTime time_zone with 'local' might die if not found on the system, so we catch it with eval
405 my $dt = eval
406 294 {
407 294 DateTime::Lite->now( time_zone => 'local' );
408 };
409 294 ▶ if( $@ || !defined( $dt ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $dt) { } 0 294 294
Condition33%1/3
$@ or not defined $dt
l!l&&r!l&&!r
00294
MC/DC0%0/2
$@ or not defined $dt
$@ not defined $dt
Truth table33%1/3
A or not(B)
A= $@B= not defined $dt
ABresult
1X1
011
000
410 {
411 0 $tz = 'UTC';
412 }
413 else
414 {
415 294 $tz = $dt->time_zone->name;
416 }
417 }
418 437 $resolved->{timeZone} = $tz;
419  
420 # NOTE: time zone name
421 437 ▶ if( length( $tzNameOpt // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length($tzNameOpt // "")) 44 393 437
Condition100%2/2
$tzNameOpt // ""
l!l
44393
MC/DC100%1/1
$tzNameOpt // ""
$tzNameOpt
Truth table100%2/2
A
A= $tzNameOpt
Aresult
11
00
422 {
423 44 $resolved->{timeZoneName} = $tzNameOpt;
424 }
425  
426 # NOTE: era
427 # long, short, narrow
428 437 ▶ if( my $era = $opts->{era} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $era = $opts->{"era"}) 93 344 437
429 {
430 # Only supported values are: long, short and narrow
431 93 my $width_map =
432 {
433 abbreviated => 'short',
434 wide => 'long',
435 };
436 93 ▶ my $tree = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
930
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
437 return( $self->pass_error( $cldr->error ) );
438 93 my $width;
439 93 my $supported = {};
440 93 LOCALE: foreach my $loc ( @$tree )
441 {
442 93 my $all = $cldr->calendar_eras_l10n(
443 locale => $loc,
444 calendar => $calendar,
445 );
446 93 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $all ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $all and $cldr->error 0 93 93
Condition33%1/3
not defined $all and $cldr->error
!ll&&!rl&&r
9300
MC/DC0%0/2
not defined $all and $cldr->error
not defined $all $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $allB= $cldr->error
ABresult
0X0
100
111
447 93 ▶ if( $all )
Branch: 1 branch
BranchTrueFalseTotal
if ($all) 93 0 93
448 {
449 93 foreach my $this ( @$all )
450 {
451 930 ▶ $supported->{ ( $width_map->{ $this->{era_width} } // $this->{era_width} ) }++;
Condition66%2/3
$$width_map{$this->{"era_width"}} // $this->{"era_width"}
l!l&&r!l&&!r
7441860
MC/DC0%0/2
$$width_map{$this->{"era_width"}} // $this->{"era_width"}
$$width_map{$this->{"era_width"}} $this->{"era_width"}
Truth table66%2/3
A // B
A= $$width_map{$this->{"era_width"}}B= $this->{"era_width"}
ABresult
1X1
011
000
452 }
453  
454 93 ▶ if( exists( $supported->{ $era } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $supported->{$era}) { } 93 0 93
elsif ($era eq 'short' and exists $supported->{'abbreviated'}) { } 0 0 0
455 {
456 93 $width = $era;
457 }
458 ▶ elsif( $era eq 'short' && exists( $supported->{abbreviated} ) )
Condition0%0/3
$era eq "short" and exists $supported->{"abbreviated"}
!ll&&!rl&&r
000
MC/DC0%0/2
$era eq "short" and exists $supported->{"abbreviated"}
$era eq "short" exists $supported->{"abbreviated"}
Truth table0%0/3
A and B
A= $era eq "short"B= exists $supported->{"abbreviated"}
ABresult
0X0
100
111
459 {
460 0 $width = 'abbreviated';
461 }
462 93 last LOCALE;
463 }
464 }
465 93 ▶ unless( defined( $width ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $width) 0 93 93
466 {
467 $width = exists( $supported->{long} )
468 ? 'long'
469 : exists( $supported->{short} )
470 0 ▶ ? 'short'
Branch: 2 branches
BranchTrueFalseTotal
exists $supported->{'long'} ? : 0 0 0
exists $supported->{'short'} ? : 0 0 0
471 : undef;
472 }
473 93 $resolved->{era} = $width;
474 }
475  
476 # NOTE month, weekday check
477 my $values_to_check =
478 {
479 # CLDR data type => [option value, resolvedOption property]
480 month => [$opts->{month}, 'month'],
481 437 day => [$opts->{weekday}, 'weekday'],
482 };
483 437 foreach my $prop ( keys( %$values_to_check ) )
484 {
485 # long, short, narrow
486 874 my $val = $values_to_check->{ $prop }->[0];
487 874 ▶ next if( !length( $val // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($val // "") 501 373 874
Condition100%2/2
$val // ""
l!l
373501
MC/DC100%1/1
$val // ""
$val
Truth table100%2/2
A
A= $val
Aresult
11
00
488 # This is already ok
489 373 ▶ next if( $prop eq 'month' && ( $val eq '2-digit' || $val eq 'numeric' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $prop eq "month" and $val eq "2-digit" || $val eq "numeric" 112 261 373
Condition83%5/6
$prop eq "month" and $val eq "2-digit" || $val eq "numeric"
!ll&&!rl&&r
114147112
$val eq "2-digit" or $val eq "numeric"
l!l&&r!l&&!r
0112147
MC/DC66%2/3
$prop eq "month" and $val eq "2-digit" || $val eq "numeric"
$prop eq "month" $val eq "2-digit" $val eq "numeric"
Truth table75%3/4
A and B or C
A= $prop eq "month"B= $val eq "2-digit"C= $val eq "numeric"
ABCresult
0XX0
1000
11X1
1011
490 # Only supported values are: long, short and narrow
491 261 my $width_map =
492 {
493 'abbreviated' => 'short',
494 'wide' => 'long',
495 };
496 261 ▶ my $tree = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
2610
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
497 return( $self->pass_error( $cldr->error ) );
498 261 my $width;
499 261 my $supported = {};
500 261 LOCALE: foreach my $loc ( @$tree )
501 {
502 262 my $all = $cldr->calendar_terms(
503 locale => $loc,
504 calendar => $calendar,
505 term_type => $prop,
506 term_context => 'format',
507 );
508 262 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $all ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $all and $cldr->error 0 262 262
Condition33%1/3
not defined $all and $cldr->error
!ll&&!rl&&r
26200
MC/DC0%0/2
not defined $all and $cldr->error
not defined $all $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $allB= $cldr->error
ABresult
0X0
100
111
509 262 ▶ if( $all && scalar( @$all ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($all and scalar @$all) 261 1 262
Condition50%1/2
$all and scalar @$all
!ll
0262
MC/DC0%0/1
$all and scalar @$all
$all
Truth table50%1/2
A
A= $all
Aresult
00
11
510 {
511 261 foreach my $this ( @$all )
512 {
513 8477 ▶ $supported->{ ( $width_map->{ $this->{term_width} } // $this->{term_width} ) }++;
Condition66%2/3
$$width_map{$this->{"term_width"}} // $this->{"term_width"}
l!l&&r!l&&!r
512433530
MC/DC0%0/2
$$width_map{$this->{"term_width"}} // $this->{"term_width"}
$$width_map{$this->{"term_width"}} $this->{"term_width"}
Truth table66%2/3
A // B
A= $$width_map{$this->{"term_width"}}B= $this->{"term_width"}
ABresult
1X1
011
000
514 }
515  
516 261 ▶ if( exists( $supported->{ $val } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $supported->{$val}) { } 261 0 261
elsif ($val eq 'short' and exists $supported->{'abbreviated'}) { } 0 0 0
517 {
518 261 $width = $val;
519 }
520 ▶ elsif( $val eq 'short' && exists( $supported->{abbreviated} ) )
Condition0%0/3
$val eq "short" and exists $supported->{"abbreviated"}
!ll&&!rl&&r
000
MC/DC0%0/2
$val eq "short" and exists $supported->{"abbreviated"}
$val eq "short" exists $supported->{"abbreviated"}
Truth table0%0/3
A and B
A= $val eq "short"B= exists $supported->{"abbreviated"}
ABresult
0X0
100
111
521 {
522 0 $width = 'abbreviated';
523 }
524 261 last LOCALE;
525 }
526 }
527 261 ▶ unless( defined( $width ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $width) 0 261 261
528 {
529 $width = exists( $supported->{long} )
530 ? 'long'
531 : exists( $supported->{short} )
532 0 ▶ ? 'short'
Branch: 2 branches
BranchTrueFalseTotal
exists $supported->{'long'} ? : 0 0 0
exists $supported->{'short'} ? : 0 0 0
533 : undef;
534 }
535 261 $resolved->{ $values_to_check->{ $prop }->[1] } = $width;
536 }
537  
538 # NOTE: minute check; minute always end up being 2-digit, even if the user explicitly set it to numeric
539 437 ▶ if( $opts->{minute} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"minute"}) 126 311 437
540 {
541 126 $resolved->{minute} = '2-digit';
542 }
543 # NOTE: second; same as minute
544 437 ▶ if( $opts->{second} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"second"}) 41 396 437
545 {
546 41 $resolved->{second} = '2-digit';
547 }
548 437 $self->{resolvedOptions} = $resolved;
549  
550 # NOTE: Getting pattern
551 437 my $cache_key = join( '|', map{ $_ . ';' . $resolved->{ $_ } } sort( keys( %$resolved ) ) );
552 437 $pattern = $self->_get_cached_pattern( $locale, $cache_key );
553 437 ▶ unless( $pattern )
Branch: 1 branch
BranchTrueFalseTotal
unless ($pattern) 297 140 437
554 {
555 # Now, get the most suitable pattern and cache it.
556 297 my $dateStyle = $resolved->{dateStyle};
557 297 my $timeStyle = $resolved->{timeStyle};
558 297 my $mode2number =
559 {
560 full => 4,
561 medium => 3,
562 long => 2,
563 short => 1,
564 };
565 # NOTE: dateStyle or timeStyle was selected with a value of: full, medium, long, short
566 297 ▶ if( $dateStyle || $timeStyle )
Branch: 1 branch
BranchTrueFalseTotal
if ($dateStyle or $timeStyle) { } 2 295 297
Condition100%3/3
$dateStyle or $timeStyle
l!l&&r!l&&!r
11295
MC/DC100%2/2
$dateStyle or $timeStyle
$dateStyle $timeStyle
Truth table100%3/3
A or B
A= $dateStyleB= $timeStyle
ABresult
1X1
011
000
567 {
568 2 my @mode_keys = keys( %$mode2number );
569 2 my $number2mode = {};
570 2 @$number2mode{ @$mode2number{ @mode_keys } } = @mode_keys;
571 2 my( $date_pattern, $time_pattern );
572 2 ▶ if( $dateStyle )
Branch: 1 branch
BranchTrueFalseTotal
if ($dateStyle) 1 1 2
573 {
574 1 ▶ my $code_date = $unicode->can( "date_format_${dateStyle}" ) ||
Condition50%1/2
$unicode->can("date_format_$dateStyle") || (return $self->error("No method date_format_$dateStyle found in ", ref $unicode))
l!l
10
MC/DC0%0/1
$unicode->can("date_format_$dateStyle") || (return $self->error("No method date_format_$dateStyle found in ", ref $unicode))
$unicode->can("date_format_$dateStyle")
Truth table50%1/2
A
A= $unicode->can("date_format_$dateStyle")
Aresult
11
00
575 return( $self->error( "No method date_format_${dateStyle} found in ", ref( $unicode ) ) );
576 1 $date_pattern = $code_date->( $unicode );
577 1 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $date_pattern ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $date_pattern and $unicode->error 0 1 1
Condition33%1/3
not defined $date_pattern and $unicode->error
!ll&&!rl&&r
100
MC/DC0%0/2
not defined $date_pattern and $unicode->error
not defined $date_pattern $unicode->error
Truth table33%1/3
not(A) and B
A= not defined $date_patternB= $unicode->error
ABresult
0X0
100
111
578 1 ▶ return( $self->error( "date_format_${dateStyle}() in class ", ref( $unicode ), " returned an empty value." ) ) if( !length( $date_pattern // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($date_pattern // "") 0 1 1
Condition50%1/2
$date_pattern // ""
l!l
10
MC/DC0%0/1
$date_pattern // ""
$date_pattern
Truth table50%1/2
A
A= $date_pattern
Aresult
11
00
579 }
580 2 ▶ if( $timeStyle )
Branch: 1 branch
BranchTrueFalseTotal
if ($timeStyle) 1 1 2
581 {
582 1 ▶ my $code_time = $unicode->can( "time_format_${timeStyle}" ) ||
Condition50%1/2
$unicode->can("time_format_$timeStyle") || (return $self->error("No method time_format_$timeStyle found in ", ref $unicode))
l!l
10
MC/DC0%0/1
$unicode->can("time_format_$timeStyle") || (return $self->error("No method time_format_$timeStyle found in ", ref $unicode))
$unicode->can("time_format_$timeStyle")
Truth table50%1/2
A
A= $unicode->can("time_format_$timeStyle")
Aresult
11
00
583 return( $self->error( "No method time_format_${timeStyle} found in ", ref( $unicode ) ) );
584 1 $time_pattern = $code_time->( $unicode );
585 1 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $date_pattern ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $date_pattern and $unicode->error 0 1 1
Condition33%1/3
not defined $date_pattern and $unicode->error
!ll&&!rl&&r
010
MC/DC0%0/2
not defined $date_pattern and $unicode->error
not defined $date_pattern $unicode->error
Truth table33%1/3
not(A) and B
A= not defined $date_patternB= $unicode->error
ABresult
0X0
100
111
586 1 ▶ return( $self->error( "time_format_${timeStyle}() in class ", ref( $unicode ), " returned an empty value." ) ) if( !length( $time_pattern // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($time_pattern // "") 0 1 1
Condition50%1/2
$time_pattern // ""
l!l
10
MC/DC0%0/1
$time_pattern // ""
$time_pattern
Truth table50%1/2
A
A= $time_pattern
Aresult
11
00
587 }
588  
589 2 ▶ if( defined( $date_pattern ) && defined( $time_pattern ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date_pattern and defined $time_pattern) { } 0 2 2
Condition66%2/3
defined $date_pattern and defined $time_pattern
!ll&&!rl&&r
110
MC/DC0%0/2
defined $date_pattern and defined $time_pattern
defined $date_pattern defined $time_pattern
Truth table66%2/3
A and B
A= defined $date_patternB= defined $time_pattern
ABresult
0X0
100
111
590 {
591 # Define the combine mode as the most comprehensive mode of either date or time style specified
592 0 my $datetime_mode = $number2mode->{ _max( $mode2number->{ $dateStyle }, $mode2number->{ $timeStyle } ) };
593 0 ▶ my $code_datetime = $unicode->can( "datetime_format_${datetime_mode}" ) ||
Condition0%0/2
$unicode->can("datetime_format_$datetime_mode") || (return $self->error("No method datetime_format_$datetime_mode found in ", ref $unicode))
l!l
00
MC/DC0%0/1
$unicode->can("datetime_format_$datetime_mode") || (return $self->error("No method datetime_format_$datetime_mode found in ", ref $unicode))
$unicode->can("datetime_format_$datetime_mode")
Truth table0%0/2
A
A= $unicode->can("datetime_format_$datetime_mode")
Aresult
11
00
594 return( $self->error( "No method datetime_format_${datetime_mode} found in ", ref( $unicode ) ) );
595 0 $pattern = $code_datetime->( $unicode );
596 0 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $date_pattern ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $date_pattern and $unicode->error 0 0 0
Condition0%0/3
not defined $date_pattern and $unicode->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $date_pattern and $unicode->error
not defined $date_pattern $unicode->error
Truth table0%0/3
not(A) and B
A= not defined $date_patternB= $unicode->error
ABresult
0X0
100
111
597 0 ▶ return( $self->error( "datetime_format_${datetime_mode}() in class ", ref( $unicode ), " returned an empty value." ) ) 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
598 0 $pattern =~ s/\{1\}/$date_pattern/g;
599 0 $pattern =~ s/\{0\}/$time_pattern/g;
600 }
601 else
602 {
603 2 ▶ $pattern = ( $date_pattern // $time_pattern );
Condition66%2/3
$date_pattern // $time_pattern
l!l&&r!l&&!r
110
MC/DC0%0/2
$date_pattern // $time_pattern
$date_pattern $time_pattern
Truth table66%2/3
A // B
A= $date_patternB= $time_pattern
ABresult
1X1
011
000
604 }
605 }
606 # NOTE: user has specified either no options or some options other than dateStyle and timeStyle
607 # We check the options provided
608 else
609 {
610 # If there is no option provided, the fallback is a short date
611 295 my $patterns = $self->_get_available_format_patterns;
612 # NOTE: Calling _select_best_pattern
613 295 ▶ my $score_object = $self->_select_best_pattern(
Condition50%1/2
$self->_select_best_pattern('patterns', $patterns, 'options', $resolved) || (return $self->pass_error)
l!l
2950
MC/DC0%0/1
$self->_select_best_pattern('patterns', $patterns, 'options', $resolved) || (return $self->pass_error)
$self->_select_best_pattern('patterns', $patterns, 'options', $resolved)
Truth table50%1/2
A
A= $self->_select_best_pattern('patterns', $patterns, 'options', $resolved)
Aresult
11
00
614 patterns => $patterns,
615 options => $resolved,
616 ) || return( $self->pass_error );
617 295 $pattern = $score_object->pattern_object->pattern;
618 295 my $skeleton = $score_object->pattern_object->skeleton;
619  
620 295 $self->{_skeleton} = $skeleton;
621 }
622 297 ▶ $self->_set_cached_pattern( $locale, $cache_key, $pattern ) unless( !defined( $pattern ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $pattern 297 0 297
623 }
624 437 $self->{_pattern} = $pattern;
625 437 return( $self );
626 }
627  
628 sub error
629 363 ▶{
Subroutine error: called CC=13 SCAR=48.6
Pod documented
630 363 my $self = shift( @_ );
631 363 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 363 363
632 {
633 0 my $def = {};
634 0 ▶ if( @_ == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and defined $_[0] and ref $_[0] eq 'HASH' and exists $_[0]{'message'}) { } 0 0 0
Condition0%0/9
@_ == 1 and defined $_[0] and ref $_[0] eq "HASH" and exists $_[0]{"message"}
!ll&&!rl&&r
000
@_ == 1 and defined $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
@_ == 1 and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/4
@_ == 1 and defined $_[0] and ref $_[0] eq "HASH" and exists $_[0]{"message"}
@_ == 1 defined $_[0] ref $_[0] eq "HASH" exists $_[0]{"message"}
Truth table0%0/5
A and B and C and D
A= @_ == 1B= defined $_[0]C= ref $_[0] eq "HASH"D= exists $_[0]{"message"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
635 defined( $_[0] ) &&
636 ref( $_[0] ) eq 'HASH' &&
637 exists( $_[0]->{message} ) )
638 {
639 0 $def = shift( @_ );
640 }
641 else
642 {
643 0 ▶ $def->{message} = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
644 }
645 0 ▶ $def->{skip_frames} = 1 unless( exists( $def->{skip_frames} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"skip_frames"} 0 0 0
646 0 $self->{error} = $ERROR = DateTime::Format::Intl::Exception->new( $def );
647 0 ▶ if( $self->fatal )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 0 0 0
648 {
649 0 die( $self->{error} );
650 }
651 else
652 {
653 0 ▶ warn( $def->{message} ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
654 0 ▶ if( Wanted::want( 'ARRAY' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (Wanted::want('ARRAY')) { } 0 0 0
elsif (Wanted::want('OBJECT')) { } 0 0 0
655 {
656 0 rreturn( [] );
657 }
658 elsif( Wanted::want( 'OBJECT' ) )
659 {
660 0 rreturn( DateTime::Format::Intl::NullObject->new );
661 }
662 0 return;
663 }
664 }
665 363 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 363 0 363
666 }
667  
668 0 ▶sub fatal { return( shift->_set_get_prop( 'fatal', @_ ) ); }
Subroutine fatal: not called CC=1 SCAR=6.9
Pod documented
669  
670 sub format
671 46 ▶{
Subroutine format: called CC=15 SCAR=38.0
Pod documented
672 46 my $self = shift( @_ );
673 46 ▶ return( $self->error( "format() must be called with an object, and not as a class function." ) ) if( !ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 46 46
674 46 my $this = shift( @_ );
675 46 ▶ if( !defined( $this ) || !length( $this // '' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $this && length($this // '')) { } 0 46 46
elsif (not builtin::blessed($this) && ($this->isa('DateTime') || $this->isa('DateTime::Lite'))) { } 0 46 46
Condition40%2/5
defined $this && length($this // '')
!ll&&!rl&&r
0046
$this // ""
l!l
460
MC/DC0%0/2
defined $this && length($this // '')
defined $this $this
Truth table33%1/3
A && B
A= defined $thisB= $this
ABresult
0X0
100
111
676 {
677 0 $this = DateTime::Lite->now;
678 }
679 ▶ elsif( !( Scalar::Util::blessed( $this ) && ( $this->isa( 'DateTime' ) || $this->isa( 'DateTime::Lite' ) ) ) )
Condition33%2/6
builtin::blessed($this) && ($this->isa('DateTime') || $this->isa('DateTime::Lite'))
!ll&&!rl&&r
0046
$this->isa("DateTime") or $this->isa("DateTime::Lite")
l!l&&r!l&&!r
0460
MC/DC0%0/3
builtin::blessed($this) && ($this->isa('DateTime') || $this->isa('DateTime::Lite'))
builtin::blessed($this) $this->isa("DateTime") $this->isa("DateTime::Lite")
Truth table25%1/4
A && B or C
A= builtin::blessed($this)B= $this->isa("DateTime")C= $this->isa("DateTime::Lite")
ABCresult
0XX0
1000
11X1
1011
680 {
681 0 return( $self->error({
682 type => 'RangeError',
683 message => "Date value provided is not a DateTime or DateTime::Lite object."
684 }) );
685 }
686 46 my $dt = $this->clone;
687 46 my $opts = $self->resolvedOptions;
688 46 my $tz;
689 46 ▶ if( $opts->{timeZone} )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'timeZone'}) { } 46 0 46
elsif ($tz eq 'floating') { } 0 0 0
690 {
691 46 $dt->set_time_zone( $tz = $opts->{timeZone} );
692 }
693 elsif( $tz eq 'floating' )
694 {
695 0 $dt->set_time_zone( $tz = 'UTC' );
696 }
697 else
698 {
699 0 $tz = $dt->time_zone->name;
700 }
701 46 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone." );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
l!l
460
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
702 46 ▶ my $unicode = $self->{_unicode} || die( "The DateTime::Locale::FromCLDR object is gone." );
Condition50%1/2
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
l!l
460
MC/DC0%0/1
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
$self->{'_unicode'}
Truth table50%1/2
A
A= $self->{'_unicode'}
Aresult
11
00
703 46 ▶ my $locale = $self->{locale} || die( "Our Locale::Unicode object is gone!" );
Condition50%1/2
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
l!l
460
MC/DC0%0/1
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
704 # We share our DateTime::Locale::FromCLDR object with DateTime, because this module fares much better than the DateTime::Locale::FromData one
705 # If the object is a DateTime::Lite one, then it works too!
706 46 $dt->set_locale( $unicode );
707  
708 # This is built upon object instantiation, so that format(9 can be called multiple times and run more rapidly.
709 # my $pattern = $self->{_pattern} || die( "Saved pattern is gone!" );
710 # my $fmt = DateTime::Format::Unicode->new(
711 # locale => $locale,
712 # pattern => $pattern,
713 # time_zone => $tz,
714 # );
715 # my $str = $fmt->format_datetime( $dt );
716 # return( $self->error( "Error formatting CLDR pattern \"${pattern}\" for locale ${locale}: ", $fmt->error ) ) if( !defined( $str ) && $fmt->error );
717 # return( $str );
718  
719  
720 46 ▶ my $parts = $self->format_to_parts( $this,
Condition50%1/2
$self->format_to_parts($this, 'datetime', $dt) || (return $self->pass_error)
l!l
046
MC/DC0%0/1
$self->format_to_parts($this, 'datetime', $dt) || (return $self->pass_error)
$self->format_to_parts($this, 'datetime', $dt)
Truth table50%1/2
A
A= $self->format_to_parts($this, 'datetime', $dt)
Aresult
11
00
721 datetime => $dt,
722 ) || return( $self->pass_error );
723 0 ▶ if( !scalar( @$parts ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$parts) 0 0 0
724 {
725 0 return( $self->error( "Error formatting datetime to parts. No data received!" ) );
726 }
727  
728 0 my $str = join( '', map( $_->{value}, @$parts ) );
729 0 return( $str );
730 }
731  
732 sub format_range
733 150 ▶{
Subroutine format_range: called CC=16 SCAR=37.7
Pod documented
734 150 my $self = shift( @_ );
735 150 my( $this1, $this2 ) = @_;
736 150 ▶ if( !( Scalar::Util::blessed( $this1 ) && ( $this1->isa( 'DateTime' ) || $this1->isa( 'DateTime::Lite' ) ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not builtin::blessed($this1) && ($this1->isa('DateTime') || $this1->isa('DateTime::Lite'))) { } 0 150 150
elsif (not builtin::blessed($this2) && ($this2->isa('DateTime') || $this2->isa('DateTime::Lite'))) { } 0 150 150
Condition33%2/6
builtin::blessed($this1) && ($this1->isa('DateTime') || $this1->isa('DateTime::Lite'))
!ll&&!rl&&r
00150
$this1->isa("DateTime") or $this1->isa("DateTime::Lite")
l!l&&r!l&&!r
01500
MC/DC0%0/3
builtin::blessed($this1) && ($this1->isa('DateTime') || $this1->isa('DateTime::Lite'))
builtin::blessed($this1) $this1->isa("DateTime") $this1->isa("DateTime::Lite")
Truth table25%1/4
A && B or C
A= builtin::blessed($this1)B= $this1->isa("DateTime")C= $this1->isa("DateTime::Lite")
ABCresult
0XX0
1000
11X1
1011
737 {
738 0 return( $self->error({
739 type => 'RangeError',
740 message => "Start datetime value provided is not a DateTime object."
741 }) );
742 }
743 ▶ elsif( !( Scalar::Util::blessed( $this2 ) && ( $this2->isa( 'DateTime' ) || $this2->isa( 'DateTime::Lite' ) ) ) )
Condition33%2/6
builtin::blessed($this2) && ($this2->isa('DateTime') || $this2->isa('DateTime::Lite'))
!ll&&!rl&&r
00150
$this2->isa("DateTime") or $this2->isa("DateTime::Lite")
l!l&&r!l&&!r
01500
MC/DC0%0/3
builtin::blessed($this2) && ($this2->isa('DateTime') || $this2->isa('DateTime::Lite'))
builtin::blessed($this2) $this2->isa("DateTime") $this2->isa("DateTime::Lite")
Truth table25%1/4
A && B or C
A= builtin::blessed($this2)B= $this2->isa("DateTime")C= $this2->isa("DateTime::Lite")
ABCresult
0XX0
1000
11X1
1011
744 {
745 0 return( $self->error({
746 type => 'RangeError',
747 message => "End datetime value provided is not a DateTime or a DateTime::Lite object."
748 }) );
749 }
750 150 my $dt1 = $this1->clone;
751 150 my $dt2 = $this2->clone;
752 150 my $opts = $self->resolvedOptions;
753 150 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone." );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
l!l
1500
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
754 150 ▶ my $unicode = $self->{_unicode} || die( "The DateTime::Locale::FromCLDR object is gone." );
Condition50%1/2
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
l!l
1500
MC/DC0%0/1
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
$self->{'_unicode'}
Truth table50%1/2
A
A= $self->{'_unicode'}
Aresult
11
00
755 150 ▶ my $locale = $self->{locale} || die( "Our Locale::Unicode object is gone!" );
Condition50%1/2
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
l!l
1500
MC/DC0%0/1
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
756 # We share our DateTime::Locale::FromCLDR object with DateTime, because this module fares much better than the DateTime::Locale::FromData one
757 # And it works well with DateTime::Lite too.
758 150 $dt1->set_locale( $unicode );
759 150 $dt2->set_locale( $unicode );
760 # Get the greatest difference between those two datetime
761 # Possible greatest diff: [qw( a B d G h H m M y )]
762 150 ▶ my $diff = $unicode->interval_greatest_diff( $dt1, $dt2, ( $opts->{dayPeriod} ? ( day_period_first => 1 ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'dayPeriod'} ? : 10 140 150
763 150 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $diff ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $diff and $unicode->error 0 150 150
Condition33%1/3
not defined $diff and $unicode->error
!ll&&!rl&&r
15000
MC/DC0%0/2
not defined $diff and $unicode->error
not defined $diff $unicode->error
Truth table33%1/3
not(A) and B
A= not defined $diffB= $unicode->error
ABresult
0X0
100
111
764 # If both dates are identical, we return the value from format() instead
765 150 ▶ if( !$diff )
Branch: 1 branch
BranchTrueFalseTotal
unless ($diff) 0 150 150
766 {
767 0 return( $self->format( $this1 ) );
768 }
769 150 ▶ my $parts = $self->format_range_to_parts( $this1, $this2,
Condition50%1/2
$self->format_range_to_parts($this1, $this2, 'diff', $diff, 'datetime1', $dt1, 'datetime2', $dt2) || (return $self->pass_error)
l!l
0150
MC/DC0%0/1
$self->format_range_to_parts($this1, $this2, 'diff', $diff, 'datetime1', $dt1, 'datetime2', $dt2) || (return $self->pass_error)
$self->format_range_to_parts($this1, $this2, 'diff', $diff, 'datetime1', $dt1, 'datetime2', $dt2)
Truth table50%1/2
A
A= $self->format_range_to_parts($this1, $this2, 'diff', $diff, 'datetime1', $dt1, 'datetime2', $dt2)
Aresult
11
00
770 diff => $diff,
771 datetime1 => $dt1,
772 datetime2 => $dt2,
773 ) || return( $self->pass_error );
774 0 ▶ if( !scalar( @$parts ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$parts) 0 0 0
775 {
776 0 return( $self->error( "Error formatting datetime range to parts. No data received!" ) );
777 }
778  
779 0 my $str = join( '', map( $_->{value}, @$parts ) );
780 0 return( $str );
781 }
782  
783 sub format_range_to_parts
784 225 ▶{
Subroutine format_range_to_parts: called CC=39 SCAR=45.1
Pod documented
785 225 my $self = shift( @_ );
786 225 my( $this1, $this2 ) = @_;
787 225 ▶ if( !( Scalar::Util::blessed( $this1 ) && ( $this1->isa( 'DateTime' ) || $this1->isa( 'DateTime::Lite' ) ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not builtin::blessed($this1) && ($this1->isa('DateTime') || $this1->isa('DateTime::Lite'))) { } 0 225 225
elsif (not builtin::blessed($this2) && ($this2->isa('DateTime') || $this2->isa('DateTime::Lite'))) { } 0 225 225
Condition33%2/6
builtin::blessed($this1) && ($this1->isa('DateTime') || $this1->isa('DateTime::Lite'))
!ll&&!rl&&r
00225
$this1->isa("DateTime") or $this1->isa("DateTime::Lite")
l!l&&r!l&&!r
02250
MC/DC0%0/3
builtin::blessed($this1) && ($this1->isa('DateTime') || $this1->isa('DateTime::Lite'))
builtin::blessed($this1) $this1->isa("DateTime") $this1->isa("DateTime::Lite")
Truth table25%1/4
A && B or C
A= builtin::blessed($this1)B= $this1->isa("DateTime")C= $this1->isa("DateTime::Lite")
ABCresult
0XX0
1000
11X1
1011
788 {
789 0 return( $self->error({
790 type => 'RangeError',
791 message => "Start datetime value provided is not a DateTime object."
792 }) );
793 }
794 ▶ elsif( !( Scalar::Util::blessed( $this2 ) && ( $this2->isa( 'DateTime' ) || $this2->isa( 'DateTime::Lite' ) ) ) )
Condition33%2/6
builtin::blessed($this2) && ($this2->isa('DateTime') || $this2->isa('DateTime::Lite'))
!ll&&!rl&&r
00225
$this2->isa("DateTime") or $this2->isa("DateTime::Lite")
l!l&&r!l&&!r
02250
MC/DC0%0/3
builtin::blessed($this2) && ($this2->isa('DateTime') || $this2->isa('DateTime::Lite'))
builtin::blessed($this2) $this2->isa("DateTime") $this2->isa("DateTime::Lite")
Truth table25%1/4
A && B or C
A= builtin::blessed($this2)B= $this2->isa("DateTime")C= $this2->isa("DateTime::Lite")
ABCresult
0XX0
1000
11X1
1011
795 {
796 0 return( $self->error({
797 type => 'RangeError',
798 message => "End datetime value provided is not a DateTime object."
799 }) );
800 }
801 225 splice( @_, 0 , 2 );
802 225 my $args = $self->_get_args_as_hash( @_ );
803 225 my $opts = $self->resolvedOptions;
804 225 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone." );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
l!l
2250
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
805 225 ▶ my $unicode = $self->{_unicode} || die( "The DateTime::Locale::FromCLDR object is gone." );
Condition50%1/2
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
l!l
2250
MC/DC0%0/1
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
$self->{'_unicode'}
Truth table50%1/2
A
A= $self->{'_unicode'}
Aresult
11
00
806 225 ▶ my $locale = $self->{locale} || die( "Our Locale::Unicode object is gone!" );
Condition50%1/2
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
l!l
2250
MC/DC0%0/1
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
807 225 my( $dt1, $dt2 );
808 # Save computational time; if it was provided (internally used), then let's use them.
809 225 ▶ if( $args->{datetime1} && $args->{datetime2} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'datetime1'} and $args->{'datetime2'}) { } 150 75 225
Condition66%2/3
$args->{"datetime1"} and $args->{"datetime2"}
!ll&&!rl&&r
750150
MC/DC50%1/2
$args->{"datetime1"} and $args->{"datetime2"}
$args->{"datetime1"} $args->{"datetime2"}
Truth table66%2/3
A and B
A= $args->{"datetime1"}B= $args->{"datetime2"}
ABresult
0X0
100
111
810 {
811 150 $dt1 = $args->{datetime1};
812 150 $dt2 = $args->{datetime2};
813 }
814 else
815 {
816 75 $dt1 = $this1->clone;
817 75 $dt2 = $this2->clone;
818 # We share our DateTime::Locale::FromCLDR object with DateTime, because this module fares much better than the DateTime::Locale::FromData one
819 # And it is native for DateTime::Lite too.
820 75 $dt1->set_locale( $unicode );
821 75 $dt2->set_locale( $unicode );
822 }
823  
824 # Get the greatest difference between those two datetime
825 # Possible greatest diff: [qw( a B d G h H m M y )]
826 225 my $diff;
827 # Save computational power, and share with us the already computed greatest difference
828 225 ▶ if( exists( $args->{diff} ) && defined( $args->{diff} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{'diff'} and defined $args->{'diff'}) { } 150 75 225
Condition66%2/3
exists $args->{"diff"} and defined $args->{"diff"}
!ll&&!rl&&r
750150
MC/DC50%1/2
exists $args->{"diff"} and defined $args->{"diff"}
exists $args->{"diff"} defined $args->{"diff"}
Truth table66%2/3
A and B
A= exists $args->{"diff"}B= defined $args->{"diff"}
ABresult
0X0
100
111
829 {
830 150 $diff = $args->{diff};
831 }
832 else
833 {
834 75 ▶ $diff = $unicode->interval_greatest_diff( $dt1, $dt2, ( $opts->{dayPeriod} ? ( day_period_first => 1 ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'dayPeriod'} ? : 5 70 75
835 75 ▶ return( $self->pass_error( $unicode->error ) ) if( !defined( $diff ) && $unicode->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $diff and $unicode->error 0 75 75
Condition33%1/3
not defined $diff and $unicode->error
!ll&&!rl&&r
7500
MC/DC0%0/2
not defined $diff and $unicode->error
not defined $diff $unicode->error
Truth table33%1/3
not(A) and B
A= not defined $diffB= $unicode->error
ABresult
0X0
100
111
836 }
837 # If both dates are identical, we return the value from format() instead
838 225 ▶ if( !$diff )
Branch: 1 branch
BranchTrueFalseTotal
unless ($diff) 0 225 225
839 {
840 0 return( $self->format_to_parts( $this1 ) );
841 }
842 # Adjust the greatest difference if it is 'h' or 'H' and we have the optionCycle set, meaning the user has selected some hour-related options
843 225 ▶ if( ( $diff eq 'h' || $diff eq 'H' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($diff eq "h" || $diff eq "H" and exists $opts->{"hourCycle"} and $opts->{"hourCycle"}) 39 186 225
Condition66%6/9
$diff eq "h" || $diff eq "H" and exists $opts->{"hourCycle"} and $opts->{"hourCycle"}
!ll&&!rl&&r
186039
$diff eq "h" || $diff eq "H" and exists $opts->{"hourCycle"}
!ll&&!rl&&r
186039
$diff eq "h" or $diff eq "H"
l!l&&r!l&&!r
390186
MC/DC25%1/4
$diff eq "h" || $diff eq "H" and exists $opts->{"hourCycle"} and $opts->{"hourCycle"}
$diff eq "h" $diff eq "H" exists $opts->{"hourCycle"} $opts->{"hourCycle"}
Truth table28%2/7
A or B and C and D
A= $diff eq "h"B= $diff eq "H"C= exists $opts->{"hourCycle"}D= $opts->{"hourCycle"}
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
844 exists( $opts->{hourCycle} ) &&
845 $opts->{hourCycle} )
846 {
847 39 ▶ my $should_be_diff = ( $opts->{hourCycle} eq 'h23' || $opts->{hourCycle} eq 'h24' ) ? 'H' : 'h';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'hourCycle'} eq 'h23' || $opts->{'hourCycle'} eq 'h24' ? : 12 27 39
Condition66%2/3
$opts->{"hourCycle"} eq "h23" or $opts->{"hourCycle"} eq "h24"
l!l&&r!l&&!r
01227
MC/DC50%1/2
$opts->{"hourCycle"} eq "h23" or $opts->{"hourCycle"} eq "h24"
$opts->{"hourCycle"} eq "h23" $opts->{"hourCycle"} eq "h24"
Truth table66%2/3
A or B
A= $opts->{"hourCycle"} eq "h23"B= $opts->{"hourCycle"} eq "h24"
ABresult
1X1
011
000
848 39 $diff = $should_be_diff;
849 }
850 # NOTE: Getting patterns
851 225 my $cache_key = "interval_${diff}_" . join( '|', map{ $_ . ';' . $opts->{ $_ } } sort( keys( %$opts ) ) );
852 225 my $def = $self->_get_cached_pattern( $locale, $cache_key );
853 225 ▶ unless( $def )
Branch: 1 branch
BranchTrueFalseTotal
unless ($def) 216 9 225
854 {
855 # Hash reference of format_id to hash of properties
856 216 my $all = $self->_get_available_interval_patterns( $diff );
857 216 ▶ if( !defined( $all ) || !scalar( keys( %$all ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $all and scalar keys %$all) 0 216 216
Condition33%1/3
defined $all and scalar keys %$all
!ll&&!rl&&r
00216
MC/DC0%0/2
defined $all and scalar keys %$all
defined $all scalar keys %$all
Truth table33%1/3
A and B
A= defined $allB= scalar keys %$all
ABresult
0X0
100
111
858 {
859 0 return( $self->error( "No interval patterns found for locale \"${locale}\"." ) );
860 }
861 216 my $patterns = {};
862 216 foreach my $skel ( sort( keys( %$all ) ) )
863 {
864 2763 my $pat = $all->{ $skel }->{format_pattern};
865 2763 ▶ if( !length( $pat // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($pat // "")) 0 2763 2763
Condition50%1/2
$pat // ""
l!l
27630
MC/DC0%0/1
$pat // ""
$pat
Truth table50%1/2
A
A= $pat
Aresult
11
00
866 {
867 0 ▶ warn( "Empty pattern for skeleton '${skel}' for locale '${locale}' and greatest difference '${diff}'." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
868 0 next;
869 }
870 2763 my $repeating_pattern = $all->{ $skel }->{repeating_field};
871 2763 my $pos_start = index( $pat, $repeating_pattern );
872 2763 ▶ if( $pos_start != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($pos_start != -1) 2649 114 2763
873 {
874 2649 substr( $pat, $pos_start, length( $repeating_pattern ), '' );
875 }
876 2763 $patterns->{ $skel } = $pat;
877 }
878  
879 # my $patterns = $unicode->available_format_patterns;
880 216 ▶ my $score_object = $self->_select_best_pattern(
Condition50%1/2
$self->_select_best_pattern('patterns', $patterns, 'options', $opts, 'diff', $diff) || (return $self->pass_error)
l!l
2160
MC/DC0%0/1
$self->_select_best_pattern('patterns', $patterns, 'options', $opts, 'diff', $diff) || (return $self->pass_error)
$self->_select_best_pattern('patterns', $patterns, 'options', $opts, 'diff', $diff)
Truth table50%1/2
A
A= $self->_select_best_pattern('patterns', $patterns, 'options', $opts, 'diff', $diff)
Aresult
11
00
881 patterns => $patterns,
882 options => $opts,
883 diff => $diff,
884 ) || return( $self->pass_error );
885  
886 216 my $pattern = $score_object->pattern_object->pattern;
887 216 my $interval_skeleton = $score_object->pattern_object->skeleton;
888 216 my $has_missing_components = $score_object->has_missing;
889 # If the result has some missing components, well, we're screwed, because the LDML does not explain how to deal with it
890  
891 216 my $ref;
892 # "Once a best match is found between requested skeleton and dateFormatItem id, the corresponding dateFormatItem pattern is used, but with adjustments primarily to make the pattern field lengths match the skeleton field lengths."
893 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
894 # No need to bother calling this method, if there is no need for adjustment
895 216 ▶ if( $score_object->need_adjustment )
Branch: 1 branch
BranchTrueFalseTotal
if ($score_object->need_adjustment) { } 18 198 216
896 {
897 # $ref has a structure like: [ $part1, $sep, $part2, $best ]
898 18 ▶ $ref = $cldr->split_interval(
Condition50%1/2
$cldr->split_interval('greatest_diff', $diff, 'pattern', $pattern) || (return $self->pass_error($cldr->error))
l!l
180
MC/DC0%0/1
$cldr->split_interval('greatest_diff', $diff, 'pattern', $pattern) || (return $self->pass_error($cldr->error))
$cldr->split_interval('greatest_diff', $diff, 'pattern', $pattern)
Truth table50%1/2
A
A= $cldr->split_interval('greatest_diff', $diff, 'pattern', $pattern)
Aresult
11
00
899 greatest_diff => $diff,
900 pattern => $pattern,
901 ) || return( $self->pass_error( $cldr->error ) );
902 }
903 else
904 {
905 198 my $data = $all->{ $interval_skeleton };
906 198 $ref = [@$data{qw( part1 separator part2 )}];
907 }
908  
909 216 $def =
910 {
911 parts => $ref,
912 # Possibly adjusted pattern
913 pattern => $pattern,
914 skeleton => $interval_skeleton,
915 };
916 216 $self->_set_cached_pattern( $locale, $cache_key, $def );
917 }
918 225 $self->{_interval_pattern} = $def->{pattern};
919 225 $self->{_interval_skeleton} = $def->{skeleton};
920 225 $self->{_greatest_diff} = $diff;
921 225 my $parts = [];
922  
923 my $parts1 = $self->_format_to_parts(
924 225 ▶ pattern => $def->{parts}->[0],
Condition50%1/2
$self->_format_to_parts('pattern', $def->{'parts'}[0], 'datetime', $dt1) || (return $self->pass_error)
l!l
0225
MC/DC0%0/1
$self->_format_to_parts('pattern', $def->{'parts'}[0], 'datetime', $dt1) || (return $self->pass_error)
$self->_format_to_parts('pattern', $def->{'parts'}[0], 'datetime', $dt1)
Truth table50%1/2
A
A= $self->_format_to_parts('pattern', $def->{'parts'}[0], 'datetime', $dt1)
Aresult
11
00
925 datetime => $dt1,
926 ) || return( $self->pass_error );
927 0 for( @$parts1 )
928 {
929 0 $_->{source} = 'startRange';
930 }
931 0 push( @$parts, @$parts1 );
932 # Add the separator
933 push( @$parts, {
934 type => 'literal',
935 0 value => $def->{parts}->[1],
936 source => 'shared',
937 });
938 my $parts2 = $self->_format_to_parts(
939 0 ▶ pattern => $def->{parts}->[2],
Condition0%0/2
$self->_format_to_parts('pattern', $def->{'parts'}[2], 'datetime', $dt2) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_format_to_parts('pattern', $def->{'parts'}[2], 'datetime', $dt2) || (return $self->pass_error)
$self->_format_to_parts('pattern', $def->{'parts'}[2], 'datetime', $dt2)
Truth table0%0/2
A
A= $self->_format_to_parts('pattern', $def->{'parts'}[2], 'datetime', $dt2)
Aresult
11
00
940 datetime => $dt2,
941 ) || return( $self->pass_error );
942 0 for( @$parts2 )
943 {
944 0 $_->{source} = 'endRange';
945 }
946 0 push( @$parts, @$parts2 );
947 0 return( $parts );
948 }
949  
950 sub format_to_parts
951 92 ▶{
Subroutine format_to_parts: called CC=18 SCAR=38.7
Pod documented
952 92 my $self = shift( @_ );
953 92 ▶ return( $self->error( "format() must be called with an object, and not as a class function." ) ) if( !ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 92 92
954 92 my $this = shift( @_ );
955 92 ▶ if( !defined( $this ) || !length( $this // '' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $this && length($this // '')) { } 0 92 92
elsif (not builtin::blessed($this) && ($this->isa('DateTime') || $this->isa('DateTime::Lite'))) { } 0 92 92
Condition40%2/5
defined $this && length($this // '')
!ll&&!rl&&r
0092
$this // ""
l!l
920
MC/DC0%0/2
defined $this && length($this // '')
defined $this $this
Truth table33%1/3
A && B
A= defined $thisB= $this
ABresult
0X0
100
111
956 {
957 0 $this = DateTime::Lite->now;
958 }
959 ▶ elsif( !( Scalar::Util::blessed( $this ) && ( $this->isa( 'DateTime' ) || $this->isa( 'DateTime::Lite' ) ) ) )
Condition33%2/6
builtin::blessed($this) && ($this->isa('DateTime') || $this->isa('DateTime::Lite'))
!ll&&!rl&&r
0092
$this->isa("DateTime") or $this->isa("DateTime::Lite")
l!l&&r!l&&!r
0920
MC/DC0%0/3
builtin::blessed($this) && ($this->isa('DateTime') || $this->isa('DateTime::Lite'))
builtin::blessed($this) $this->isa("DateTime") $this->isa("DateTime::Lite")
Truth table25%1/4
A && B or C
A= builtin::blessed($this)B= $this->isa("DateTime")C= $this->isa("DateTime::Lite")
ABCresult
0XX0
1000
11X1
1011
960 {
961 0 return( $self->error({
962 type => 'RangeError',
963 message => "Date value provided is not a DateTime or DateTime::Lite object."
964 }) );
965 }
966 92 my $args = {};
967 92 ▶ $args = $self->_get_args_as_hash( @_ ) if( ( scalar( @_ ) == 1 && ref( $_[0] // '' ) eq 'HASH' ) || !( @_ % 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and ref($_[0] // "") eq "HASH" or not @_ % 2 92 0 92
Condition25%2/8
scalar @_ == 1 and ref($_[0] // "") eq "HASH" or not @_ % 2
l!l&&r!l&&!r
0920
scalar @_ == 1 and ref($_[0] // "") eq "HASH"
!ll&&!rl&&r
9200
$_[0] // ""
l!l
00
MC/DC0%0/3
scalar @_ == 1 and ref($_[0] // "") eq "HASH" or not @_ % 2
scalar @_ == 1 $_[0] not @_ % 2
Truth table20%1/5
A and B or not(C)
A= scalar @_ == 1B= $_[0]C= not @_ % 2
ABCresult
11X1
0X11
1011
0X00
1000
968 92 my $opts = $self->resolvedOptions;
969 92 ▶ my $unicode = $self->{_unicode} || die( "The DateTime::Locale::FromCLDR object is gone." );
Condition50%1/2
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
l!l
920
MC/DC0%0/1
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
$self->{'_unicode'}
Truth table50%1/2
A
A= $self->{'_unicode'}
Aresult
11
00
970 # This is built upon object instantiation, so that format(9 can be called multiple times and run more rapidly.
971 92 ▶ my $pattern = $self->{_pattern} || die( "Saved pattern is gone!" );
Condition50%1/2
$self->{'_pattern'} || die('Saved pattern is gone!')
l!l
920
MC/DC0%0/1
$self->{'_pattern'} || die('Saved pattern is gone!')
$self->{'_pattern'}
Truth table50%1/2
A
A= $self->{'_pattern'}
Aresult
11
00
972 92 my $dt;
973 # Save computational time; if it was provided (internally used), then let's use them.
974 92 ▶ if( $args->{datetime} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'datetime'}) { } 46 46 92
975 {
976 46 $dt = $args->{datetime};
977 }
978 else
979 {
980 46 $dt = $this->clone;
981 # We share our DateTime::Locale::FromCLDR object with DateTime, because this module fares much better than the DateTime::Locale::FromData one
982 # And it works naturally with DateTime::Lite too.
983 46 $dt->set_locale( $unicode );
984 }
985  
986 92 my $tz;
987 92 ▶ if( $opts->{timeZone} )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'timeZone'}) { } 92 0 92
elsif ($tz eq 'floating') { } 0 0 0
988 {
989 92 $dt->set_time_zone( $tz = $opts->{timeZone} );
990 }
991 elsif( $tz eq 'floating' )
992 {
993 0 $dt->set_time_zone( $tz = 'UTC' );
994 }
995 else
996 {
997 0 $tz = $dt->time_zone->name;
998 }
999  
1000 92 ▶ my $parts = $self->_format_to_parts(
Condition50%1/2
$self->_format_to_parts('pattern', $pattern, 'datetime', $dt) || (return $self->pass_error)
l!l
092
MC/DC0%0/1
$self->_format_to_parts('pattern', $pattern, 'datetime', $dt) || (return $self->pass_error)
$self->_format_to_parts('pattern', $pattern, 'datetime', $dt)
Truth table50%1/2
A
A= $self->_format_to_parts('pattern', $pattern, 'datetime', $dt)
Aresult
11
00
1001 pattern => $pattern,
1002 datetime => $dt,
1003 ) || return( $self->pass_error );
1004 0 return( $parts );
1005 }
1006  
1007 0 ▶sub formatRange { return( shift->format_range( @_ ) ); }
Subroutine formatRange: not called CC=1 SCAR=6.9
Pod documented
1008  
1009 0 ▶sub formatRangeToParts { return( shift->format_range_to_parts( @_ ) ); }
Subroutine formatRangeToParts: not called CC=1 SCAR=6.9
Pod documented
1010  
1011 0 ▶sub formatToParts { return( shift->format_to_parts( @_ ) ); }
Subroutine formatToParts: not called CC=1 SCAR=6.9
Pod documented
1012  
1013 150 ▶sub greatest_diff { return( shift->{_greatest_diff} ); }
Subroutine greatest_diff: called CC=1 SCAR=0.0
Pod documented
1014  
1015 150 ▶sub interval_pattern { return( shift->{_interval_pattern} ); }
Subroutine interval_pattern: called CC=1 SCAR=0.0
Pod documented
1016  
1017 150 ▶sub interval_skeleton { return( shift->{_interval_skeleton} ); }
Subroutine interval_skeleton: called CC=1 SCAR=0.0
Pod documented
1018  
1019 sub pass_error
1020 830 ▶{
Subroutine pass_error: called CC=37 SCAR=53.0
Pod undocumented
1021 830 my $self = shift( @_ );
1022 830 ▶ my $pack = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
83000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1023 830 my $opts = {};
1024 830 my( $err, $class, $code );
1025 11 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1026 830 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 317 513 830
1027 {
1028 # Either an hash defining a new error and this will be passed along to error(); or
1029 # an hash with a single property: { class => 'Some::ExceptionClass' }
1030 317 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 317 317
Condition33%1/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
03170
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
1031 {
1032 0 $opts = $_[0];
1033 }
1034 else
1035 {
1036 317 ▶ if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH") 0 317 317
Condition33%1/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
31700
MC/DC0%0/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1 ref $_[-1] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
1037 {
1038 0 $opts = pop( @_ );
1039 }
1040 317 $err = $_[0];
1041 }
1042 }
1043 830 ▶ $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 830 830
Condition44%4/9
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
!ll&&!rl&&r
83000
not defined $err and exists $opts->{"error"} and defined $opts->{"error"}
!ll&&!rl&&r
83000
not defined $err and exists $opts->{"error"}
!ll&&!rl&&r
3175130
MC/DC0%0/4
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
not defined $err exists $opts->{"error"} defined $opts->{"error"} length $opts->{"error"}
Truth table40%2/5
not(A) and B and C and D
A= not defined $errB= exists $opts->{"error"}C= defined $opts->{"error"}D= length $opts->{"error"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1044 # We set $class only if the hash provided is a one-element hash and not an error-defining hash
1045 830 ▶ $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 830 830
Condition33%2/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
!ll&&!rl&&r
83000
exists $opts->{"class"} and defined $opts->{"class"}
!ll&&!rl&&r
83000
MC/DC0%0/3
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
exists $opts->{"class"} defined $opts->{"class"} length $opts->{"class"}
Truth table25%1/4
A and B and C
A= exists $opts->{"class"}B= defined $opts->{"class"}C= length $opts->{"class"}
ABCresult
0XX0
10X0
1100
1111
1046 830 ▶ $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 830 830
Condition33%2/6
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
!ll&&!rl&&r
83000
exists $opts->{"code"} and defined $opts->{"code"}
!ll&&!rl&&r
83000
MC/DC0%0/3
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
exists $opts->{"code"} defined $opts->{"code"} length $opts->{"code"}
Truth table25%1/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length $opts->{"code"}
ABCresult
0XX0
10X0
1100
1111
1047
1048 # called with no argument, most likely from the same class to pass on an error
1049 # set up earlier by another method; or
1050 # with an hash containing just one argument class => 'Some::ExceptionClass'
1051 830 ▶ if( !defined( $err ) && ( !scalar( @_ ) || defined( $class ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $err and !scalar(@_) || defined $class) { } 513 317 830
elsif (defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class) { } 317 0 317
Condition50%3/6
not defined $err and !scalar(@_) || defined $class
!ll&&!rl&&r
3170513
not scalar @_ or defined $class
l!l&&r!l&&!r
51300
MC/DC33%1/3
not defined $err and !scalar(@_) || defined $class
not defined $err not scalar @_ defined $class
Truth table50%2/4
not(A) and not(B) or C
A= not defined $errB= not scalar @_C= defined $class
ABCresult
0XX0
1000
11X1
1011
1052 {
1053 # $error is a previous erro robject
1054 0 ▶ my $error = ref( $self ) ? $self->{error} : length( ${ $pack . '::ERROR' } ) ? ${ $pack . '::ERROR' } : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $self ? : 513 0 513
length ${$pack . '::ERROR';} ? : 0 0 0
1055 513 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 513 513
1056 {
1057 0 warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef" );
1058 }
1059 else
1060 {
1061 513 ▶ $err = ( defined( $class ) ? bless( $error => $class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 513 513
1062 513 ▶ $err->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 513 513
1063 }
1064 }
1065 ▶ elsif( defined( $err ) &&
Condition25%3/12
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class
!ll&&!rl&&r
00317
defined $err and builtin::blessed($err)
!ll&&!rl&&r
00317
scalar @_ == 1 or scalar @_ == 2 and defined $class
l!l&&r!l&&!r
31700
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 table16%1/6
A and B and C or D and E
A= defined $errB= builtin::blessed($err)C= scalar @_ == 1D= scalar @_ == 2E= defined $class
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
1066 Scalar::Util::blessed( $err ) &&
1067 ( scalar( @_ ) == 1 ||
1068 ( scalar( @_ ) == 2 && defined( $class ) )
1069 ) )
1070 {
1071 317 ▶ $self->{error} = ${ $pack . '::ERROR' } = ( defined( $class ) ? bless( $err => $class ) : $err );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 317 317
1072 317 ▶ $self->{error}->code( $code ) if( defined( $code ) && $self->{error}->can( 'code' ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code and $self->{"error"}->can("code") 0 317 317
Condition33%1/3
defined $code and $self->{"error"}->can("code")
!ll&&!rl&&r
31700
MC/DC0%0/2
defined $code and $self->{"error"}->can("code")
defined $code $self->{"error"}->can("code")
Truth table33%1/3
A and B
A= defined $codeB= $self->{"error"}->can("code")
ABresult
0X0
100
111
1073
1074 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 317 317
Condition33%2/6
$self->{"fatal"} or defined ${"${class}::FATAL_EXCEPTIONS";} and ${"${class}::FATAL_EXCEPTIONS";}
l!l&&r!l&&!r
00317
defined ${"${class}::FATAL_EXCEPTIONS";} and ${"${class}::FATAL_EXCEPTIONS";}
!ll&&!rl&&r
31700
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 table25%1/4
A or B and C
A= $self->{"fatal"}B= defined ${"${class}::FATAL_EXCEPTIONS";}C= ${"${class}::FATAL_EXCEPTIONS";}
ABCresult
1XX1
0111
00X0
0100
1075 {
1076 0 die( $self->{error} );
1077 }
1078 }
1079 # If the error provided is not an object, we call error to create one
1080 else
1081 {
1082 0 return( $self->error( @_ ) );
1083 }
1084
1085 830 ▶ if( Wanted::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (Wanted::want("OBJECT")) 0 830 830
1086 {
1087 0 rreturn( DateTime::Format::Intl::NullObject->new );
1088 }
1089 830 return;
1090 }
1091  
1092 65 ▶sub pattern { return( shift->{_pattern} ); }
Subroutine pattern: called CC=1 SCAR=0.0
Pod documented
1093  
1094 884 ▶sub resolvedOptions { return( shift->_set_get_prop( 'resolvedOptions', @_ ) ); }
Subroutine resolvedOptions: called CC=1 SCAR=0.0
Pod documented
1095  
1096 65 ▶sub skeleton { return( shift->{_skeleton} ); }
Subroutine skeleton: called CC=1 SCAR=0.0
Pod documented
1097  
1098 sub supportedLocalesOf
1099 1 ▶{
Subroutine supportedLocalesOf: called CC=16 SCAR=33.3
Pod documented
1100 1 my $self = shift( @_ );
1101 1 my $locales = shift( @_ );
1102 1 my $opts = $self->_get_args_as_hash( @_ );
1103 1 my $res = [];
1104 1 ▶ if( !defined( $locales ) || !length( $locales ) || ( ( Scalar::Util::reftype( $locales ) // '' ) eq 'ARRAY' && !scalar( @$locales ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $locales && length $locales or (builtin::reftype($locales) // "") eq "ARRAY" and not scalar @$locales) 0 1 1
Condition36%4/11
not defined $locales && length $locales or (builtin::reftype($locales) // "") eq "ARRAY" and not scalar @$locales
l!l&&r!l&&!r
001
defined $locales && length $locales
!ll&&!rl&&r
001
(builtin::reftype($locales) // "") eq "ARRAY" and not scalar @$locales
!ll&&!rl&&r
010
builtin::reftype($locales) // ""
l!l
10
MC/DC0%0/4
not defined $locales && length $locales or (builtin::reftype($locales) // "") eq "ARRAY" and not scalar @$locales
defined $locales length $locales builtin::reftype($locales) not scalar @$locales
Truth table20%1/5
not(A && B) or C and not(D)
A= defined $localesB= length $localesC= builtin::reftype($locales)D= not scalar @$locales
ABCDresult
0XXX1
10XX1
11111
110X0
11100
1105 {
1106 0 return( $res );
1107 }
1108 1 ▶ $locales = ( Scalar::Util::reftype( $locales ) // '' ) eq 'ARRAY' ? $locales : [$locales];
Branch: 1 branch
BranchTrueFalseTotal
(builtin::reftype($locales) // '') eq 'ARRAY' ? : 1 0 1
Condition50%1/2
builtin::reftype($locales) // ""
l!l
10
MC/DC0%0/1
builtin::reftype($locales) // ""
builtin::reftype($locales)
Truth table50%1/2
A
A= builtin::reftype($locales)
Aresult
11
00
1109 1 ▶ my $cldr = $self->_cldr || return( $self->pass_error );
Condition50%1/2
$self->_cldr || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->_cldr || (return $self->pass_error)
$self->_cldr
Truth table50%1/2
A
A= $self->_cldr
Aresult
11
00
1110 1 ▶ LOCALE: for( my $i = 0; $i < scalar( @$locales ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$locales) 3 1 4
1111 {
1112 3 ▶ my $locale = Locale::Intl->new( $locales->[$i] ) ||
Condition50%1/2
'Locale::Intl'->new($locales->[$i]) || (return $self->pass_error('Locale::Intl'->error))
l!l
30
MC/DC0%0/1
'Locale::Intl'->new($locales->[$i]) || (return $self->pass_error('Locale::Intl'->error))
'Locale::Intl'->new($locales->[$i])
Truth table50%1/2
A
A= 'Locale::Intl'->new($locales->[$i])
Aresult
11
00
1113 return( $self->pass_error( Locale::Intl->error ) );
1114 3 ▶ my $tree = $cldr->make_inheritance_tree( $locale->core ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale->core) || (return $self->pass_error($cldr->error))
l!l
30
MC/DC0%0/1
$cldr->make_inheritance_tree($locale->core) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale->core)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale->core)
Aresult
11
00
1115 return( $self->pass_error( $cldr->error ) );
1116 # Remove the last one, which is 'und', a.k.a 'root'
1117 3 pop( @$tree );
1118 3 foreach my $loc ( @$tree )
1119 {
1120 3 my $ref = $cldr->locale( locale => $loc );
1121 3 ▶ if( $ref && ref( $ref ) eq 'HASH' && scalar( keys( %$ref ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and ref $ref eq "HASH" and scalar keys %$ref) 3 0 3
Condition40%2/5
$ref and ref $ref eq "HASH" and scalar keys %$ref
!ll
03
$ref and ref $ref eq "HASH"
!ll&&!rl&&r
003
MC/DC0%0/2
$ref and ref $ref eq "HASH" and scalar keys %$ref
$ref ref $ref eq "HASH"
Truth table33%1/3
A and B
A= $refB= ref $ref eq "HASH"
ABresult
0X0
100
111
1122 {
1123 3 push( @$res, $loc );
1124 3 next LOCALE;
1125 }
1126 }
1127 }
1128 1 return( $res );
1129 }
1130  
1131 # Adjust pattern to match the specified format for each component:
1132 # "Once a best match is found between requested skeleton and dateFormatItem id, the corresponding dateFormatItem pattern is used, but with adjustments primarily to make the pattern field lengths match the skeleton field lengths."
1133 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
1134 sub _adjust_pattern
1135 75 ▶{
Subroutine _adjust_pattern: called CC=48 SCAR=56.7
1136 75 my $self = shift( @_ );
1137 75 my $args = $self->_get_args_as_hash( @_ );
1138 75 ▶ my $pattern = $args->{pattern} || die( "No pattern was provided." );
Condition50%1/2
$args->{'pattern'} || die('No pattern was provided.')
l!l
750
MC/DC0%0/1
$args->{'pattern'} || die('No pattern was provided.')
$args->{'pattern'}
Truth table50%1/2
A
A= $args->{'pattern'}
Aresult
11
00
1139 75 ▶ my $opts = $args->{options} || die( "No resolved options hash was provided." );
Condition50%1/2
$args->{'options'} || die('No resolved options hash was provided.')
l!l
750
MC/DC0%0/1
$args->{'options'} || die('No resolved options hash was provided.')
$args->{'options'}
Truth table50%1/2
A
A= $args->{'options'}
Aresult
11
00
1140 75 ▶ if( ref( $pattern ) && !overload::Method( $pattern => '""' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $pattern and not overload::Method($pattern, '""')) { } 0 75 75
elsif (ref $opts ne 'HASH') { } 0 75 75
Condition33%1/3
ref $pattern and not overload::Method($pattern, "\"\"")
!ll&&!rl&&r
7500
MC/DC0%0/2
ref $pattern and not overload::Method($pattern, "\"\"")
ref $pattern not overload::Method($pattern, "\"\"")
Truth table33%1/3
A and not(B)
A= ref $patternB= not overload::Method($pattern, "\"\"")
ABresult
0X0
100
111
1141 {
1142 0 return( $self->error( "Pattern provided (", overload::StrVal( $pattern ), ") is a reference, but does not stringify." ) );
1143 }
1144 elsif( ref( $opts ) ne 'HASH' )
1145 {
1146 0 ▶ return( $self->error( "Resolved options provided (", overload::StrVal( $opts // 'undef' ), ") is not an hash reference." ) );
Condition0%0/2
$opts // "undef"
l!l
00
MC/DC0%0/1
$opts // "undef"
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1147 }
1148 75 ▶ my $request_object = $args->{request_object} || die( "Missing the request object." );
Condition50%1/2
$args->{'request_object'} || die('Missing the request object.')
l!l
750
MC/DC0%0/1
$args->{'request_object'} || die('Missing the request object.')
$args->{'request_object'}
Truth table50%1/2
A
A= $args->{'request_object'}
Aresult
11
00
1149 # Might not be provided.
1150 75 my $pattern_object = $args->{pattern_object};
1151 75 ▶ if( !ref( $request_object ) || ( ref( $request_object ) && !$request_object->isa( 'DateTime::Format::Intl::Skeleton' ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $request_object or ref $request_object and not $request_object->isa('DateTime::Format::Intl::Skeleton')) { } 0 75 75
elsif (defined $pattern_object and !ref($pattern_object) || ref $pattern_object && !$pattern_object->isa('DateTime::Format::Intl::Skeleton')) { } 0 75 75
Condition33%2/6
not ref $request_object or ref $request_object and not $request_object->isa("DateTime::Format::Intl::Skeleton")
l!l&&r!l&&!r
0075
ref $request_object and not $request_object->isa("DateTime::Format::Intl::Skeleton")
!ll&&!rl&&r
0750
MC/DC0%0/3
not ref $request_object or ref $request_object and not $request_object->isa("DateTime::Format::Intl::Skeleton")
not ref $request_object ref $request_object not $request_object->isa("DateTime::Format::Intl::Skeleton")
Truth table25%1/4
not(A) or B and not(C)
A= not ref $request_objectB= ref $request_objectC= not $request_object->isa("DateTime::Format::Intl::Skeleton")
ABCresult
1XX1
0111
00X0
0100
1152 {
1153 0 ▶ return( $self->error( "The request object provided (", overload::StrVal( $request_object // 'undef' ), ") is not a DateTime::Format::Intl::Skeleton object." ) );
Condition0%0/2
$request_object // "undef"
l!l
00
MC/DC0%0/1
$request_object // "undef"
$request_object
Truth table0%0/2
A
A= $request_object
Aresult
11
00
1154 }
1155 ▶ elsif( defined( $pattern_object ) &&
Condition33%3/9
defined $pattern_object and !ref($pattern_object) || ref $pattern_object && !$pattern_object->isa("DateTime::Format::Intl::Skeleton")
!ll&&!rl&&r
0750
not ref $pattern_object or ref $pattern_object and not $pattern_object->isa("DateTime::Format::Intl::Skeleton")
l!l&&r!l&&!r
0075
ref $pattern_object and not $pattern_object->isa("DateTime::Format::Intl::Skeleton")
!ll&&!rl&&r
0750
MC/DC0%0/4
defined $pattern_object and !ref($pattern_object) || ref $pattern_object && !$pattern_object->isa("DateTime::Format::Intl::Skeleton")
defined $pattern_object not ref $pattern_object ref $pattern_object not $pattern_object->isa("DateTime::Format::Intl::Skeleton")
Truth table20%1/5
A and not(B) or C and not(D)
A= defined $pattern_objectB= not ref $pattern_objectC= ref $pattern_objectD= not $pattern_object->isa("DateTime::Format::Intl::Skeleton")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1156 ( !ref( $pattern_object ) || ( ref( $pattern_object ) && !$pattern_object->isa( 'DateTime::Format::Intl::Skeleton' ) ) ) )
1157 {
1158 0 ▶ return( $self->error( "The pattern object provided (", overload::StrVal( $pattern_object // 'undef' ), ") is not a DateTime::Format::Intl::Skeleton object." ) );
Condition0%0/2
$pattern_object // "undef"
l!l
00
MC/DC0%0/1
$pattern_object // "undef"
$pattern_object
Truth table0%0/2
A
A= $pattern_object
Aresult
11
00
1159 }
1160 75 ▶ my $unicode = $self->{_unicode} || die( "The DateTime::Locale::FromCLDR object is gone." );
Condition50%1/2
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
l!l
750
MC/DC0%0/1
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone.')
$self->{'_unicode'}
Truth table50%1/2
A
A= $self->{'_unicode'}
Aresult
11
00
1161 75 my $component_precision = {};
1162 75 my $options_map = $self->_get_options_map;
1163  
1164 my $component_to_match =
1165 {
1166 # Those are not related to pattern, but because they are in our options we add them here to avoid an error, but discard them later
1167 calendar => undef,
1168 numberingSystem => undef,
1169 # This option is used as an ancillary value to hourCycle option
1170 hour12 => undef,
1171 # hourCycle itself is only present if the option 'hour' is set
1172 hourCycle => undef,
1173 locale => undef,
1174 timeZone => undef,
1175 era => sub
1176 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1177 0 return( ['G' => 'G' x $options_map->{type_to_length}->{ $opts->{era} } ] );
1178 },
1179 year => 'y',
1180 # Possible values: numeric, 2-digit, long, short, narrow
1181 month => sub
1182 28 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
1183 # We respect the locale's choice for month display, whether it is 'L' or 'M'
1184 return({
1185 'L' => ( 'L' x $options_map->{month}->{ $opts->{month} } ),
1186 28 'M' => ( 'M' x $options_map->{month}->{ $opts->{month} } ),
1187 });
1188 },
1189 day => 'd',
1190 # Possible values are 'narrow', 'short' and 'long'
1191 dayPeriod => sub
1192 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1193 return({
1194 'a' => ( 'a' x $options_map->{type_to_length}->{ $opts->{dayPeriod} } ),
1195 'b' => ( 'b' x $options_map->{type_to_length}->{ $opts->{dayPeriod} } ),
1196 0 'B' => ( 'B' x $options_map->{type_to_length}->{ $opts->{dayPeriod} } ),
1197 });
1198 },
1199 # For hours, whatever the pattern, be it 'h', 'H', 'k', or 'K', it is overriden by the user's explicit preference
1200 hour => sub
1201 43 ▶ {
Subroutine __ANON__: called CC=17 SCAR=42.7
1202 43 ▶ if( !exists( $opts->{hourCycle} ) || !defined( $opts->{hourCycle} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"hourCycle"} and defined $opts->{"hourCycle"}) 0 43 43
Condition33%1/3
exists $opts->{"hourCycle"} and defined $opts->{"hourCycle"}
!ll&&!rl&&r
0043
MC/DC0%0/2
exists $opts->{"hourCycle"} and defined $opts->{"hourCycle"}
exists $opts->{"hourCycle"} defined $opts->{"hourCycle"}
Truth table33%1/3
A and B
A= exists $opts->{"hourCycle"}B= defined $opts->{"hourCycle"}
ABresult
0X0
100
111
1203 {
1204 0 my $pref = $unicode->time_format_preferred;
1205 0 ▶ if( $pref eq 'h' )
Branch: 3 branches
BranchTrueFalseTotal
if ($pref eq 'h') { } 0 0 0
elsif ($pref eq 'H') { } 0 0 0
elsif ($pref eq 'k') { } 0 0 0
1206 {
1207 0 $opts->{hourCycle} = 'h11';
1208 }
1209 elsif( $pref eq 'H' )
1210 {
1211 0 $opts->{hourCycle} = 'h23';
1212 }
1213 elsif( $pref eq 'k' )
1214 {
1215 0 $opts->{hourCycle} = 'h23';
1216 }
1217 }
1218 43 ▶ if( $opts->{hourCycle} eq 'h11' )
Branch: 4 branches
BranchTrueFalseTotal
if ($opts->{'hourCycle'} eq 'h11') { } 0 43 43
elsif ($opts->{'hourCycle'} eq 'h12' or $opts->{'hour12'}) { } 30 13 43
elsif ($opts->{'hourCycle'} eq 'h23') { } 1 12 13
elsif ($opts->{'hourCycle'} eq 'h24' or exists $opts->{'hour12'} and not $opts->{'hour12'}) { } 12 0 12
1219 {
1220 0 ▶ return( [ [qw( h H k K )] => $opts->{hour} eq '2-digit' ? 'KK' : 'K' ] );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'hour'} eq '2-digit' ? : 0 0 0
1221 }
1222 ▶ elsif( $opts->{hourCycle} eq 'h12' || $opts->{hour12} )
Condition66%2/3
$opts->{"hourCycle"} eq "h12" or $opts->{"hour12"}
l!l&&r!l&&!r
30013
MC/DC50%1/2
$opts->{"hourCycle"} eq "h12" or $opts->{"hour12"}
$opts->{"hourCycle"} eq "h12" $opts->{"hour12"}
Truth table66%2/3
A or B
A= $opts->{"hourCycle"} eq "h12"B= $opts->{"hour12"}
ABresult
1X1
011
000
1223 {
1224 30 ▶ return( [ [qw( h H k K )] => $opts->{hour} eq '2-digit' ? 'hh' : 'h' ] );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'hour'} eq '2-digit' ? : 14 16 30
1225 }
1226 elsif( $opts->{hourCycle} eq 'h23' )
1227 {
1228 1 ▶ return( [ [qw( h H k K )] => $opts->{hour} eq '2-digit' ? 'HH' : 'H' ] );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'hour'} eq '2-digit' ? : 1 0 1
1229 }
1230 ▶ elsif( $opts->{hourCycle} eq 'h24' || ( exists( $opts->{hour12} ) && !$opts->{hour12} ) )
Condition16%1/6
$opts->{"hourCycle"} eq "h24" or exists $opts->{"hour12"} and not $opts->{"hour12"}
l!l&&r!l&&!r
1200
exists $opts->{"hour12"} and not $opts->{"hour12"}
!ll&&!rl&&r
000
MC/DC0%0/3
$opts->{"hourCycle"} eq "h24" or exists $opts->{"hour12"} and not $opts->{"hour12"}
$opts->{"hourCycle"} eq "h24" exists $opts->{"hour12"} not $opts->{"hour12"}
Truth table25%1/4
A or B and not(C)
A= $opts->{"hourCycle"} eq "h24"B= exists $opts->{"hour12"}C= not $opts->{"hour12"}
ABCresult
1XX1
0111
00X0
0100
1231 {
1232 12 ▶ return( [ [qw( h H k K )] => $opts->{hour} eq '2-digit' ? 'kk' : 'k' ] );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'hour'} eq '2-digit' ? : 12 0 12
1233 }
1234 },
1235 minute => 'm',
1236 # NOTE: also: "Finally: If the requested skeleton included both seconds and fractional seconds and the dateFormatItem skeleton included seconds but not fractional seconds, then the seconds field of the corresponding pattern should be adjusted by appending the locale’s decimal separator, followed by the sequence of ‘S’ characters from the requested skeleton."
1237 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
1238 second => sub
1239 12 ▶ {
Subroutine __ANON__: called CC=8 SCAR=35.9
1240 12 ▶ my $seconds = ( $opts->{second} eq '2-digit' ? ( 's' x 2 ) : 's' );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'second'} eq '2-digit' ? : 12 0 12
1241 12 ▶ if( $opts->{second} && $opts->{fractionalSecondDigits} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'second'} and $opts->{'fractionalSecondDigits'}) { } 0 12 12
Condition33%1/3
$opts->{"second"} and $opts->{"fractionalSecondDigits"}
!ll&&!rl&&r
0120
MC/DC0%0/2
$opts->{"second"} and $opts->{"fractionalSecondDigits"}
$opts->{"second"} $opts->{"fractionalSecondDigits"}
Truth table33%1/3
A and B
A= $opts->{"second"}B= $opts->{"fractionalSecondDigits"}
ABresult
0X0
100
111
1242 {
1243 0 my @parts = split( /(?:'(?:(?:[^']|'')*)')/, $pattern );
1244 0 ▶ my $has_fractional_seconds = scalar( grep( /S/, @parts ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar grep(/S/, @parts) ? : 0 0 0
1245 0 ▶ if( $has_fractional_seconds )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_fractional_seconds) { } 0 0 0
1246 {
1247 0 return( [['s'] => $seconds] );
1248 }
1249 else
1250 {
1251 0 ▶ my $symbols = $unicode->number_symbols || die( $unicode->error );
Condition0%0/2
$unicode->number_symbols || die($unicode->error)
l!l
00
MC/DC0%0/1
$unicode->number_symbols || die($unicode->error)
$unicode->number_symbols
Truth table0%0/2
A
A= $unicode->number_symbols
Aresult
11
00
1252 0 ▶ my $sep = $symbols->{decimal} || '.';
Condition0%0/2
$symbols->{'decimal'} || '.'
l!l
00
MC/DC0%0/1
$symbols->{'decimal'} || '.'
$symbols->{'decimal'}
Truth table0%0/2
A
A= $symbols->{'decimal'}
Aresult
11
00
1253 0 return( [['s'] => $seconds . $sep . ( 'S' x $opts->{fractionalSecondDigits} )] );
1254 }
1255 }
1256 else
1257 {
1258 12 return( [['s'] => $seconds] );
1259 }
1260 },
1261 fractionalSecondDigits => sub
1262 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1263 return(['S', sub
1264 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1265 0 my( $token, $length ) = @_;
1266 # Remove fractional seconds if 0; we do not return undef; undef implies we leave the original string untouched
1267 0 ▶ return( '' ) if( $opts->{fractionalSecondDigits} == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"fractionalSecondDigits"} == 0 0 0 0
1268 0 return( 'S' x $opts->{fractionalSecondDigits} );
1269 0 }]);
1270 },
1271 weekday => sub
1272 10 ▶ {
Subroutine __ANON__: called CC=1 SCAR=2.3
1273 return([ [qw( c e E )], sub
1274 10 ▶ {
Subroutine __ANON__: called CC=8 SCAR=32.9
1275 10 my( $token, $length ) = @_;
1276 # If the pattern component found is 'c' or 'e', and is less or equal to 2 characters, we leave it untouched, because it would translate into the week day number, and we deal only with the week day name, and we do not want to interfere with the locale's preferred pattern
1277 10 ▶ if( $token eq 'E' || ( ( $token eq 'c' || $token eq 'e' ) && $length >= 3 ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($token eq 'E' or $token eq 'c' || $token eq 'e' and $length >= 3) { } 10 0 10
elsif ($token eq 'c' || $token eq 'e' and $length >= 3) { } 0 0 0
Condition44%4/9
$token eq "E" or $token eq "c" || $token eq "e" and $length >= 3
l!l&&r!l&&!r
640
$token eq "c" || $token eq "e" and $length >= 3
!ll&&!rl&&r
004
$token eq "c" or $token eq "e"
l!l&&r!l&&!r
400
MC/DC0%0/4
$token eq "E" or $token eq "c" || $token eq "e" and $length >= 3
$token eq "E" $token eq "c" $token eq "e" $length >= 3
Truth table33%2/6
A or B or C and D
A= $token eq "E"B= $token eq "c"C= $token eq "e"D= $length >= 3
ABCDresult
1XXX1
01X11
00111
000X0
01X00
00100
1278 {
1279 10 return( 'E' x $options_map->{type_to_length}->{ $opts->{weekday} } );
1280 }
1281 # The week day in word starts at 3 characters. Below that it is the week day as a number
1282 ▶ elsif( ( $token eq 'c' || $token eq 'e' ) && $length >= 3 )
Condition0%0/6
$token eq "c" || $token eq "e" and $length >= 3
!ll&&!rl&&r
000
$token eq "c" or $token eq "e"
l!l&&r!l&&!r
000
MC/DC0%0/3
$token eq "c" || $token eq "e" and $length >= 3
$token eq "c" $token eq "e" $length >= 3
Truth table0%0/5
A or B and C
A= $token eq "c"B= $token eq "e"C= $length >= 3
ABCresult
00X0
1X00
0100
1X11
0111
1283 {
1284 0 return( $token x ( $options_map->{weekday}->{ $opts->{weekday} } + 2 ) );
1285 }
1286 0 return;
1287 10 }]);
1288 },
1289 # Like for hours, the user preference takes precedence over the pattern component found in the locale's pattern
1290 timeZoneName => sub
1291 30 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
1292 30 return( [ [qw( O v V z Z )] => $options_map->{timezone}->{ $opts->{timeZoneName} } ] );
1293 },
1294 75 };
1295  
1296 75 foreach my $option ( sort( keys( %$opts ) ) )
1297 {
1298 571 ▶ if( exists( $component_to_match->{ $option } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $component_to_match->{$option}) { } 571 0 571
1299 {
1300 571 my $val = $component_to_match->{ $option };
1301 571 ▶ next if( !defined( $val ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 402 169 571
1302 169 ▶ if( ref( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) { } 123 46 169
1303 {
1304 123 ▶ if( ref( $val ) eq 'CODE' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'CODE') { } 123 0 123
elsif (ref $val eq 'HASH') { } 0 0 0
1305 {
1306 123 my $rv = $val->();
1307 # It returned an array reference.
1308 # The first part are the LDML pattern components applicable
1309 # The second part is how we deal with them when we find them: either we have a string, or a code reference to execute.
1310 123 ▶ if( ref( $rv ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $rv eq 'ARRAY') { } 95 28 123
elsif (ref $rv eq 'HASH') { } 28 0 28
1311 {
1312 # If the first element is an array, it is because there are multiple pattern components to catch
1313 # $rv->[1] can be a string, or a code for finer granularity
1314 95 ▶ if( ref( $rv->[0] ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $rv->[0] eq 'ARRAY') { } 95 0 95
elsif (ref $rv->[0]) { } 0 0 0
1315 {
1316 95 foreach my $comp ( @{$rv->[0]} )
1317 {
1318 364 $component_precision->{ $comp } = $rv->[1];
1319 }
1320 }
1321 # This should not be happening
1322 elsif( ref( $rv->[0] ) )
1323 {
1324 0 die( "The first array element returned for option \"${option}\" is a reference, and I do not know what to do with it: '", overload::StrVal( $rv->[0] ), "'" );
1325 }
1326 else
1327 {
1328 0 $component_precision->{ $rv->[0] } = $rv->[1];
1329 }
1330 }
1331 # It returns an hash reference of key-value pairs we add to the final hash
1332 elsif( ref( $rv ) eq 'HASH' )
1333 {
1334 28 my @keys = keys( %$rv );
1335 # Add the given hash keys to our option to pattern component hash reference
1336 28 @$component_precision{ @keys } = @$rv{ @keys };
1337 }
1338 else
1339 {
1340 0 die( "Unsupported value of type '" . ref( $rv ) . "' returned from code reference execution for option \"${option}\"." );
1341 }
1342 }
1343 elsif( ref( $val ) eq 'HASH' )
1344 {
1345 0 my @keys = keys( %$val );
1346 }
1347 else
1348 {
1349 0 die( "Unsupported value '", overload::StrVal( $val ), "' returned for option \"${option}\"." );
1350 }
1351 }
1352 else
1353 {
1354 46 ▶ $component_precision->{ $val } = ( $opts->{ $option } eq '2-digit' ? ( $val x 2 ) : $val );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{$option} eq '2-digit' ? : 38 8 46
1355 }
1356 }
1357 else
1358 {
1359 0 die( "Missing the option \"${option}\" in our configuration!" );
1360 }
1361 }
1362  
1363 # "When the pattern field corresponds to an availableFormats skeleton with a field length that matches the field length in the requested skeleton, the pattern field length should not be adjusted. This permits locale data to override a requested field length"
1364 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
1365 # We need the following to perform this LDML check.
1366 # Character to length. For example: M => 3
1367 75 my $request_len = {};
1368 75 my $pattern_len = {};
1369 75 my $request_tokens = $request_object->tokens;
1370 75 foreach my $def ( @$request_tokens )
1371 {
1372 169 $request_len->{ $def->{component} } = $def->{len};
1373 }
1374 75 ▶ if( defined( $pattern_object ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pattern_object) 75 0 75
1375 {
1376 75 my $pattern_tokens = $pattern_object->skeleton_tokens;
1377 75 foreach my $def ( @$pattern_tokens )
1378 {
1379 166 $pattern_len->{ $def->{component} } = $def->{len};
1380 }
1381 }
1382 # TODO: An additional rule stipulates that:
1383 # "Pattern field lengths for hour, minute, and second should by default not be adjusted to match the requested field length (i.e. locale data takes priority)."
1384 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
1385 # However, I am pondering whether to implement it or not.
1386  
1387 75 $pattern =~ s{
1388 \G
1389 (?:
1390 '((?:[^']|'')*)' # quote escaped bit of text
1391 # it needs to end with one
1392 # quote not followed by
1393 # another
1394 |
1395 (([a-zA-Z])\3*) # could be a pattern
1396 |
1397 (.) # anything else
1398 )
1399 }
1400 {
1401 330 ▶ if( defined( $1 ) )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $1) { } 0 330 330
elsif (defined $2) { } 199 131 330
elsif (defined $4) { } 131 0 131
1402 {
1403 0 "'" . $1 . "'";
1404 }
1405 elsif( defined( $2 ) )
1406 {
1407 199 my $token = $2;
1408 199 my $component = $3;
1409 199 ▶ if( exists( $component_precision->{ $component } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $component_precision->{$component}) { } 169 30 199
1410 {
1411 # either a string or a code reference
1412 169 my $this = $component_precision->{ $component };
1413 # "adjustments should never convert a numeric element in the pattern to an alphabetic element, or the opposite."
1414 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
1415 # For example: skeleton 'yMMM' and pattern actually is 'y年M月'
1416 # This allows the locale to override
1417 # The above rule only materialise for the 'month' option, so we check for it here:
1418 169 ▶ if( ( $component eq 'L' || $component eq 'M' ) &&
Branch: 4 branches
BranchTrueFalseTotal
if ($component eq 'L' || $component eq 'M' and length $token <= 2 and $opts->{'month'} ne 'numeric' and $opts->{'month'} ne '2-digit') { } 0 169 169
elsif (exists $pattern_len->{$component} and exists $request_len->{$component} and $pattern_len->{$component} == $request_len->{$component}) { } 29 140 169
elsif (ref $this eq 'CODE') { } 10 130 140
elsif (ref $this) { } 0 130 130
Condition75%9/12
$component eq "L" || $component eq "M" and length $token <= 2 and $opts->{"month"} ne "numeric" and $opts->{"month"} ne "2-digit"
!ll&&!rl&&r
16900
$component eq "L" || $component eq "M" and length $token <= 2 and $opts->{"month"} ne "numeric"
!ll&&!rl&&r
16270
$component eq "L" || $component eq "M" and length $token <= 2
!ll&&!rl&&r
141217
$component eq "L" or $component eq "M"
l!l&&r!l&&!r
208141
MC/DC0%0/5
$component eq "L" || $component eq "M" and length $token <= 2 and $opts->{"month"} ne "numeric" and $opts->{"month"} ne "2-digit"
$component eq "L" $component eq "M" length $token <= 2 $opts->{"month"} ne "numeric" $opts->{"month"} ne "2-digit"
Truth table44%4/9
A or B and C and D and E
A= $component eq "L"B= $component eq "M"C= length $token <= 2D= $opts->{"month"} ne "numeric"E= $opts->{"month"} ne "2-digit"
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
1419 length( $token ) <= 2 &&
1420 $opts->{month} ne 'numeric' &&
1421 $opts->{month} ne '2-digit' )
1422 {
1423 0 $token;
1424 }
1425 ▶ elsif( exists( $pattern_len->{ $component } ) &&
Condition100%6/6
exists $pattern_len->{$component} and exists $request_len->{$component} and $pattern_len->{$component} == $request_len->{$component}
!ll&&!rl&&r
578329
exists $pattern_len->{$component} and exists $request_len->{$component}
!ll&&!rl&&r
2730112
MC/DC100%3/3
exists $pattern_len->{$component} and exists $request_len->{$component} and $pattern_len->{$component} == $request_len->{$component}
exists $pattern_len->{$component} exists $request_len->{$component} $pattern_len->{$component} == $request_len->{$component}
Truth table100%4/4
A and B and C
A= exists $pattern_len->{$component}B= exists $request_len->{$component}C= $pattern_len->{$component} == $request_len->{$component}
ABCresult
0XX0
10X0
1100
1111
1426 exists( $request_len->{ $component } ) &&
1427 $pattern_len->{ $component } == $request_len->{ $component } )
1428 {
1429 29 $token;
1430 }
1431 elsif( ref( $this ) eq 'CODE' )
1432 {
1433 10 my $rv = $this->( $component, length( $token ) );
1434 # If the result is undefined, we leave the original untouched
1435 10 ▶ defined( $rv ) ? $rv : $token;
Branch: 1 branch
BranchTrueFalseTotal
defined $rv ? : 10 0 10
1436 }
1437 elsif( ref( $this ) )
1438 {
1439 0 die( "The value returned for token \"${token}\" is a reference, but I do not know what to do with it: '", overload::StrVal( $this ), "'" );
1440 }
1441 else
1442 {
1443 130 $this;
1444 }
1445 }
1446 # we leave it untouched
1447 else
1448 {
1449 30 $token;
1450 }
1451 }
1452 elsif( defined( $4 ) )
1453 {
1454 131 $4;
1455 }
1456 # Should not get here
1457 else
1458 {
1459 0 undef;
1460 }
1461 }sgex;
1462  
1463 75 return( $pattern );
1464 }
1465  
1466 sub _append_components
1467 3 ▶{
Subroutine _append_components: called CC=19 SCAR=40.8
1468 3 my $self = shift( @_ );
1469 3 my $args = $self->_get_args_as_hash( @_ );
1470 3 ▶ my $pattern = $args->{pattern} || die( "No format pattern was provided." );
Condition50%1/2
$args->{'pattern'} || die('No format pattern was provided.')
l!l
30
MC/DC0%0/1
$args->{'pattern'} || die('No format pattern was provided.')
$args->{'pattern'}
Truth table50%1/2
A
A= $args->{'pattern'}
Aresult
11
00
1471 3 ▶ my $missing = $args->{missing} || die( "No array reference of missing components was provided." );
Condition50%1/2
$args->{'missing'} || die('No array reference of missing components was provided.')
l!l
30
MC/DC0%0/1
$args->{'missing'} || die('No array reference of missing components was provided.')
$args->{'missing'}
Truth table50%1/2
A
A= $args->{'missing'}
Aresult
11
00
1472 # Possible values: wide (Monday), abbreviated (Mon), short (Mo) and narrow (M)
1473 # my $width = $args->{width} || die( "No width value provided." );
1474 3 ▶ if( ref( $pattern ) && !overload::Method( $pattern => '""' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $pattern and not overload::Method($pattern, '""')) { } 0 3 3
elsif (ref $missing ne 'ARRAY') { } 0 3 3
Condition33%1/3
ref $pattern and not overload::Method($pattern, "\"\"")
!ll&&!rl&&r
300
MC/DC0%0/2
ref $pattern and not overload::Method($pattern, "\"\"")
ref $pattern not overload::Method($pattern, "\"\"")
Truth table33%1/3
A and not(B)
A= ref $patternB= not overload::Method($pattern, "\"\"")
ABresult
0X0
100
111
1475 {
1476 0 die( "The pattern value provided (", overload::StrVal( $pattern ), ") is a reference (", ref( $pattern ), "), but it does not stringify." );
1477 }
1478 elsif( ref( $missing ) ne 'ARRAY' )
1479 {
1480 0 die( "The value provided for missing components (", overload::StrVal( $missing ), ") is not an array reference." );
1481 }
1482 3 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone." );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
l!l
30
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
1483 3 ▶ my $locale = $self->{locale} || die( "The locale value is gone!" );
Condition50%1/2
$self->{'locale'} || die('The locale value is gone!')
l!l
30
MC/DC0%0/1
$self->{'locale'} || die('The locale value is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
1484 3 ▶ my $calendar = $self->{calendar} || 'gregorian';
Condition50%1/2
$self->{'calendar'} || 'gregorian'
l!l
03
MC/DC0%0/1
$self->{'calendar'} || 'gregorian'
$self->{'calendar'}
Truth table50%1/2
A
A= $self->{'calendar'}
Aresult
11
00
1485 3 my $alias =
1486 {
1487 'c' => 'E',
1488 'e' => 'E',
1489 'H' => 'h',
1490 'k' => 'h',
1491 'K' => 'h',
1492 'L' => 'M',
1493 'v' => 'Z',
1494 };
1495 3 ▶ my $missing_hash = +{ map{ ( $alias->{ $_ } // $_ ) => $_ } @$missing };
Condition33%1/3
$alias->{$_} // $_
l!l&&r!l&&!r
030
MC/DC0%0/2
$alias->{$_} // $_
$alias->{$_} $_
Truth table33%1/3
A // B
A= $alias->{$_}B= $_
ABresult
1X1
011
000
1496  
1497 # my @ordered_options = qw( era year month weekday day dayPeriod hour minute second timeZoneName );
1498 # becomes:
1499 3 my @ordered_options = qw( G y M E d B h m s Z );
1500 # Possible components found in skeleton in CLDR data: [qw( B E G H M Q W Z c d h m s v w y )]
1501 # All possible format ID known in the CLDR calendar_append_formats table
1502 3 my $map =
1503 {
1504 # 'B' has no correspondence in table calendar_append_formats, but has in table date_terms
1505 'c' => ['Day-Of-Week' => 'weekday'],
1506 'd' => ['Day' => 'day'],
1507 'e' => ['Day-Of-Week' => 'weekday'],
1508 'E' => ['Day-Of-Week' => 'weekday'],
1509 'G' => ['Era' => 'era'],
1510 'h' => ['Hour' => 'hour'],
1511 'H' => ['Hour' => 'hour'],
1512 'k' => ['Hour' => 'hour'],
1513 'K' => ['Hour' => 'hour'],
1514 'L' => ['Month' => 'month'],
1515 'm' => ['Minute' => 'minute'],
1516 'M' => ['Month' => 'month'],
1517 # We put it here, but it is actually not used
1518 'Q' => ['Quarter' => 'quarter'],
1519 's' => ['Second' => 'second'],
1520 'v' => ['Timezone' => 'zone'],
1521 # We put it here, but it is actually not used
1522 'w' => ['Week' => 'week'],
1523 'W' => ['Week' => 'week'],
1524 'y' => ['Year' => 'year'],
1525 'Z' => ['Timezone' => 'zone'],
1526 };
1527 3 ▶ my $tree = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
30
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
1528 return( $self->pass_error( $cldr->error ) );
1529 my $get_append_pattern = sub
1530 3 ▶ {
Subroutine __ANON__: called CC=6 SCAR=19.1
1531 3 my $elem = shift( @_ );
1532 # e.g.: {0} {1}
1533 # or: {0} ({2}: {1})
1534 3 my $pat;
1535 3 foreach my $loc ( @$tree )
1536 {
1537 3 my $ref = $cldr->calendar_append_format(
1538 format_id => $elem,
1539 locale => $loc,
1540 calendar => $calendar,
1541 );
1542 3 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $ref ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $cldr->error 0 3 3
Condition33%1/3
not defined $ref and $cldr->error
!ll&&!rl&&r
300
MC/DC0%0/2
not defined $ref and $cldr->error
not defined $ref $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $refB= $cldr->error
ABresult
0X0
100
111
1543 3 ▶ if( $ref )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 3 0 3
1544 {
1545 3 $pat = $ref->{format_pattern};
1546 3 last;
1547 }
1548 }
1549 3 ▶ return( $pat // '' );
Condition50%1/2
$pat // ""
l!l
30
MC/DC0%0/1
$pat // ""
$pat
Truth table50%1/2
A
A= $pat
Aresult
11
00
1550 3 };
1551 # day
1552 # dayperiod
1553 # month
1554 # quarter
1555 my $get_term = sub
1556 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
1557 0 my $elem = shift( @_ );
1558 0 my $str;
1559 0 foreach my $loc ( @$tree )
1560 {
1561 0 my $ref = $cldr->date_term(
1562 locale => $loc,
1563 term_type => $elem,
1564 # Possible choices are 'standard' and 'narrow', but 'narrow' is relatively rare (11.70%).
1565 term_length => 'standard',
1566 );
1567 0 ▶ return( $self->pass_error( $cldr->error ) ) if( !defined( $ref ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $cldr->error 0 0 0
Condition0%0/3
not defined $ref and $cldr->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $cldr->error
not defined $ref $cldr->error
Truth table0%0/3
not(A) and B
A= not defined $refB= $cldr->error
ABresult
0X0
100
111
1568 0 ▶ if( $ref )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 0 0 0
1569 {
1570 0 $str = $ref->{display_name};
1571 0 last;
1572 }
1573 }
1574 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
1575 3 };
1576  
1577 3 local $" = ', ';
1578 3 foreach my $comp ( @ordered_options )
1579 {
1580 30 ▶ next unless( exists( $missing_hash->{ $comp } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $missing_hash->{$comp} 27 3 30
1581 3 ▶ if( !exists( $map->{ $comp } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $map->{$comp}) 0 3 3
1582 {
1583 0 warn( "Unsupported component (${comp}) requested." );
1584 }
1585 3 my $def = $map->{ $comp };
1586 3 my $format = $get_append_pattern->( $def->[0] );
1587 3 ▶ if( !defined( $format ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $format) { } 0 3 3
elsif (not length $format) { } 0 3 3
1588 {
1589 0 return( $self->pass_error );
1590 }
1591 elsif( !length( $format ) )
1592 {
1593 0 return( $self->error( "Unable to find an append format pattern for component '${comp}' corresponding to append item '", $def->[0], "' for the locale tree @$tree" ) );
1594 }
1595 3 $format =~ s/\{0\}/$pattern/;
1596 3 $format =~ s/\{1\}/$missing_hash->{ $comp }/;
1597 3 ▶ if( index( $format, '{2}' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($format, "{2}") != -1) 0 3 3
1598 {
1599 0 my $term = $get_term->( $def->[1] );
1600 0 ▶ if( !defined( $term ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $term) { } 0 0 0
elsif (not length $term) { } 0 0 0
1601 {
1602 0 return( $self->pass_error );
1603 }
1604 elsif( !length( $term ) )
1605 {
1606 0 return( $self->error( "Unable to find a date term for element '", $def->[1], "' for the locale tree @$tree" ) );
1607 }
1608 # Since this is a litteral term, we need to surround it with single quote.
1609 0 $format =~ s/\{2\}/\'$term\'/;
1610 }
1611 3 $pattern = $format;
1612 }
1613 3 return( $pattern );
1614 }
1615  
1616 sub _cldr
1617 552 ▶{
Subroutine _cldr: called CC=4 SCAR=14.0
1618 552 my $self = shift( @_ );
1619 552 my $cldr;
1620 552 ▶ if( ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 551 1 552
1621 {
1622 $cldr = $self->{_cldr} ||
1623 551 ▶ return( $self->error( "The Locale::Unicode::Data object is gone!" ) );
Condition50%1/2
$self->{'_cldr'} || (return $self->error('The Locale::Unicode::Data object is gone!'))
l!l
5510
MC/DC0%0/1
$self->{'_cldr'} || (return $self->error('The Locale::Unicode::Data object is gone!'))
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
1624 }
1625 else
1626 {
1627 1 ▶ $cldr = Locale::Unicode::Data->new ||
Condition50%1/2
'Locale::Unicode::Data'->new || (return $self->pass_error('Locale::Unicode::Data'->error))
l!l
10
MC/DC0%0/1
'Locale::Unicode::Data'->new || (return $self->pass_error('Locale::Unicode::Data'->error))
'Locale::Unicode::Data'->new
Truth table50%1/2
A
A= 'Locale::Unicode::Data'->new
Aresult
11
00
1628 return( $self->pass_error( Locale::Unicode::Data->error ) );
1629 }
1630 552 return( $cldr );
1631 }
1632  
1633 sub _clear_cache
1634 662 ▶{
Subroutine _clear_cache: called CC=3 SCAR=14.2
1635 662 my $self = shift( @_ );
1636 662 my $current_time = time();
1637 662 ▶ if( $current_time - $LAST_CACHE_CLEAR > 86400 || keys( %$CACHE ) > $MAX_CACHE_SIZE )
Branch: 1 branch
BranchTrueFalseTotal
if ($current_time - $DateTime::Format::Intl::LAST_CACHE_CLEAR > 86400 or keys %$DateTime::Format::Intl::CACHE > $DateTime::Format::Intl::MAX_CACHE_SIZE) 0 662 662
Condition33%1/3
$current_time - $DateTime::Format::Intl::LAST_CACHE_CLEAR > 86400 or keys %$DateTime::Format::Intl::CACHE > $DateTime::Format::Intl::MAX_CACHE_SIZE
l!l&&r!l&&!r
00662
MC/DC0%0/2
$current_time - $DateTime::Format::Intl::LAST_CACHE_CLEAR > 86400 or keys %$DateTime::Format::Intl::CACHE > $DateTime::Format::Intl::MAX_CACHE_SIZE
$current_time - $DateTime::Format::Intl::LAST_CACHE_CLEAR > 86400 keys %$DateTime::Format::Intl::CACHE > $DateTime::Format::Intl::MAX_CACHE_SIZE
Truth table33%1/3
A or B
A= $current_time - $DateTime::Format::Intl::LAST_CACHE_CLEAR > 86400B= keys %$DateTime::Format::Intl::CACHE > $DateTime::Format::Intl::MAX_CACHE_SIZE
ABresult
1X1
011
000
1638 {
1639 0 %$CACHE = ();
1640 0 $LAST_CACHE_CLEAR = $current_time;
1641 }
1642 }
1643  
1644 # Takes a pattern, break it down into pieces of information as an hash reference and return an array of those hash references
1645 sub _format_to_parts
1646 317 ▶{
Subroutine _format_to_parts: called CC=12 SCAR=44.8
1647 317 my $self = shift( @_ );
1648 317 my $args = $self->_get_args_as_hash( @_ );
1649 317 ▶ my $pat = $args->{pattern} || die( "No pattern was provided." );
Condition50%1/2
$args->{'pattern'} || die('No pattern was provided.')
l!l
3170
MC/DC0%0/1
$args->{'pattern'} || die('No pattern was provided.')
$args->{'pattern'}
Truth table50%1/2
A
A= $args->{'pattern'}
Aresult
11
00
1650 317 ▶ my $dt = $args->{datetime} || die( "No DateTime or DateTime::Lite object was provided." );
Condition50%1/2
$args->{'datetime'} || die('No DateTime or DateTime::Lite object was provided.')
l!l
3170
MC/DC0%0/1
$args->{'datetime'} || die('No DateTime or DateTime::Lite object was provided.')
$args->{'datetime'}
Truth table50%1/2
A
A= $args->{'datetime'}
Aresult
11
00
1651 317 ▶ my $locale = $self->{locale} || die( "Our Locale::Unicode object is gone!" );
Condition50%1/2
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
l!l
3170
MC/DC0%0/1
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
1652 317 my $opts = $self->resolvedOptions;
1653 317 ▶ unless( $opts->{numberingSystem} eq 'latn' )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"numberingSystem"} eq "latn") 0 317 317
1654 {
1655 0 ▶ my $clone = Locale::Intl->new( "$locale" ) ||
Condition0%0/2
'Locale::Intl'->new("$locale") || (return $self->pass_error('Locale::Intl'->error))
l!l
00
MC/DC0%0/1
'Locale::Intl'->new("$locale") || (return $self->pass_error('Locale::Intl'->error))
'Locale::Intl'->new("$locale")
Truth table0%0/2
A
A= 'Locale::Intl'->new("$locale")
Aresult
11
00
1656 return( $self->pass_error( Locale::Intl->error ) );
1657 0 $clone->number( $opts->{numberingSystem} );
1658 0 $locale = $clone;
1659 }
1660 317 ▶ my $fmt = DateTime::Format::Unicode->new( locale => $locale, time_zone => $opts->{timeZone} ) ||
Condition50%1/2
'DateTime::Format::Unicode'->new('locale', $locale, 'time_zone', $opts->{'timeZone'}) || (return $self->pass_error('DateTime::Format::Unicode'->error))
l!l
0317
MC/DC0%0/1
'DateTime::Format::Unicode'->new('locale', $locale, 'time_zone', $opts->{'timeZone'}) || (return $self->pass_error('DateTime::Format::Unicode'->error))
'DateTime::Format::Unicode'->new('locale', $locale, 'time_zone', $opts->{'timeZone'})
Truth table50%1/2
A
A= 'DateTime::Format::Unicode'->new('locale', $locale, 'time_zone', $opts->{'timeZone'})
Aresult
11
00
1661 return( $self->pass_error( DateTime::Format::Unicode->error ) );
1662 0 ▶ my $map = $fmt->_get_helper_methods ||
Condition0%0/2
$fmt->_get_helper_methods || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$fmt->_get_helper_methods || (return $self->pass_error)
$fmt->_get_helper_methods
Truth table0%0/2
A
A= $fmt->_get_helper_methods
Aresult
11
00
1663 return( $self->pass_error );
1664 0 my $comp_map =
1665 {
1666 'a' => 'dayPeriod',
1667 # Non-standard
1668 'A' => 'millisecond',
1669 'b' => 'dayPeriod',
1670 'B' => 'dayPeriod',
1671 'c' => 'weekday',
1672 'C' => 'hour',
1673 'd' => 'day',
1674 # Non-standard
1675 'D' => 'dayOfYear',
1676 'e' => 'weekday',
1677 'E' => 'weekday',
1678 # Non-standard
1679 'F' => 'dayOfWeekMonth',
1680 'g' => 'day',
1681 'G' => 'era',
1682 'h' => 'hour',
1683 'H' => 'hour',
1684 'j' => 'hour',
1685 'J' => 'hour',
1686 'k' => 'hour',
1687 'K' => 'hour',
1688 'L' => 'month',
1689 'M' => 'month',
1690 'm' => 'minute',
1691 'O' => 'timeZoneName',
1692 'q' => 'quarter',
1693 'Q' => 'quarter',
1694 'r' => 'year',
1695 's' => 'second',
1696 'S' => 'secondFractional',
1697 'u' => 'year',
1698 # Non-standard
1699 'U' => 'cyclicYear',
1700 'v' => 'timeZoneName',
1701 'V' => 'timeZoneName',
1702 'w' => 'week',
1703 'W' => 'week',
1704 'x' => 'timeZoneName',
1705 'X' => 'timeZoneName',
1706 'y' => 'year',
1707 'Y' => 'year',
1708 'z' => 'timeZoneName',
1709 'Z' => 'timeZoneName',
1710 };
1711  
1712 my $unescape = sub
1713 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1714 0 my $str = shift( @_ );
1715 0 $str =~ s/\'\'/\'/g;
1716 0 return( $str );
1717 0 };
1718  
1719 my $cldr_pattern = sub
1720 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1721 0 my $pattern = shift( @_ );
1722 0 my $component = substr( $pattern, 0, 1 );
1723 0 ▶ if( exists( $map->{ $component } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map->{$component}) { } 0 0 0
1724 {
1725 0 ▶ die( "Unknown component '${component}' in our component to type map." ) if( !exists( $comp_map->{ $component } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $comp_map->{$component} 0 0 0
1726 0 my $code = $map->{ $component };
1727 0 my $str = $code->( $fmt, $component, length( $pattern ), $dt );
1728 return({
1729 0 ▶ type => $comp_map->{ $component },
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
1730 value => ( $str // '' ),
1731 });
1732 }
1733 # Unknown, we return the pattern as-is
1734 else
1735 {
1736 return({
1737 0 type => 'literal',
1738 value => $unescape->( $pattern ),
1739 });
1740 }
1741 0 };
1742  
1743 0 my $parts = [];
1744 # try-catch
1745 eval
1746 0 {
1747 0 $pat =~ s{
1748 \G
1749 (?:
1750 '((?:[^']|'')*)' # quote escaped bit of text
1751 # it needs to end with one
1752 # quote not followed by
1753 # another
1754 |
1755 (([a-zA-Z])\3*) # could be a pattern
1756 |
1757 (.) # anything else
1758 )
1759 }
1760 {
1761 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
1762 {
1763 0 push( @$parts, { value => $unescape->( $1 ), type => 'literal' });
1764 0 $1;
1765 }
1766 elsif( defined( $2 ) )
1767 {
1768 0 push( @$parts, $cldr_pattern->( $2 ) );
1769 0 $2;
1770 }
1771 elsif( defined( $4 ) )
1772 {
1773 0 push( @$parts, { value => $unescape->( $4 ), type => 'literal' });
1774 0 $4;
1775 }
1776 else
1777 {
1778 0 undef;
1779 }
1780 }sgex;
1781 };
1782 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1783 {
1784 0 return( $self->error( "Error formatting CLDR pattern for locale $locale: $@" ) );
1785 }
1786 0 return( $parts );
1787 }
1788  
1789 sub _get_args_as_hash
1790 30896 ▶{
Subroutine _get_args_as_hash: called CC=6 SCAR=19.0
1791 30896 my $self = shift( @_ );
1792 30896 my $ref = {};
1793 30896 ▶ if( scalar( @_ ) == 1 &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and (ref $_[0] || '') eq 'HASH') { } 436 30460 30896
elsif (not scalar(@_) % 2) { } 30460 0 30460
Condition62%5/8
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
!ll&&!rl&&r
304600436
scalar @_ == 1 and defined $_[0]
!ll&&!rl&&r
304600436
ref $_[0] || ''
l!l
4360
MC/DC33%1/3
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
scalar @_ == 1 defined $_[0] ref $_[0]
Truth table50%2/4
A and B and C
A= scalar @_ == 1B= defined $_[0]C= ref $_[0]
ABCresult
0XX0
10X0
1100
1111
1794 defined( $_[0] ) &&
1795 ( ref( $_[0] ) || '' ) eq 'HASH' )
1796 {
1797 436 $ref = shift( @_ );
1798 }
1799 elsif( !( scalar( @_ ) % 2 ) )
1800 {
1801 30460 $ref = { @_ };
1802 }
1803 else
1804 {
1805 0 die( "Uneven number of parameters provided." );
1806 }
1807 30896 return( $ref );
1808 }
1809  
1810 sub _get_available_format_patterns
1811 295 ▶{
Subroutine _get_available_format_patterns: called CC=12 SCAR=26.3
1812 295 my $self = shift( @_ );
1813 295 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone." );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
l!l
2950
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
1814 295 ▶ my $locale = $self->{locale} || die( "The locale value is gone!" );
Condition50%1/2
$self->{'locale'} || die('The locale value is gone!')
l!l
2950
MC/DC0%0/1
$self->{'locale'} || die('The locale value is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
1815 295 ▶ my $calendar = $self->{calendar} || 'gregorian';
Condition50%1/2
$self->{'calendar'} || 'gregorian'
l!l
0295
MC/DC0%0/1
$self->{'calendar'} || 'gregorian'
$self->{'calendar'}
Truth table50%1/2
A
A= $self->{'calendar'}
Aresult
11
00
1816 # "The dateFormatItems inherit from their parent locale, so the inherited items need to be considered when processing."
1817 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Mapping_Requested_Time_Skeletons_To_Patterns>
1818 295 ▶ my $tree = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
2950
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
1819 return( $self->pass_error( $cldr->error ) );
1820 # Keep track of the format skeleton already found, so we do not replace them while going up the tree
1821 295 my $patterns = {};
1822 295 local $" = ', ';
1823 295 foreach my $loc ( @$tree )
1824 {
1825 598 my $all = $cldr->calendar_available_formats(
1826 locale => $loc,
1827 calendar => $calendar,
1828 alt => undef,
1829 # count might contain some value
1830 );
1831 598 ▶ return( $self->pass_error ) if( !defined( $all ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $all and $cldr->error 0 598 598
Condition33%1/3
not defined $all and $cldr->error
!ll&&!rl&&r
59800
MC/DC0%0/2
not defined $all and $cldr->error
not defined $all $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $allB= $cldr->error
ABresult
0X0
100
111
1832 598 ▶ if( $all && scalar( @$all ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($all and scalar @$all) 591 7 598
Condition50%1/2
$all and scalar @$all
!ll
0598
MC/DC0%0/1
$all and scalar @$all
$all
Truth table50%1/2
A
A= $all
Aresult
00
11
1833 {
1834 591 for( @$all )
1835 {
1836 39155 ▶ next if( exists( $patterns->{ $_->{format_id} } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $$patterns{$_->{"format_id"}} 17356 21799 39155
1837 21799 $patterns->{ $_->{format_id} } = $_->{format_pattern};
1838 }
1839 # We do not stop here even though we may have a match, because we want to collect all the possible pattern throughout the locale's tree.
1840 }
1841 }
1842 295 return( $patterns );
1843 }
1844  
1845 sub _get_available_interval_patterns
1846 216 ▶{
Subroutine _get_available_interval_patterns: called CC=11 SCAR=25.2
1847 216 my $self = shift( @_ );
1848 216 ▶ my $diff = shift( @_ ) || die( "No greatest difference component was provided." );
Condition50%1/2
shift @_ || die('No greatest difference component was provided.')
l!l
2160
MC/DC0%0/1
shift @_ || die('No greatest difference component was provided.')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1849 216 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone." );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
l!l
2160
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
1850 216 ▶ my $locale = $self->{locale} || die( "The locale value is gone!" );
Condition50%1/2
$self->{'locale'} || die('The locale value is gone!')
l!l
2160
MC/DC0%0/1
$self->{'locale'} || die('The locale value is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
1851 216 ▶ my $calendar = $self->{calendar} || 'gregorian';
Condition50%1/2
$self->{'calendar'} || 'gregorian'
l!l
0216
MC/DC0%0/1
$self->{'calendar'} || 'gregorian'
$self->{'calendar'}
Truth table50%1/2
A
A= $self->{'calendar'}
Aresult
11
00
1852 # Get all the interval patterns for the given greatest difference
1853 # "The dateFormatItems inherit from their parent locale, so the inherited items need to be considered when processing."
1854 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Mapping_Requested_Time_Skeletons_To_Patterns>
1855 216 ▶ my $tree = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
2160
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
1856 return( $self->pass_error( $cldr->error ) );
1857 216 my $patterns = {};
1858 216 local $" = ', ';
1859 216 foreach my $loc ( @$tree )
1860 {
1861 432 my $all = $cldr->calendar_interval_formats(
1862 locale => $loc,
1863 calendar => $calendar,
1864 greatest_diff_id => $diff,
1865 );
1866 432 ▶ if( $all && scalar( @$all ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($all and scalar @$all) 432 0 432
Condition50%1/2
$all and scalar @$all
!ll
0432
MC/DC0%0/1
$all and scalar @$all
$all
Truth table50%1/2
A
A= $all
Aresult
00
11
1867 {
1868 432 for( @$all )
1869 {
1870 5526 ▶ next if( exists( $patterns->{ $_->{format_id} } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $$patterns{$_->{"format_id"}} 2763 2763 5526
1871 2763 $patterns->{ $_->{format_id} } = $_;
1872 }
1873 # We do not stop here even though we may have a match, because we want to collect all the possible pattern throughout the locale's tree.
1874 }
1875 }
1876 216 return( $patterns );
1877 }
1878  
1879 sub _get_cached_pattern
1880 662 ▶{
Subroutine _get_cached_pattern: called CC=4 SCAR=13.9
1881 662 my $self = shift( @_ );
1882 662 my( $locale, $key ) = @_;
1883 662 $self->_clear_cache;
1884 662 ▶ if( exists( $CACHE->{ $locale } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DateTime::Format::Intl::CACHE->{$locale} and ref $DateTime::Format::Intl::CACHE->{$locale} eq "HASH" and exists $DateTime::Format::Intl::CACHE->{$locale}{$key}) 149 513 662
Condition83%5/6
exists $DateTime::Format::Intl::CACHE->{$locale} and ref $DateTime::Format::Intl::CACHE->{$locale} eq "HASH" and exists $DateTime::Format::Intl::CACHE->{$locale}{$key}
!ll&&!rl&&r
14499149
exists $DateTime::Format::Intl::CACHE->{$locale} and ref $DateTime::Format::Intl::CACHE->{$locale} eq "HASH"
!ll&&!rl&&r
140648
MC/DC66%2/3
exists $DateTime::Format::Intl::CACHE->{$locale} and ref $DateTime::Format::Intl::CACHE->{$locale} eq "HASH" and exists $DateTime::Format::Intl::CACHE->{$locale}{$key}
exists $DateTime::Format::Intl::CACHE->{$locale} ref $DateTime::Format::Intl::CACHE->{$locale} eq "HASH" exists $DateTime::Format::Intl::CACHE->{$locale}{$key}
Truth table75%3/4
A and B and C
A= exists $DateTime::Format::Intl::CACHE->{$locale}B= ref $DateTime::Format::Intl::CACHE->{$locale} eq "HASH"C= exists $DateTime::Format::Intl::CACHE->{$locale}{$key}
ABCresult
0XX0
10X0
1100
1111
1885 ref( $CACHE->{ $locale } ) eq 'HASH' &&
1886 exists( $CACHE->{ $locale }->{ $key } ) )
1887 {
1888 149 return( $CACHE->{ $locale }->{ $key } );
1889 }
1890 513 return;
1891 }
1892  
1893 sub _get_datetime_format
1894 20 ▶{
Subroutine _get_datetime_format: called CC=15 SCAR=32.0
1895 20 my $self = shift( @_ );
1896 20 my $opts = $self->_get_args_as_hash( @_ );
1897 20 ▶ my $width = $opts->{width} || die( "No datetime format width was provided." );
Condition50%1/2
$opts->{'width'} || die('No datetime format width was provided.')
l!l
200
MC/DC0%0/1
$opts->{'width'} || die('No datetime format width was provided.')
$opts->{'width'}
Truth table50%1/2
A
A= $opts->{'width'}
Aresult
11
00
1898 20 ▶ my $type = $opts->{type} || 'atTime';
Condition50%1/2
$opts->{'type'} || 'atTime'
l!l
020
MC/DC0%0/1
$opts->{'type'} || 'atTime'
$opts->{'type'}
Truth table50%1/2
A
A= $opts->{'type'}
Aresult
11
00
1899 20 ▶ die( "Bad datetime format '${type}'" ) if( $type ne 'atTime' && $type ne 'standard' );
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "atTime" and $type ne "standard" 0 20 20
Condition33%1/3
$type ne "atTime" and $type ne "standard"
!ll&&!rl&&r
2000
MC/DC0%0/2
$type ne "atTime" and $type ne "standard"
$type ne "atTime" $type ne "standard"
Truth table33%1/3
A and B
A= $type ne "atTime"B= $type ne "standard"
ABresult
0X0
100
111
1900 20 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone." );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
l!l
200
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone.')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
1901 20 ▶ my $locale = $self->{locale} || die( "Our Locale::Unicode object is gone!" );
Condition50%1/2
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
l!l
200
MC/DC0%0/1
$self->{'locale'} || die('Our Locale::Unicode object is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
1902 20 ▶ my $locales = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
200
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
1903 return( $self->pass_error( $cldr->error ) );
1904 20 ▶ my $calendar = $self->{calendar} || 'gregorian';
Condition50%1/2
$self->{'calendar'} || 'gregorian'
l!l
020
MC/DC0%0/1
$self->{'calendar'} || 'gregorian'
$self->{'calendar'}
Truth table50%1/2
A
A= $self->{'calendar'}
Aresult
11
00
1905 20 my $pattern;
1906 20 foreach my $loc ( @$locales )
1907 {
1908 20 my $ref = $cldr->calendar_datetime_format(
1909 locale => $loc,
1910 calendar => $calendar,
1911 format_type => $type,
1912 format_length => $width,
1913 );
1914 20 ▶ return( $self->pass_error ) if( !defined( $ref ) && $cldr->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $cldr->error 0 20 20
Condition33%1/3
not defined $ref and $cldr->error
!ll&&!rl&&r
2000
MC/DC0%0/2
not defined $ref and $cldr->error
not defined $ref $cldr->error
Truth table33%1/3
not(A) and B
A= not defined $refB= $cldr->error
ABresult
0X0
100
111
1915 20 ▶ if( $ref && $ref->{format_pattern} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and $ref->{"format_pattern"}) 20 0 20
Condition33%1/3
$ref and $ref->{"format_pattern"}
!ll&&!rl&&r
0020
MC/DC0%0/2
$ref and $ref->{"format_pattern"}
$ref $ref->{"format_pattern"}
Truth table33%1/3
A and B
A= $refB= $ref->{"format_pattern"}
ABresult
0X0
100
111
1916 {
1917 20 $pattern = $ref->{format_pattern};
1918 20 last;
1919 }
1920 }
1921 20 ▶ return( $pattern // '' );
Condition50%1/2
$pattern // ""
l!l
200
MC/DC0%0/1
$pattern // ""
$pattern
Truth table50%1/2
A
A= $pattern
Aresult
11
00
1922 }
1923  
1924 sub _get_default_options_for_locale
1925 7 ▶{
Subroutine _get_default_options_for_locale: called CC=8 SCAR=21.6
1926 7 my $self = shift( @_ );
1927 my $locale = shift( @_ ) || $self->{locale} ||
1928 7 ▶ return( $self->error( "No locale was provided to get default options." ) );
Condition40%2/5
shift @_ || $self->{'locale'} || (return $self->error('No locale was provided to get default options.'))
l!l
70
shift @_ or $self->{"locale"}
l!l&&r!l&&!r
070
MC/DC0%0/2
shift @_ || $self->{'locale'} || (return $self->error('No locale was provided to get default options.'))
shift @_ $self->{"locale"}
Truth table33%1/3
A or B
A= shift @_B= $self->{"locale"}
ABresult
1X1
011
000
1929 # We want to know basically if the day, and month should be either numeric (i.e. 1 digit), or 2-digit
1930 # For this, we use the short date locale format and we check for d or d{2} and M and M{2} or L and L{2}
1931 7 ▶ my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone!" );
Condition50%1/2
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone!')
l!l
70
MC/DC0%0/1
$self->{'_cldr'} || die('The Locale::Unicode::Data object is gone!')
$self->{'_cldr'}
Truth table50%1/2
A
A= $self->{'_cldr'}
Aresult
11
00
1932 # my $unicode = $self->{_unicode} || die( "The DateTime::Locale::FromCLDR object is gone!" );
1933 7 ▶ my $tree = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
70
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
1934 return( $self->pass_error( $cldr->error ) );
1935 7 my $opts =
1936 {
1937 day => 'numeric',
1938 month => 'numeric',
1939 year => 'numeric',
1940 hour => 'numeric',
1941 minute => 'numeric',
1942 second => 'numeric',
1943 };
1944 7 my $defaults;
1945 7 foreach my $loc ( @$tree )
1946 {
1947 14 ▶ if( exists( $BROWSER_DEFAULTS->{ $loc } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DateTime::Format::Intl::BROWSER_DEFAULTS->{$loc}) 7 7 14
1948 {
1949 7 $defaults = $BROWSER_DEFAULTS->{ $loc };
1950 7 last;
1951 }
1952 }
1953 7 ▶ $defaults = $BROWSER_DEFAULTS->{en} if( !defined( $defaults ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $defaults 0 7 7
1954 7 my @keys = keys( %$defaults );
1955 7 @$opts{ @keys } = @$defaults{ @keys };
1956 # $opts->{numberingSystem} = $unicode->number_system;
1957 7 return( $opts );
1958 }
1959  
1960 # Function to get locale-specific preferences for scoring
1961 sub _get_locale_preferences
1962 551 ▶{
Subroutine _get_locale_preferences: called CC=6 SCAR=18.0
1963 551 my $self = shift( @_ );
1964 551 ▶ my $locale = $self->{locale} || die( "Locale::Intl object is gone!" );
Condition50%1/2
$self->{'locale'} || die('Locale::Intl object is gone!')
l!l
5510
MC/DC0%0/1
$self->{'locale'} || die('Locale::Intl object is gone!')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
1965 551 ▶ my $cldr = $self->_cldr || return( $self->pass_error );
Condition50%1/2
$self->_cldr || (return $self->pass_error)
l!l
5510
MC/DC0%0/1
$self->_cldr || (return $self->pass_error)
$self->_cldr
Truth table50%1/2
A
A= $self->_cldr
Aresult
11
00
1966
1967 # Define common preference groups
1968 551 my $eastern_europe =
1969 {
1970 dayPeriod => 3,
1971 timeZone => 2
1972 };
1973
1974 551 my $western_europe =
1975 {
1976 dayPeriod => 3,
1977 timeZone => 1
1978 };
1979  
1980 551 my $middle_east =
1981 {
1982 weekday => 5,
1983 era => 1,
1984 dayPeriod => 4,
1985 timeZone => 3
1986 };
1987
1988 551 my $indian_subcontinent =
1989 {
1990 dayPeriod => 3,
1991 timeZone => 2
1992 };
1993  
1994 551 my $east_asia =
1995 {
1996 weekday => 5,
1997 era => 5,
1998 dayPeriod => 1,
1999 timeZone => 1
2000 };
2001  
2002 551 my $south_east_asia =
2003 {
2004 dayPeriod => 3,
2005 timeZone => 2
2006 };
2007  
2008 # Locale-specific preferences with finer granularity
2009 551 my %locale_preferences =
2010 (
2011 # English locales with finer granularity
2012 'en-US' => { dayPeriod => 4, timeZone => 1 }, # US uses h12
2013 'en-GB' => { dayPeriod => 4, timeZone => 1 }, # GB uses h23
2014 'en-CA' => { dayPeriod => 4, timeZone => 1 }, # Canada uses h12
2015 'en-AU' => { dayPeriod => 4, timeZone => 1 }, # Australia uses h23
2016 'en-IN' => { dayPeriod => 4, timeZone => 2 }, # India uses h12
2017 'en-NZ' => { dayPeriod => 4, timeZone => 1 }, # New Zealand uses h23
2018
2019 # French locales with finer granularity
2020 'fr-FR' => { dayPeriod => 2, timeZone => 1 }, # France uses h24
2021 'fr-CA' => { dayPeriod => 2, timeZone => 1 }, # Quebec uses h12
2022 'fr-BE' => { dayPeriod => 2, timeZone => 1 }, # Belgium uses h24
2023 'fr-CH' => { dayPeriod => 2, timeZone => 1 }, # Switzerland uses h24
2024  
2025 # Spanish locales with finer granularity
2026 'es-ES' => { dayPeriod => 3, timeZone => 1 }, # Spain uses h24
2027 'es-MX' => { dayPeriod => 3, timeZone => 1 }, # Mexico uses h12
2028 'es-US' => { dayPeriod => 3, timeZone => 1 }, # US Spanish uses h12
2029 'es-AR' => { dayPeriod => 3, timeZone => 1 }, # Argentina uses h12
2030  
2031 # Chinese locales with finer granularity
2032 'zh-CN' => { weekday => 5, era => 5, dayPeriod => 2, timeZone => 1 }, # China uses h24
2033 'zh-TW' => { weekday => 5, era => 5, dayPeriod => 2, timeZone => 1 }, # Taiwan uses h24
2034 'zh-HK' => { weekday => 5, era => 5, dayPeriod => 2, timeZone => 1 }, # Hong Kong uses h12
2035  
2036 # Russian locale with h24 format
2037 'ru' => { dayPeriod => 3, timeZone => 2 }, # Russia uses h24
2038  
2039 # Eastern European locales
2040 'be' => $eastern_europe,
2041 'bg' => $eastern_europe,
2042 'cs' => $eastern_europe,
2043 'hr' => $eastern_europe,
2044 'hu' => $eastern_europe,
2045 'lt' => $eastern_europe,
2046 'lv' => $eastern_europe,
2047 'pl' => $eastern_europe,
2048 'ro' => $eastern_europe,
2049 'ru' => $eastern_europe,
2050 'sk' => $eastern_europe,
2051 'sl' => $eastern_europe,
2052 'uk' => $eastern_europe,
2053  
2054 # Western European locales
2055 'af' => $western_europe,
2056 'ca' => $western_europe,
2057 'da' => $western_europe,
2058 'de' => { dayPeriod => 3, timeZone => 2 }, # Germany uses h24
2059 'es' => $western_europe,
2060 'fi' => $western_europe,
2061 'fr' => { dayPeriod => 3, timeZone => 1 },
2062 'it' => $western_europe,
2063 'nl' => $western_europe,
2064 'sv' => $western_europe,
2065  
2066 # Middle Eastern and Arabic-speaking locales
2067 'ar' => $middle_east,
2068 'he' => $middle_east,
2069 'fa' => $middle_east,
2070 'ur' => $middle_east,
2071
2072 # Indian subcontinent locales
2073 'hi' => $indian_subcontinent,
2074 'bn' => $indian_subcontinent,
2075 'gu' => $indian_subcontinent,
2076 'ml' => $indian_subcontinent,
2077 'mr' => $indian_subcontinent,
2078 'ta' => $indian_subcontinent,
2079 'te' => $indian_subcontinent,
2080
2081 # East Asia
2082 # Japan uses h24
2083 'ja' => { weekday => 4, era => 6, dayPeriod => 3, timeZone => 2 },
2084 'zh' => $east_asia,
2085 'ko' => { weekday => 4, era => 4, dayPeriod => 3, timeZone => 2 },
2086  
2087 # Southeast Asian locales
2088 'id' => $south_east_asia,
2089 'ms' => $south_east_asia,
2090 'vi' => $south_east_asia,
2091 'th' => $south_east_asia,
2092  
2093 # Default fallback for unspecified locales
2094 _default =>
2095 {
2096 weekday => 7,
2097 era => 4,
2098 dayPeriod => 4,
2099 timeZone => 3,
2100 }
2101 );
2102  
2103 551 ▶ my $locales = $cldr->make_inheritance_tree( $locale ) ||
Condition50%1/2
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
l!l
5510
MC/DC0%0/1
$cldr->make_inheritance_tree($locale) || (return $self->pass_error($cldr->error))
$cldr->make_inheritance_tree($locale)
Truth table50%1/2
A
A= $cldr->make_inheritance_tree($locale)
Aresult
11
00
2104 return( $self->pass_error( $cldr->error ) );
2105 # Remove the last one: und
2106 551 pop( @$locales );
2107 # Return the specific locale's preferences, or fallback to the default
2108 551 foreach my $loc ( @$locales )
2109 {
2110 558 ▶ if( exists( $locale_preferences{ $loc } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $locale_preferences{$loc}) 4 554 558
2111 {
2112 4 return( $locale_preferences{ $loc } );
2113 }
2114 }
2115 # Return the specific locale's preferences, or fallback to the default
2116 547 return( $locale_preferences{_default} );
2117 }
2118  
2119 # We return 2 hash reference:
2120 # 1) An hash of components to weight and penalty used for scoring available patterns
2121 # 2) An hash of resolved options related components with their expected length, so we can score higher a pattern that match our option and has the right length.
2122 sub _get_option_dictionary
2123 551 ▶{
Subroutine _get_option_dictionary: called CC=37 SCAR=46.5
2124 551 my $self = shift( @_ );
2125 551 my $args = $self->_get_args_as_hash( @_ );
2126 # Resolved options
2127 my $opts = $args->{options} ||
2128 551 ▶ return( $self->error( "No options was provided." ) );
Condition50%1/2
$args->{'options'} || (return $self->error('No options was provided.'))
l!l
5510
MC/DC0%0/1
$args->{'options'} || (return $self->error('No options was provided.'))
$args->{'options'}
Truth table50%1/2
A
A= $args->{'options'}
Aresult
11
00
2129 # For intervals; this is optional and may be undef
2130 551 my $diff = $args->{diff};
2131 # Scoring adjustments based on locale-specific preferences
2132 551 my $locale_preferences = $self->_get_locale_preferences;
2133 # Score based on exact matches in the skeleton, with higher weights for more critical components
2134 # Define expected lengths and pattern characters for all options
2135 my $options_dict =
2136 {
2137 era =>
2138 {
2139 pattern_components => [qw(G)],
2140 penalty => 15,
2141 len =>
2142 {
2143 short => [1..3], # G..GGG
2144 long => 4, # GGGG
2145 narrow => 5, # GGGGG
2146 },
2147 weight => ( $locale_preferences->{era} || 4 ),
2148 },
2149 year =>
2150 {
2151 pattern_components => [qw(y Y)],
2152 penalty => 15,
2153 len =>
2154 {
2155 # 4 should be enough, but there is no upper limit actually in the LDML specifications
2156 numeric => [1..6], # y (numeric year)
2157 '2-digit' => 2 # yy (2-digit year)
2158 },
2159 weight => 14, # Year is generally important
2160 },
2161 month =>
2162 {
2163 pattern_components => [qw(M L)], # M and L for month
2164 penalty => 15,
2165 len =>
2166 {
2167 numeric => [1, 2], # M (numeric) or MM (2-digit)
2168 '2-digit' => 2, # MM (2-digit month)
2169 short => 3, # MMM (abbreviated month)
2170 long => 4, # MMMM (full month name)
2171 narrow => 5 # MMMMM (narrow month)
2172 },
2173 weight => 17, # Month is usually important
2174 },
2175 day =>
2176 {
2177 pattern_components => [qw(d)],
2178 penalty => 15,
2179 len =>
2180 {
2181 numeric => 1, # d (numeric day)
2182 '2-digit' => 2 # dd (2-digit day)
2183 },
2184 weight => 10,
2185 },
2186 weekday =>
2187 {
2188 pattern_components => [qw(c e E)],
2189 # Penalize heavily for unrequested weekday
2190 penalty => 20,
2191 len =>
2192 {
2193 # length of 1 and 2 are reserved for weekday as a number for pattern component 'c' and 'e', but not for E.
2194 # Abbreviated in CLDR
2195 short =>
2196 {
2197 'c' => 3, # ccc (Tue)
2198 'e' => 3, # eee (Tue)
2199 'E' => [1..3], # E..EEE (Tue)
2200 },
2201 # Wide in CLDR
2202 long => 4, # cccc (Tuesday), eeee (Tuesday), EEEE (Tuesday)
2203 # 6 characters should not happen though
2204 # Narrow and short in CLDR
2205 narrow => [5,6], # ccccc (T), cccccc (Tu), eeeee (T), eeeeee (Tu), EEEEE (T), EEEEEE (Tu)
2206 },
2207 weight => ( $locale_preferences->{weekday} || 7 ),
2208 },
2209 dayPeriod =>
2210 {
2211 # "Patterns for 12-hour-cycle time formats (using h or K) must include a day period field using one of a, b, or B."
2212 # <https://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems>
2213 # See at the end of this method for the implementation of this rule.
2214 # pattern_components => [qw(a b B)],
2215 # Actually, 'a' is AM/PM, not really a day period
2216 pattern_components => [qw(b B)],
2217 # Penalize for unrequested day periods
2218 penalty => 15,
2219 len =>
2220 {
2221 short => [1..3], # a..aaa, b..bbb, B..BBB (AM/PM)
2222 long => 4, # aaaa, bbbb, BBBB; b or B for specific day periods like noon or midnight
2223 narrow => 5, # aaaaa, bbbbb, BBBBB
2224 },
2225 weight => ( $locale_preferences->{dayPeriod} || 4 ),
2226 },
2227 hour =>
2228 {
2229 pattern_components => [qw(h H k K)],
2230 penalty => 15,
2231 len =>
2232 {
2233 numeric => [1,2], # h, H, k, K (numeric hour)
2234 '2-digit' => 2, # hh, HH, kk, KK (2-digit hour)
2235 },
2236 weight => 3,
2237 alias =>
2238 {
2239 # Only 'h' or 'H' are used in our option skeleton built in _options_to_skeleton()
2240 # and generally also in the CLDR available pattern skeletons
2241 'H' => ['k'],
2242 'h' => ['K'],
2243 },
2244 },
2245 minute =>
2246 {
2247 pattern_components => [qw(m)],
2248 penalty => 15,
2249 len =>
2250 {
2251 numeric => [1,2], # m (numeric minute)
2252 '2-digit' => 2, # mm (2-digit minute)
2253 },
2254 weight => 3,
2255 },
2256 second =>
2257 {
2258 pattern_components => [qw(s)],
2259 penalty => 15,
2260 len =>
2261 {
2262 numeric => [1,2], # s (numeric second)
2263 '2-digit' => 2, # ss (2-digit second)
2264 },
2265 weight => 3,
2266 },
2267 fractionalSecondDigits =>
2268 {
2269 pattern_components => [qw(S)],
2270 # Default penalty for unrequested components
2271 penalty => 5,
2272 len =>
2273 {
2274 1 => 1, # S (tenths of a second)
2275 2 => 2, # SS (hundredths of a second)
2276 3 => 3, # SSS (milliseconds)
2277 },
2278 weight => 3,
2279 },
2280 # 'V' is more for the time zone ID, or long time zone name, or exemplar city name
2281 timeZoneName =>
2282 {
2283 pattern_components => [qw(O z Z v V)],
2284 # Default penalty for unrequested components
2285 penalty => 5,
2286 len =>
2287 {
2288 short =>
2289 {
2290 'O' => 1, # O (GMT-8)
2291 'v' => 1, # v (short generic non-location format; e.g.: PT)
2292 'V' => 1, # V (short time zone ID; e.g. uslax)
2293 'z' => [1..3], # z..zzz (short localized GMT offset; e.g.: PDT)
2294 'Z' => [1..3], # Z..ZZZ (ISO8601 basic format; e.g.: -0800)
2295 },
2296 long => [4,5], # OOOO (GMT-08:00), zzzz (long localized GMT offset; e.g.: Pacific Daylight Time), ZZZZ (long localized GMT format. e.g.: GMT-8:00), ZZZZZ (ISO8601 extended format with hours, minutes and optional seconds; e.g.: -08:00 or -07:52:58)
2297 long =>
2298 {
2299 'O' => 4, # OOOO (long localized GMT format; e.g.: GMT-08:00)
2300 'v' => 4, # vvvv (long generic non-location format; e.g.: Pacific Time)
2301 # I seriously doubt VVV or VVVV would be occurring, but out of abondance of precaution, I add it anyway
2302 'V' => [2..4], # VV (long time zone ID; e.g. America/Los_Angeles), VVV (exemplar city; e.g.: Los Angeles), VVVV (generic location format; e.g.: Los Angeles Time)
2303 'z' => 4, # zzzz (long specific non-location format; e.g.: Pacific Daylight Time)
2304 # I doubt the ISO8601 extended format occurs, but out of abondance of precaution, I add it here anyway.
2305 'Z' => [4,5], # ZZZZ (long localized GMT format: e.g.: GMT-8:00), ZZZZZ (ISO8601 extended format with hours, minutes and optional seconds; e.g.: -07:52:58)
2306 },
2307 shortOffset => 1, # Z (short ISO-8601 time zone offset)
2308 longOffset => 4, # ZZZZ (long ISO-8601 time zone offset with GMT)
2309 shortGeneric => 1, # v (short generic non-location format; e.g.: PT)
2310 longGeneric => 4, # vvvv (long generic non-location format; e.g.: Pacific Time), VVVV (long generic location format; e.g.: Los Angeles Time)
2311 },
2312 551 ▶ weight => ( $locale_preferences->{timeZone} || 3 ),
Condition75%6/8
$locale_preferences->{'era'} || 4
l!l
5501
$locale_preferences->{'weekday'} || 7
l!l
5501
$locale_preferences->{'dayPeriod'} || 4
l!l
5510
$locale_preferences->{'timeZone'} || 3
l!l
5510
MC/DC100%1/1
$locale_preferences->{'era'} || 4
$locale_preferences->{'era'}
MC/DC100%1/1
$locale_preferences->{'weekday'} || 7
$locale_preferences->{'weekday'}
MC/DC0%0/1
$locale_preferences->{'dayPeriod'} || 4
$locale_preferences->{'dayPeriod'}
MC/DC0%0/1
$locale_preferences->{'timeZone'} || 3
$locale_preferences->{'timeZone'}
Truth table100%2/2
A
A= $locale_preferences->{'era'}
Aresult
11
00
Truth table100%2/2
A
A= $locale_preferences->{'weekday'}
Aresult
11
00
Truth table50%1/2
A
A= $locale_preferences->{'dayPeriod'}
Aresult
11
00
Truth table50%1/2
A
A= $locale_preferences->{'timeZone'}
Aresult
11
00
2313 }
2314 };
2315 # The components length for the selected options
2316 551 my $components_length = {};
2317 # The components weight and penalty
2318 551 my $components_weight = {};
2319 # The components aliases only for the resolved options components
2320 # Because, as the Unicode LDML specifies: "Only one field of each type is allowed; that is, "Hh" is not valid."
2321 # <https://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems>
2322 551 my $components_alias = {};
2323 551 foreach my $option ( keys( %$options_dict ) )
2324 {
2325 6061 my $def = $options_dict->{ $option };
2326 6061 my $components = $def->{pattern_components};
2327 6061 foreach my $c ( @$components )
2328 {
2329 12673 $components_weight->{ $c } = {};
2330 12673 for( qw( weight penalty ) )
2331 {
2332 25346 $components_weight->{ $c }->{ $_ } = $def->{ $_ };
2333 }
2334 }
2335 6061 ▶ if( exists( $opts->{ $option } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{$option}) { } 1565 4496 6061
elsif (defined $diff and scalar grep(($_ eq $diff), @{$$def{'pattern_components'};})) { } 0 7252 7252
2336 {
2337 1565 my $len = $def->{len};
2338 # Should not happen though
2339 1565 ▶ die( "Misconfiguration: missing option value \"", $opts->{ $option }, "\" in our option length dictionary." ) if( !exists( $len->{ $opts->{ $option } } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$len{$opts->{$option}} 0 1565 1565
2340 1565 ▶ if( ref( $len->{ $opts->{ $option } } ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$len{$opts->{$option}} eq 'HASH') { } 182 1383 1565
2341 {
2342 182 foreach my $c ( keys( %{$len->{ $opts->{ $option } }} ) )
2343 {
2344 650 $components_length->{ $c } = $len->{ $opts->{ $option } }->{ $c };
2345 }
2346 }
2347 else
2348 {
2349 1383 foreach my $c ( @$components )
2350 {
2351 # which could be an integer, or an array reference of integer, such as [1,2]
2352 2616 $components_length->{ $c } = $len->{ $opts->{ $option } };
2353 }
2354 }
2355  
2356 1565 ▶ if( exists( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'alias'}) { } 194 1371 1565
2357 {
2358 194 foreach my $k ( keys( %{$def->{alias}} ) )
2359 {
2360 388 ▶ die( "Configuration error: I was expecting an array reference for this alias value for component \"${k}\", but instead I got '", $def->{alias}->{ $k }, "'" ) if( ref( $def->{alias}->{ $k } ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $def->{"alias"}{$k} ne "ARRAY" 0 388 388
2361 388 my $keys = $def->{alias}->{ $k };
2362 388 $components_alias->{ $k } = [@$keys];
2363 }
2364 }
2365 else
2366 {
2367 1371 foreach my $c ( @$components )
2368 {
2369 # Any other, we alias to
2370 2490 my @keys = grep( $_ ne $c, @$components );
2371 2490 $components_alias->{ $c } = \@keys;
2372 }
2373 }
2374 }
2375 # If this option possible components match the greatest difference component if provided
2376 1740 ▶ elsif( defined( $diff ) && scalar( grep( $_ eq $diff, @{$def->{pattern_components}} ) ) )
Condition100%2/2
defined $diff and scalar grep(($_ eq $diff), @{$$def{"pattern_components"};})
!ll
27561740
MC/DC100%1/1
defined $diff and scalar grep(($_ eq $diff), @{$$def{"pattern_components"};})
defined $diff
Truth table100%2/2
A
A= defined $diff
Aresult
00
11
2377 {
2378 # We build an array of all possible length for this option
2379 0 my $len = $def->{len};
2380 0 foreach my $comp ( keys( %$len ) )
2381 {
2382 0 ▶ if( ref( $len->{ $comp } ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $len->{$comp} eq 'HASH') { } 0 0 0
2383 {
2384 0 foreach my $c ( keys( %{$len->{ $comp }} ) )
2385 {
2386 0 ▶ $components_length->{ $c } ||= [];
Condition0%0/2
$components_length->{$c} ||= []
l!l
00
MC/DC0%0/1
$components_length->{$c} ||= []
$components_length->{$c}
Truth table0%0/2
A
A= $components_length->{$c}
Aresult
11
00
2387 0 ▶ push( @{$components_length->{ $c }}, ref( $len->{ $comp }->{ $c } ) eq 'ARRAY' ? @{$len->{ $comp }->{ $c }} : $len->{ $comp }->{ $c } );
Branch: 1 branch
BranchTrueFalseTotal
ref $len->{$comp}{$c} eq 'ARRAY' ? : 0 0 0
2388 }
2389 }
2390 else
2391 {
2392 0 foreach my $c ( @$components )
2393 {
2394 0 ▶ $components_length->{ $c } ||= [];
Condition0%0/2
$components_length->{$c} ||= []
l!l
00
MC/DC0%0/1
$components_length->{$c} ||= []
$components_length->{$c}
Truth table0%0/2
A
A= $components_length->{$c}
Aresult
11
00
2395 # which could be an integer, or an array reference of integer, such as [1,2]
2396 0 ▶ push( @{$components_length->{ $c }}, ref( $len->{ $comp } ) eq 'ARRAY' ? @{$len->{ $comp }} : $len->{ $comp } );
Branch: 1 branch
BranchTrueFalseTotal
ref $len->{$comp} eq 'ARRAY' ? : 0 0 0
2397 }
2398 }
2399 }
2400  
2401 0 ▶ if( exists( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'alias'}) { } 0 0 0
2402 {
2403 0 foreach my $k ( keys( %{$def->{alias}} ) )
2404 {
2405 0 ▶ die( "Configuration error: I was expecting an array reference for this alias value for component \"${k}\", but instead I got '", $def->{alias}->{ $k }, "'" ) if( ref( $def->{alias}->{ $k } ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $def->{"alias"}{$k} ne "ARRAY" 0 0 0
2406 0 my $keys = $def->{alias}->{ $k };
2407 0 $components_alias->{ $k } = [@$keys];
2408 }
2409 }
2410 else
2411 {
2412 0 foreach my $c ( @$components )
2413 {
2414 # Any other, we alias to
2415 0 my @keys = grep( $_ ne $c, @$components );
2416 0 $components_alias->{ $c } = \@keys;
2417 }
2418 }
2419 }
2420 }
2421  
2422 # "Patterns for 12-hour-cycle time formats (using h or K) must include a day period field using one of a, b, or B."
2423 # <https://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems>
2424 # We add an entry for AM/PM if hour12 is true and dayPeriod is not provided.
2425 # If dayPeriod is already provided, no need for 'a' as it would be redundant and the CLDR data reflects this.
2426 551 ▶ if( exists( $opts->{hour12} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"hour12"} and $opts->{"hour12"} and not exists $opts->{"dayPeriod"}) 120 431 551
Condition100%6/6
exists $opts->{"hour12"} and $opts->{"hour12"} and not exists $opts->{"dayPeriod"}
!ll&&!rl&&r
38942120
exists $opts->{"hour12"} and $opts->{"hour12"}
!ll&&!rl&&r
33752162
MC/DC100%3/3
exists $opts->{"hour12"} and $opts->{"hour12"} and not exists $opts->{"dayPeriod"}
exists $opts->{"hour12"} $opts->{"hour12"} not exists $opts->{"dayPeriod"}
Truth table100%4/4
A and B and not(C)
A= exists $opts->{"hour12"}B= $opts->{"hour12"}C= not exists $opts->{"dayPeriod"}
ABCresult
0XX0
10X0
1100
1111
2427 $opts->{hour12} &&
2428 !exists( $opts->{dayPeriod} ) )
2429 {
2430 120 $components_length->{a} = [1..3];
2431 120 $components_weight->{a} = 5;
2432 120 $components_alias->{a} = ['a'];
2433 }
2434 # Some adjustments
2435 551 ▶ if( exists( $opts->{hour12} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"hour12"}) 214 337 551
2436 {
2437 214 ▶ if( $opts->{hour12} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'hour12'}) { } 162 52 214
2438 {
2439 # Remove H23 and H24
2440 162 delete( @$components_length{ qw( H k ) } );
2441 }
2442 else
2443 {
2444 # Remove h11 and h12
2445 52 delete( @$components_length{ qw( h K ) } );
2446 }
2447 }
2448 551 return( $components_length, $components_weight, $components_alias );
2449 }
2450  
2451 sub _get_options_map
2452 626 ▶{
Subroutine _get_options_map: called CC=1 SCAR=0.0
2453 626 my $self = shift( @_ );
2454 626 my $map =
2455 {
2456 # Maps for format length adjustments
2457 type_to_length =>
2458 {
2459 # actually 'abbreviated' in LDML parlance
2460 short => 1,
2461 # actually 'wide' in LDML parlance
2462 long => 4,
2463 narrow => 5,
2464 },
2465 # Those have been carefully considered n light of the documentation at:
2466 # <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#timezonename>
2467 # and the LDML symbols at:
2468 # <https://unicode.org/reports/tr35/tr35-dates.html#dfst-zone>
2469 # my $timeZoneName_map =
2470 timezone =>
2471 {
2472 # Short localized form (e.g.: "PST", "GMT-8")
2473 short => 'z',
2474 # Long localized form (e.g., "Pacific Standard Time", "Nordamerikanische Westküsten-Normalzeit")
2475 long => 'zzzz',
2476 # Short localized GMT format (e.g., "GMT-8")
2477 shortOffset => 'O',
2478 # Long localized GMT format (e.g., "GMT-08:00")
2479 longOffset => 'OOOO',
2480 # Short generic non-location format (e.g.: "PT", "Los Angeles Zeit").
2481 shortGeneric => 'v',
2482 # Long generic non-location format (e.g.: "Pacific Time", "Nordamerikanische Westküstenzeit")
2483 longGeneric => 'vvvv'
2484 },
2485 # my $month_map =
2486 month =>
2487 {
2488 numeric => 1,
2489 '2-digit' => 2,
2490 # 'abbreviated' in LDML parlance
2491 short => 3,
2492 # 'wide' in LDML parlance
2493 long => 4,
2494 narrow => 5,
2495 },
2496 # For pattern characters 'c' or 'e'
2497 # my $weekday_map =
2498 weekday =>
2499 {
2500 # actually 'abbreviated' in LDML parlance -> example: 'Tue'
2501 short => 1, # 2, or 3 are also acceptable
2502 # actually 'wide' in LDML parlance -> example: 'Tuesday'
2503 long => 4,
2504 # also matches 'narrow' in LDML -> example: 'T'
2505 narrow => 5,
2506
2507 },
2508 };
2509 626 return( $map );
2510 }
2511  
2512 sub _max
2513 2 ▶{
Subroutine _max: called CC=2 SCAR=6.9
2514 2 my( $x, $y ) = @_;
2515 2 ▶ return( ( $x > $y ) ? $x : $y );
Branch: 1 branch
BranchTrueFalseTotal
$x > $y ? : 1 1 2
2516 }
2517  
2518 sub _new_request_object
2519 551 ▶{
Subroutine _new_request_object: called CC=5 SCAR=16.5
2520 551 my $self = shift( @_ );
2521 551 my $args = $self->_get_args_as_hash( @_ );
2522 551 ▶ my $opts = $args->{options} || die( "No resolved options hash reference provided." );
Condition50%1/2
$args->{'options'} || die('No resolved options hash reference provided.')
l!l
5510
MC/DC0%0/1
$args->{'options'} || die('No resolved options hash reference provided.')
$args->{'options'}
Truth table50%1/2
A
A= $args->{'options'}
Aresult
11
00
2523 551 my $diff = $args->{diff};
2524 # $tokens is an array reference of hash with component, token and len properties
2525 # $components is an array of 1-letter component
2526 551 ▶ my( $requested_skeleton, $tokens, $components, $date_components, $time_components ) = $self->_options_to_skeleton(
Branch: 1 branch
BranchTrueFalseTotal
defined $diff ? : 216 335 551
Condition50%1/2
$self->_options_to_skeleton('options', $opts, defined $diff ? ('diff', $diff) : ()) || (return $self->pass_error)
l!l
5510
MC/DC0%0/1
$self->_options_to_skeleton('options', $opts, defined $diff ? ('diff', $diff) : ()) || (return $self->pass_error)
$self->_options_to_skeleton('options', $opts, defined $diff ? ('diff', $diff) : ())
Truth table50%1/2
A
A= $self->_options_to_skeleton('options', $opts, defined $diff ? ('diff', $diff) : ())
Aresult
11
00
2527 options => $opts,
2528 ( defined( $diff ) ? ( diff => $diff ) : () ),
2529 ) || return( $self->pass_error );
2530  
2531 # Checking for exact match in the available pattern skeleton sounds like a great idea, but it leads to false positive.
2532 # So, we are best off going through all of the patterns and scoring them
2533 551 ▶ my $request_object = $self->_new_skeleton_object(
Condition50%1/2
$self->_new_skeleton_object('pattern_skeleton', $requested_skeleton, 'components', $components, 'date_components', $date_components, 'time_components', $time_components, 'tokens', $tokens, 'debug', $DateTime::Format::Intl::DEBUG) || (return $self->pass_error)
l!l
5510
MC/DC0%0/1
$self->_new_skeleton_object('pattern_skeleton', $requested_skeleton, 'components', $components, 'date_components', $date_components, 'time_components', $time_components, 'tokens', $tokens, 'debug', $DateTime::Format::Intl::DEBUG) || (return $self->pass_error)
$self->_new_skeleton_object('pattern_skeleton', $requested_skeleton, 'components', $components, 'date_components', $date_components, 'time_components', $time_components, 'tokens', $tokens, 'debug', $DateTime::Format::Intl::DEBUG)
Truth table50%1/2
A
A= $self->_new_skeleton_object('pattern_skeleton', $requested_skeleton, 'components', $components, 'date_components', $date_components, 'time_components', $time_components, 'tokens', $tokens, 'debug', $DateTime::Format::Intl::DEBUG)
Aresult
11
00
2534 pattern_skeleton => $requested_skeleton,
2535 components => $components,
2536 date_components => $date_components,
2537 time_components => $time_components,
2538 tokens => $tokens,
2539 debug => $DEBUG,
2540 ) || return( $self->pass_error );
2541 551 return( $request_object );
2542 }
2543  
2544 sub _new_score_result
2545 27544 ▶{
Subroutine _new_score_result: called CC=2 SCAR=7.1
2546 27544 my $self = shift( @_ );
2547 27544 ▶ my $obj = DateTime::Format::Intl::ScoreResult->new( @_ ) ||
Condition50%1/2
'DateTime::Format::Intl::ScoreResult'->new(@_) || (return $self->pass_error('DateTime::Format::Intl::ScoreResult'->error))
l!l
275440
MC/DC0%0/1
'DateTime::Format::Intl::ScoreResult'->new(@_) || (return $self->pass_error('DateTime::Format::Intl::ScoreResult'->error))
'DateTime::Format::Intl::ScoreResult'->new(@_)
Truth table50%1/2
A
A= 'DateTime::Format::Intl::ScoreResult'->new(@_)
Aresult
11
00
2548 return( $self->pass_error( DateTime::Format::Intl::ScoreResult->error ) );
2549 27544 return( $obj );
2550 }
2551  
2552 sub _new_skeleton_object
2553 28093 ▶{
Subroutine _new_skeleton_object: called CC=2 SCAR=7.1
2554 28093 my $self = shift( @_ );
2555 28093 ▶ my $obj = DateTime::Format::Intl::Skeleton->new( @_ ) ||
Condition50%1/2
'DateTime::Format::Intl::Skeleton'->new(@_) || (return $self->pass_error('DateTime::Format::Intl::Skeleton'->error))
l!l
280930
MC/DC0%0/1
'DateTime::Format::Intl::Skeleton'->new(@_) || (return $self->pass_error('DateTime::Format::Intl::Skeleton'->error))
'DateTime::Format::Intl::Skeleton'->new(@_)
Truth table50%1/2
A
A= 'DateTime::Format::Intl::Skeleton'->new(@_)
Aresult
11
00
2556 return( $self->pass_error( DateTime::Format::Intl::Skeleton->error ) );
2557 28093 return( $obj );
2558 }
2559  
2560 # Generate a skeleton from the user-provided options, ensuring a consistent order
2561 sub _options_to_skeleton
2562 551 ▶{
Subroutine _options_to_skeleton: called CC=13 SCAR=26.0
2563 551 my $self = shift( @_ );
2564 551 my $args = $self->_get_args_as_hash( @_ );
2565 my $opts = $args->{options} ||
2566 551 ▶ return( $self->error( "No options provided." ) );
Condition50%1/2
$args->{'options'} || (return $self->error('No options provided.'))
l!l
5510
MC/DC0%0/1
$args->{'options'} || (return $self->error('No options provided.'))
$args->{'options'}
Truth table50%1/2
A
A= $args->{'options'}
Aresult
11
00
2567 # Provided if format_range() was called, otherwise this is undef
2568 551 my $diff = $args->{diff};
2569  
2570 551 my $skeleton = '';
2571  
2572 # Ensure a fixed order of components when building the skeleton
2573 # "The canonical order is from top to bottom in that table; that is, "yM" not "My"."
2574 # <https://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems>
2575 551 my @ordered_options = qw( era year month weekday day dayPeriod hour minute second timeZoneName );
2576  
2577 551 my $options_map = $self->_get_options_map;
2578 # Map of option keys to skeleton components
2579 # Possible components found in skeleton in CLDR data: [qw( B E G H M Q W Z c d h m s v w y )]
2580 # "It is not necessary to supply dateFormatItems with skeletons for every field length; fields in the skeleton and pattern are expected to be adjusted in parallel to handle a request."
2581 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
2582 my $option_to_skeleton =
2583 {
2584 year => sub
2585 551 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
2586 551 ▶ return( 'y' x ( exists( $opts->{year} ) ? ( $opts->{year} eq '2-digit' ? 2 : 1 ) : 1 ) );
Branch: 2 branches
BranchTrueFalseTotal
exists $opts->{'year'} ? : 257 294 551
$opts->{'year'} eq '2-digit' ? : 2 255 257
2587 },
2588 month => sub
2589 551 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
2590 551 ▶ return( 'M' x ( exists( $opts->{month} ) ? $options_map->{month}->{ $opts->{month} } : 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'month'} ? : 330 221 551
2591 },
2592 day => sub
2593 551 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
2594 551 ▶ return( 'd' x ( exists( $opts->{day} ) ? ( $opts->{day} eq '2-digit' ? 2 : 1 ) : 1 ) );
Branch: 2 branches
BranchTrueFalseTotal
exists $opts->{'day'} ? : 241 310 551
$opts->{'day'} eq '2-digit' ? : 2 239 241
2595 },
2596 # There are 1 instance in the CLDR data where the skeleton uses 'c' (locale 'fi' with skeleton 'yMMMMccccd')
2597 weekday => sub
2598 551 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
2599 551 ▶ return( 'E' x ( exists( $opts->{weekday} ) ? $options_map->{weekday}->{ $opts->{weekday} } : 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'weekday'} ? : 141 410 551
2600 },
2601 # Can switch to 'H' for 24-hour time
2602 # hour => 'h',
2603 hour => sub
2604 551 ▶ {
Subroutine __ANON__: called CC=7 SCAR=19.5
2605 551 ▶ my $comp = ( exists( $opts->{hourCycle} ) && defined( $opts->{hourCycle} ) && ( $opts->{hourCycle} eq 'h23' || $opts->{hourCycle} eq 'h24' ) ) ? 'H' : 'h';
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'hourCycle'} && defined $opts->{'hourCycle'} && ($opts->{'hourCycle'} eq 'h23' || $opts->{'hourCycle'} eq 'h24') ? : 52 499 551
Condition88%8/9
exists $opts->{"hourCycle"} and defined $opts->{"hourCycle"} and $opts->{"hourCycle"} eq "h23" || $opts->{"hourCycle"} eq "h24"
!ll&&!rl&&r
33716252
exists $opts->{"hourCycle"} and defined $opts->{"hourCycle"}
!ll&&!rl&&r
3370214
$opts->{"hourCycle"} eq "h23" or $opts->{"hourCycle"} eq "h24"
l!l&&r!l&&!r
151162
MC/DC75%3/4
exists $opts->{"hourCycle"} and defined $opts->{"hourCycle"} and $opts->{"hourCycle"} eq "h23" || $opts->{"hourCycle"} eq "h24"
exists $opts->{"hourCycle"} defined $opts->{"hourCycle"} $opts->{"hourCycle"} eq "h23" $opts->{"hourCycle"} eq "h24"
Truth table80%4/5
A and B and C or D
A= exists $opts->{"hourCycle"}B= defined $opts->{"hourCycle"}C= $opts->{"hourCycle"} eq "h23"D= $opts->{"hourCycle"} eq "h24"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2606 551 ▶ return( $comp x ( exists( $opts->{hour} ) ? ( $opts->{hour} eq '2-digit' ? 2 : 1 ) : 1 ) );
Branch: 2 branches
BranchTrueFalseTotal
exists $opts->{'hour'} ? : 194 357 551
$opts->{'hour'} eq '2-digit' ? : 80 114 194
2607 },
2608 minute => sub
2609 551 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.2
2610 551 ▶ return( 'm' x ( exists( $opts->{minute} ) ? ( $opts->{minute} eq '2-digit' ? 2 : 1 ) : 1 ) );
Branch: 2 branches
BranchTrueFalseTotal
exists $opts->{'minute'} ? : 150 401 551
$opts->{'minute'} eq '2-digit' ? : 150 0 150
2611 },
2612 second => sub
2613 551 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.2
2614 551 ▶ return( 's' x ( exists( $opts->{second} ) ? ( $opts->{second} eq '2-digit' ? 2 : 1 ) : 1 ) );
Branch: 2 branches
BranchTrueFalseTotal
exists $opts->{'second'} ? : 43 508 551
$opts->{'second'} eq '2-digit' ? : 43 0 43
2615 },
2616 era => sub
2617 551 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
2618 551 ▶ return( 'G' x ( exists( $opts->{era} ) ? $options_map->{type_to_length}->{ $opts->{era} } : 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'era'} ? : 115 436 551
2619 },
2620 dayPeriod => sub
2621 551 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
2622 551 ▶ return( 'B' x ( exists( $opts->{dayPeriod} ) ? $options_map->{type_to_length}->{ $opts->{dayPeriod} } : 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'dayPeriod'} ? : 42 509 551
2623 },
2624 # There is 1 instance in the CLDR data where the skeleton uses 'Z' (locale 'fa' with skeleton 'HHmmZ')
2625 timeZoneName => sub
2626 551 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
2627 551 ▶ return( exists( $opts->{timeZoneName} ) ? $options_map->{timezone}->{ $opts->{timeZoneName} } : 'v' );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'timeZoneName'} ? : 52 499 551
2628 },
2629 # 'w' (week of year) and 'W' (week of month) are also found in the skeletons. 309 and 322 times respectively.
2630 # 'Q' (quarter) is also found 419 times in the skeletons, amazingly enough.
2631 551 };
2632 # SELECT DISTINCT(format_id) FROM calendar_available_formats WHERE format_id regexp('G') ORDER BY LENGTH(format_id), format_id;
2633 # my $singletons =
2634 # {
2635 # # Bh, Bhm, Bhms, EBhm, EBhms
2636 # 'B' => 1,
2637 # # 'c' can have multiple occurrence
2638 # # 'd' can have multiple occurrence
2639 # # E can have multiple occurrence
2640 # # Gy, GyM, GyMd, GyMMM, GyMMMM, GyMMMd, GyMMMEd, GyMMMMd, GyMEEEEd, GyMMMMEd, GyMMMEEEEd
2641 # 'G' => 1,
2642 # # H, h, K, k can have multiple occurrence
2643 # # M, L can have multiple occurrence, although L never appears in skeletons
2644 # # m can have multiple occurrence
2645 # # s can have multiple occurrence
2646 # # Q can have multiple occurrence
2647 # # v can have multiple occurrence
2648 # # w can have multiple occurrence
2649 # # W probably can have multiple occurrence, although it never appears in skeletons
2650 # # y can have multiple occurrence
2651 # 'Z' => 1,
2652 # };
2653  
2654 551 my $date_elements =
2655 {
2656 era => 1,
2657 year => 1,
2658 month => 1,
2659 weekday => 1,
2660 day => 1,
2661 };
2662 551 my $time_elements =
2663 {
2664 dayPeriod => 1,
2665 hour => 1,
2666 minute => 1,
2667 second => 1,
2668 timeZoneName => 1,
2669 };
2670 551 my $components = [];
2671 551 my $tokens = [];
2672 551 my $date_components = [];
2673 551 my $time_components = [];
2674 551 foreach my $option ( @ordered_options )
2675 {
2676 5510 ▶ my $value = ( ref( $option_to_skeleton->{ $option } ) ? $option_to_skeleton->{ $option }->() : $option_to_skeleton->{ $option } );
Branch: 1 branch
BranchTrueFalseTotal
ref $option_to_skeleton->{$option} ? : 5510 0 5510
2677 5510 ▶ if( ( exists( $opts->{ $option } ) && length( $opts->{ $option } // '' ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{$option} and length($opts->{$option} // "") or defined $diff and $value eq $diff) 1565 3945 5510
Condition63%7/11
exists $opts->{$option} and length($opts->{$option} // "") or defined $diff and $value eq $diff
l!l&&r!l&&!r
156503945
exists $opts->{$option} and length($opts->{$option} // "")
!ll&&!rl&&r
394501565
$opts->{$option} // ""
l!l
15650
defined $diff and $value eq $diff
!ll&&!rl&&r
242115240
MC/DC25%1/4
exists $opts->{$option} and length($opts->{$option} // "") or defined $diff and $value eq $diff
exists $opts->{$option} $opts->{$option} defined $diff $value eq $diff
Truth table42%3/7
A and B or C and D
A= exists $opts->{$option}B= $opts->{$option}C= defined $diffD= $value eq $diff
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2678 ( defined( $diff ) && $value eq $diff ) )
2679 {
2680 1565 $skeleton .= $value;
2681 1565 push( @$tokens, {
2682 component => substr( $value, 0, 1 ),
2683 token => $value,
2684 len => length( $value ),
2685 });
2686 1565 push( @$components, substr( $value, 0, 1 ) );
2687 1565 ▶ if( exists( $date_elements->{ $option } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $date_elements->{$option}) { } 1084 481 1565
elsif (exists $time_elements->{$option}) { } 481 0 481
2688 {
2689 1084 push( @$date_components, substr( $value, 0, 1 ) );
2690 }
2691 elsif( exists( $time_elements->{ $option } ) )
2692 {
2693 481 push( @$time_components, substr( $value, 0, 1 ) );
2694 }
2695 else
2696 {
2697 0 ▶ warn( "Uncategorised option \"${option}\" in either date or time map." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
2698 }
2699 }
2700 }
2701 551 ▶ return( wantarray ? ( $skeleton, $tokens, $components, $date_components, $time_components ) : $skeleton );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 551 551
2702 }
2703  
2704 # Convert a pattern to a skeleton for comparison
2705 sub _pattern_to_skeleton
2706 27542 ▶{
Subroutine _pattern_to_skeleton: called CC=3 SCAR=11.0
2707 27542 my $self = shift( @_ );
2708 27542 my $pattern = shift( @_ );
2709
2710 # Map format patterns to skeleton components
2711 # Found 16 skeleton components: [qw( B E G H M Q W Z c d h m s v w y )]
2712 27542 my $format_to_skeleton =
2713 {
2714 'a' => 'B',
2715 'A' => 'B',
2716 'b' => 'B',
2717 'B' => 'B',
2718 'c' => 'E',
2719 'C' => 'h',
2720 'd' => 'd',
2721 # D (day of year)
2722 'e' => 'E',
2723 'E' => 'E',
2724 # F (Day of Week in Month)
2725 # g (Modified Julian day)
2726 'G' => 'G',
2727 'h' => 'h',
2728 'H' => 'H',
2729 'j' => 'h',
2730 'J' => 'h',
2731 'k' => 'H',
2732 'K' => 'h',
2733 'L' => 'M',
2734 'M' => 'M',
2735 'm' => 'm',
2736 'O' => 'v',
2737 'q' => 'Q',
2738 'Q' => 'Q',
2739 # r (Related Gregorian year)
2740 's' => 's',
2741 # S (Fractional Second)
2742 # u (Extended year)
2743 # U (Cyclic year name)
2744 'v' => 'v',
2745 'V' => 'v',
2746 'w' => 'w',
2747 'W' => 'W',
2748 'x' => 'v',
2749 'X' => 'v',
2750 'y' => 'y',
2751 'Y' => 'y',
2752 'z' => 'Z',
2753 'Z' => 'Z',
2754 };
2755
2756 27542 my $skeleton = '';
2757 # TODO: needs to be improved
2758 27542 foreach my $component ( split( //, $pattern ) )
2759 {
2760 211782 ▶ if( exists( $format_to_skeleton->{ $component } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $format_to_skeleton->{$component}) 134833 76949 211782
2761 {
2762 # $skeleton .= $format_to_skeleton->{ $component };
2763 134833 $skeleton .= $component;
2764 }
2765 }
2766 27542 return( $skeleton );
2767 }
2768  
2769 sub _remove_literal_text
2770 27542 ▶{
Subroutine _remove_literal_text: called CC=3 SCAR=11.3
2771 27542 my $self = shift( @_ );
2772 27542 my $pattern = shift( @_ );
2773 # This is an internal mishandling: die
2774 27542 ▶ die( "No pattern was provided!" ) if( !length( $pattern // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($pattern // "") 0 27542 27542
Condition50%1/2
$pattern // ""
l!l
275420
MC/DC0%0/1
$pattern // ""
$pattern
Truth table50%1/2
A
A= $pattern
Aresult
11
00
2775 # Regex to handle escaped single quotes ('') and remove literal text
2776 # Matches text inside single quotes and escaped quotes
2777 27542 $pattern =~ s/'(?:[^']|'')*'//g;
2778 27542 return( $pattern );
2779 }
2780  
2781 # Fine-tuned scoring logic based on real-world usage patterns and cultural preferences
2782 sub _score_pattern
2783 27522 ▶{
Subroutine _score_pattern: called CC=38 SCAR=36.7
2784 27522 my $self = shift( @_ );
2785 27522 my $args = $self->_get_args_as_hash( @_ );
2786 27522 ▶ my $pattern_object = $args->{pattern_object} || die( "Missing pattern object." );
Condition50%1/2
$args->{'pattern_object'} || die('Missing pattern object.')
l!l
275220
MC/DC0%0/1
$args->{'pattern_object'} || die('Missing pattern object.')
$args->{'pattern_object'}
Truth table50%1/2
A
A= $args->{'pattern_object'}
Aresult
11
00
2787 27522 ▶ my $request_object = $args->{request_object} || die( "Missing request object." );
Condition50%1/2
$args->{'request_object'} || die('Missing request object.')
l!l
275220
MC/DC0%0/1
$args->{'request_object'} || die('Missing request object.')
$args->{'request_object'}
Truth table50%1/2
A
A= $args->{'request_object'}
Aresult
11
00
2788 27522 ▶ my $opts = $args->{options} || die( "Missing the user options." );
Condition50%1/2
$args->{'options'} || die('Missing the user options.')
l!l
275220
MC/DC0%0/1
$args->{'options'} || die('Missing the user options.')
$args->{'options'}
Truth table50%1/2
A
A= $args->{'options'}
Aresult
11
00
2789 27522 my $pattern = $pattern_object->pattern;
2790 27522 my $pattern_skeleton = $pattern_object->pattern_skeleton;
2791 # Array of descriptive dictionary for each component, such as: { component => 'E', token => 'EEEE', len => 4 }
2792 27522 my $pattern_tokens = $pattern_object->tokens;
2793 27522 my $requested_skeleton = $request_object->pattern_skeleton;
2794 27522 my $requested_tokens = $request_object->tokens;
2795  
2796 27522 ▶ my $locale = $self->{locale} || die( "The Locale::Intl object is gone" );
Condition50%1/2
$self->{'locale'} || die('The Locale::Intl object is gone')
l!l
275220
MC/DC0%0/1
$self->{'locale'} || die('The Locale::Intl object is gone')
$self->{'locale'}
Truth table50%1/2
A
A= $self->{'locale'}
Aresult
11
00
2797 27522 ▶ my $unicode = $self->{_unicode} || die( "The DateTime::Locale::FromCLDR object is gone" );
Condition50%1/2
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone')
l!l
275220
MC/DC0%0/1
$self->{'_unicode'} || die('The DateTime::Locale::FromCLDR object is gone')
$self->{'_unicode'}
Truth table50%1/2
A
A= $self->{'_unicode'}
Aresult
11
00
2798
2799 27522 my $score = 0;
2800  
2801 27522 my $components_length = $self->{_components_length};
2802 27522 my $components_weight = $self->{_components_weight};
2803 27522 my $components_alias = $self->{_components_alias};
2804  
2805 # Collect the components in the pattern skeleton
2806 27522 my $pattern_chars = $pattern_object->components;
2807 27522 my $pattern_components = +{ map{ $_->{component} => $_ } @$pattern_tokens };
2808  
2809 # This is used to check if a component found in the pattern is found or not in the skeleton. If it is not, the penalty is not as bad.
2810 27522 my $skeleton_tokens = $pattern_object->skeleton_tokens;
2811 27522 my $skeleton_components = +{ map{ $_->{component} => $_ } @$skeleton_tokens };
2812  
2813 # Penalize for extra components not in the requested skeleton
2814 27522 my $extra_component_penalty = 0;
2815  
2816  
2817 # Score for a component that matches perfectly, i.e. the right component and right length
2818 27522 my $perfect_component_score = 100;
2819 # Keep track of this hypothetical perfect score separate from the actual score, because we do not want to pollute the latter with the former, since this $perfect_score is just a test whether this available pattern skeleton matches perfectly our requested skeleton or not. If it is, we bump up the review of all available patterns stops.
2820 27522 my $perfect_score = 0;
2821 27522 my $missing = [];
2822 # Determine if this pattern needs adjustment, assuming it will be the one retained in the end.
2823 # We do this assessment here, because it is easy to check, and it saves us later the trouble of parsing the pattern once more to check for any need for adjustment, by calling the method _adjust_pattern
2824 27522 my $need_adjustment = 0;
2825  
2826 # We give weight on the existence of a component from the requested skeleton in the available pattern; and
2827 # on the pertinence (length) of that components, such as MMMM for long (wide)
2828 # The order is not important, because of variation from locale to locale
2829 # The best will be retained, and its pattern adjusted to fit the user options; for example 'MMMM' might become 'MMM'
2830 27522 ▶ for( my $i = 0; $i < scalar( @$requested_tokens ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$requested_tokens) 77045 27522 104567
2831 {
2832 77045 my $def = $requested_tokens->[$i];
2833 77045 my $requested_component = $def->{component};
2834 77045 my $alias;
2835 # my $alias = ( exists( $pattern_components->{ $requested_component } ) ? $requested_component : [grep( exists( $pattern_components->{ $_ } ), @{$components_alias->{ $requested_component } || []} )]->[0] );
2836 77045 ▶ if( exists( $pattern_components->{ $requested_component } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $pattern_components->{$requested_component}) { } 28638 48407 77045
elsif (my $found_alias = [grep(exists $pattern_components->{$_}, @{$components_alias->{$requested_component} or [];})]->[0]) { } 810 47597 48407
2837 {
2838 28638 $alias = $requested_component;
2839 }
2840 # Found the component in our request skeleton, but as an alias, which means that we will need to adjust our pattern
2841 48407 ▶ elsif( my $found_alias = [grep( exists( $pattern_components->{ $_ } ), @{$components_alias->{ $requested_component } || []} )]->[0] )
Condition50%1/2
$components_alias->{$requested_component} || []
l!l
484070
MC/DC0%0/1
$components_alias->{$requested_component} || []
$components_alias->{$requested_component}
Truth table50%1/2
A
A= $components_alias->{$requested_component}
Aresult
11
00
2842 {
2843 810 $alias = $found_alias;
2844 810 $need_adjustment++;
2845 }
2846 else
2847 {
2848 47597 $alias = $requested_component;
2849 47597 $need_adjustment++;
2850 }
2851  
2852 77045 ▶ my $exists = ( exists( $pattern_components->{ $alias } ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
exists $pattern_components->{$alias} ? : 29448 47597 77045
2853 # Does the current pattern have our requested component, such as 'E' ?
2854 77045 ▶ if( $exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($exists) { } 29448 47597 77045
2855 {
2856 # Our requested component might exist, even though the pattern skeleton is smaller than our requested one.
2857 # For example: YMMMd (requested skeleton) vs yd (pattern skeleton)
2858 29448 $score += $components_weight->{ $alias }->{weight};
2859 29448 my $expected_length = $components_length->{ $alias };
2860  
2861 29448 ▶ if( ref( $expected_length ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expected_length eq 'ARRAY') { } 14150 15298 29448
2862 {
2863 14150 ▶ if( scalar( grep{ $pattern_components->{ $alias }->{len} == $_ } @$expected_length ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep({$pattern_components->{$alias}{'len'} == $_;} @$expected_length)) { } 11590 2560 14150
2864 {
2865 # Reward for exact numeric match
2866 11590 $score += 5;
2867 11590 $perfect_score += $perfect_component_score;
2868 }
2869 else
2870 {
2871 # Penalize for abbreviation mismatch
2872 2560 ▶ my $component_penalty = 3 + ( ( $expected_length->[0] > $pattern_components->{ $alias }->{len} ) ? ( $expected_length->[0] - $pattern_components->{ $alias }->{len} ) : ( $pattern_components->{ $alias }->{len} - $expected_length->[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
$expected_length->[0] > $pattern_components->{$alias}{'len'} ? : 0 2560 2560
2873 2560 $score -= $component_penalty;
2874 2560 $need_adjustment++;
2875 }
2876 }
2877 else
2878 {
2879 # Exact length match (e.g., MMM, EEEE)
2880 15298 ▶ if( $pattern_components->{ $alias }->{len} == $expected_length )
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_components->{$alias}{'len'} == $expected_length) { } 9273 6025 15298
2881 {
2882 # Reward for exact match
2883 9273 $score += 5;
2884 9273 $perfect_score += $perfect_component_score;
2885 }
2886 else
2887 {
2888 # Penalize for mismatched length (e.g., MMM instead of MMMM or MM)
2889 6025 ▶ my $component_penalty = 3 + ( ( $expected_length > $pattern_components->{ $alias }->{len} ) ? ( $expected_length - $pattern_components->{ $alias }->{len} ) : ( $pattern_components->{ $alias }->{len} - $expected_length ) );
Branch: 1 branch
BranchTrueFalseTotal
$expected_length > $pattern_components->{$alias}{'len'} ? : 3323 2702 6025
2890 6025 $score -= $component_penalty;
2891 6025 $need_adjustment++;
2892 }
2893 }
2894 }
2895 # Requested component is missing, penalising this pattern
2896 else
2897 {
2898 47597 push( @$missing, $alias );
2899 # my $component_penalty = ( $components_weight->{ $alias }->{weight} || 10 );
2900 47597 my $component_penalty = 12;
2901 47597 $score -= $component_penalty;
2902 }
2903 }
2904  
2905 # Penalise for extra components in the pattern that were not requested
2906 27522 foreach my $component ( @$pattern_chars )
2907 {
2908 # Possible characters found in skeleton in CLDR data: [qw( B E G H M Q W Z c d h m s v w y )]
2909 # However, the DateTime::Format::Intl that implements the JavaScript Intl.DateTimeFormat does not support some components.
2910 # This is an unknown component, maybe W or Q, which is not an option component, i.e. a component derived from DateTimeFormat options
2911 82514 ▶ unless( exists( $components_weight->{ $component } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $components_weight->{$component}) 3506 79008 82514
2912 {
2913 # Cancel our perfect score
2914 3506 $perfect_score = 0;
2915 3506 $extra_component_penalty += 15;
2916 3506 next;
2917 }
2918  
2919 # This component is missing from our requested skeleton, but is also absent from the current pattern skeleton, so this is forgivable.
2920 79008 ▶ if( !exists( $components_length->{ $component } ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $components_length->{$component} || exists $skeleton_components->{$component}) { } 795 78213 79008
elsif (not exists $components_length->{$component}) { } 47676 30537 78213
Condition100%3/3
exists $components_length->{$component} || exists $skeleton_components->{$component}
l!l&&r!l&&!r
3053747676795
MC/DC100%2/2
exists $components_length->{$component} || exists $skeleton_components->{$component}
exists $components_length->{$component} exists $skeleton_components->{$component}
Truth table100%3/3
A || B
A= exists $components_length->{$component}B= exists $skeleton_components->{$component}
ABresult
1X1
011
000
2921 !exists( $skeleton_components->{ $component } ) )
2922 {
2923 795 next;
2924 }
2925 # This component is not among our requested component
2926 elsif( !exists( $components_length->{ $component } ) )
2927 {
2928 # "Patterns and skeletons for 24-hour-cycle time formats (using H or k) currently should not include fields with day period components (a, b, or B); these pattern components should be ignored if they appear in skeletons. However, in the future, CLDR may allow use of B (but not a or b) in 24-hour-cycle time formats."
2929 # <https://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems>
2930 # We increase penalty if the rule aforementioned materialise.
2931 47676 my $augmented_penalty = 2;
2932 47676 ▶ if( exists( $opts->{hourCycle} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'hourCycle'} and $opts->{'hourCycle'} eq 'h23' || $opts->{'hourCycle'} eq 'h24' and $component eq 'a' || $component eq 'b' || $component eq 'B') { } 210 47466 47676
elsif ($component eq 'S' and exists $opts->{'second'}) { } 0 94932 94932
Condition80%12/15
exists $opts->{"hourCycle"} and $opts->{"hourCycle"} eq "h23" || $opts->{"hourCycle"} eq "h24" and $component eq "a" || $component eq "b" || $component eq "B"
!ll&&!rl&&r
417055761210
exists $opts->{"hourCycle"} and $opts->{"hourCycle"} eq "h23" || $opts->{"hourCycle"} eq "h24"
!ll&&!rl&&r
23718179875971
$opts->{"hourCycle"} eq "h23" or $opts->{"hourCycle"} eq "h24"
l!l&&r!l&&!r
142582917987
$component eq "a" or $component eq "b" or $component eq "B"
l!l&&r!l&&!r
02105761
$component eq "a" or $component eq "b"
l!l&&r!l&&!r
005971
MC/DC66%4/6
exists $opts->{"hourCycle"} and $opts->{"hourCycle"} eq "h23" || $opts->{"hourCycle"} eq "h24" and $component eq "a" || $component eq "b" || $component eq "B"
exists $opts->{"hourCycle"} $opts->{"hourCycle"} eq "h23" $opts->{"hourCycle"} eq "h24" $component eq "a" $component eq "b" $component eq "B"
Truth table60%6/10
A and B or C and D or E or F
A= exists $opts->{"hourCycle"}B= $opts->{"hourCycle"} eq "h23"C= $opts->{"hourCycle"} eq "h24"D= $component eq "a"E= $component eq "b"F= $component eq "B"
ABCDEFresult
0XXXXX0
100XXX0
11X0000
1010000
11X1XX1
11X01X1
11X0011
1011XX1
10101X1
1010011
2933 # H or k
2934 ( $opts->{hourCycle} eq 'h23' || $opts->{hourCycle} eq 'h24' ) &&
2935 ( $component eq 'a' || $component eq 'b' || $component eq 'B' ) )
2936 {
2937 210 $augmented_penalty = 10;
2938 }
2939 # "A requested skeleton that includes both seconds and fractional seconds (e.g. “mmssSSS”) is allowed to match a dateFormatItem skeleton that includes seconds but not fractional seconds (e.g. “ms”)."
2940 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
2941 # Although the above rule never happens, as of now (2024-09-29), in the current CLDR data (v35), we implement it anyway.
2942 ▶ elsif( $component eq 'S' &&
Condition33%1/3
$component eq "S" and exists $opts->{"second"}
!ll&&!rl&&r
4746600
MC/DC0%0/2
$component eq "S" and exists $opts->{"second"}
$component eq "S" exists $opts->{"second"}
Truth table33%1/3
A and B
A= $component eq "S"B= exists $opts->{"second"}
ABresult
0X0
100
111
2943 exists( $opts->{second} ) )
2944 {
2945 0 next;
2946 }
2947 47676 ▶ $augmented_penalty += ( $components_weight->{ $component }->{penalty} || 15 );
Condition50%1/2
$components_weight->{$component}{'penalty'} || 15
l!l
476760
MC/DC0%0/1
$components_weight->{$component}{'penalty'} || 15
$components_weight->{$component}{'penalty'}
Truth table50%1/2
A
A= $components_weight->{$component}{'penalty'}
Aresult
11
00
2948 # Penalise extra components
2949 47676 $extra_component_penalty += $augmented_penalty;
2950 # Cancel our perfect score
2951 47676 $perfect_score = 0;
2952 }
2953 }
2954  
2955 # Adjust the final score
2956 # Penalise for extra components
2957 27522 $score -= $extra_component_penalty;
2958 27522 ▶ if( $perfect_score == ( scalar( @$requested_tokens ) * $perfect_component_score ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($perfect_score == scalar(@$requested_tokens) * $perfect_component_score) 527 26995 27522
2959 {
2960 527 $score += $perfect_score;
2961 }
2962  
2963 # Adjust score based on specific options (e.g., hour cycle)
2964 27522 ▶ if( exists( $opts->{hourCycle} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"hourCycle"}) 12093 15429 27522
2965 {
2966 12093 ▶ if( $opts->{hourCycle} eq 'h12'
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'hourCycle'} eq 'h12' and index($pattern_skeleton, 'h') != -1) { } 2049 10044 12093
elsif ($opts->{'hourCycle'} eq 'h24' and index($pattern_skeleton, 'H') != -1) { } 324 17244 17568
Condition100%3/3
$opts->{"hourCycle"} eq "h12" and index($pattern_skeleton, "h") != -1
!ll&&!rl&&r
259274522049
MC/DC100%2/2
$opts->{"hourCycle"} eq "h12" and index($pattern_skeleton, "h") != -1
$opts->{"hourCycle"} eq "h12" index($pattern_skeleton, "h") != -1
Truth table100%3/3
A and B
A= $opts->{"hourCycle"} eq "h12"B= index($pattern_skeleton, "h") != -1
ABresult
0X0
100
111
2967 && index( $pattern_skeleton, 'h' ) != -1 )
2968 {
2969 2049 $score += 5;
2970 }
2971 ▶ elsif( $opts->{hourCycle} eq 'h24' &&
Condition100%3/3
$opts->{"hourCycle"} eq "h24" and index($pattern_skeleton, "H") != -1
!ll&&!rl&&r
75242196324
MC/DC100%2/2
$opts->{"hourCycle"} eq "h24" and index($pattern_skeleton, "H") != -1
$opts->{"hourCycle"} eq "h24" index($pattern_skeleton, "H") != -1
Truth table100%3/3
A and B
A= $opts->{"hourCycle"} eq "h24"B= index($pattern_skeleton, "H") != -1
ABresult
0X0
100
111
2972 index( $pattern_skeleton, 'H' ) != -1 )
2973 {
2974 324 $score += 5;
2975 }
2976 }
2977 27522 ▶ my $result = $self->_new_score_result(
Condition50%1/2
$self->_new_score_result('missing', $missing, 'need_adjustment', $need_adjustment, 'pattern_object', $pattern_object, 'request_object', $request_object, 'score', $score) || (return $self->pass_error)
l!l
275220
MC/DC0%0/1
$self->_new_score_result('missing', $missing, 'need_adjustment', $need_adjustment, 'pattern_object', $pattern_object, 'request_object', $request_object, 'score', $score) || (return $self->pass_error)
$self->_new_score_result('missing', $missing, 'need_adjustment', $need_adjustment, 'pattern_object', $pattern_object, 'request_object', $request_object, 'score', $score)
Truth table50%1/2
A
A= $self->_new_score_result('missing', $missing, 'need_adjustment', $need_adjustment, 'pattern_object', $pattern_object, 'request_object', $request_object, 'score', $score)
Aresult
11
00
2978 missing => $missing,
2979 need_adjustment => $need_adjustment,
2980 pattern_object => $pattern_object,
2981 request_object => $request_object,
2982 score => $score,
2983 ) || return( $self->pass_error );
2984 27522 return( $result );
2985 }
2986  
2987 # Select the best pattern from available patterns
2988 sub _select_best_pattern
2989 551 ▶{
Subroutine _select_best_pattern: called CC=57 SCAR=41.9
2990 551 my $self = shift( @_ );
2991 551 my $args = $self->_get_args_as_hash( @_ );
2992 my $available_patterns = $args->{patterns} ||
2993 551 ▶ return( $self->error( "No patterns provided." ) );
Condition50%1/2
$args->{'patterns'} || (return $self->error('No patterns provided.'))
l!l
5510
MC/DC0%0/1
$args->{'patterns'} || (return $self->error('No patterns provided.'))
$args->{'patterns'}
Truth table50%1/2
A
A= $args->{'patterns'}
Aresult
11
00
2994 my $opts = $args->{options} ||
2995 551 ▶ return( $self->error( "No options was provided." ) );
Condition50%1/2
$args->{'options'} || (return $self->error('No options was provided.'))
l!l
5510
MC/DC0%0/1
$args->{'options'} || (return $self->error('No options was provided.'))
$args->{'options'}
Truth table50%1/2
A
A= $args->{'options'}
Aresult
11
00
2996 # If we are called by format_range()
2997 551 my $diff = $args->{diff};
2998  
2999 # Convert user options to a skeleton (an abstracted form of the requested options)
3000 551 ▶ my $request_object = $self->_new_request_object(
Branch: 1 branch
BranchTrueFalseTotal
defined $diff ? : 216 335 551
Condition50%1/2
$self->_new_request_object('options', $opts, defined $diff ? ('diff', $diff) : ()) || (return $self->pass_error)
l!l
5510
MC/DC0%0/1
$self->_new_request_object('options', $opts, defined $diff ? ('diff', $diff) : ()) || (return $self->pass_error)
$self->_new_request_object('options', $opts, defined $diff ? ('diff', $diff) : ())
Truth table50%1/2
A
A= $self->_new_request_object('options', $opts, defined $diff ? ('diff', $diff) : ())
Aresult
11
00
3001 options => $opts,
3002 ( defined( $diff ) ? ( diff => $diff ) : () ),
3003 ) || return( $self->pass_error );
3004 551 my $requested_skeleton = $request_object->pattern_skeleton;
3005 551 my @sorted_available_skeletons = sort{ length( $a ) <=> length( $b ) } sort( keys( %$available_patterns ) );
3006 551 my $requested_skeleton_len = length( $requested_skeleton );
3007 551 ▶ for( my $i = 0; $i < scalar( @sorted_available_skeletons ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @sorted_available_skeletons) 12513 35 12548
3008 {
3009 # If the next skeleton is equal of greater in length as our requested skeleton, we
3010 # take all the ones before it and place it at the end of the stack, so we deal with them last,
3011 # and thus avoid wasting processing power on pattern that have little chance of being satisfactory.
3012 12513 ▶ if( $i <= $#sorted_available_skeletons &&
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#sorted_available_skeletons and length $sorted_available_skeletons[$i] >= $requested_skeleton_len) 516 11997 12513
Condition66%2/3
$i <= $#sorted_available_skeletons and length $sorted_available_skeletons[$i] >= $requested_skeleton_len
!ll&&!rl&&r
011997516
MC/DC50%1/2
$i <= $#sorted_available_skeletons and length $sorted_available_skeletons[$i] >= $requested_skeleton_len
$i <= $#sorted_available_skeletons length $sorted_available_skeletons[$i] >= $requested_skeleton_len
Truth table66%2/3
A and B
A= $i <= $#sorted_available_skeletonsB= length $sorted_available_skeletons[$i] >= $requested_skeleton_len
ABresult
0X0
100
111
3013 length( $sorted_available_skeletons[$i] ) >= $requested_skeleton_len )
3014 {
3015 # push( @sorted_available_skeletons, splice( @sorted_available_skeletons, 0, $i ) );
3016 516 ▶ push( @sorted_available_skeletons, splice( @sorted_available_skeletons, 0, ( $i - 1 ) ) ) if( $i > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 463 53 516
3017 516 last;
3018 }
3019 }
3020  
3021  
3022 551 ▶ my( $components_len, $components_weight, $components_alias ) = $self->_get_option_dictionary(
Branch: 1 branch
BranchTrueFalseTotal
defined $diff ? : 216 335 551
3023 options => $opts,
3024 ( defined( $diff ) ? ( diff => $diff ) : () ),
3025 );
3026 551 ▶ return( $self->pass_error ) if( !defined( $components_len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $components_len 0 551 551
3027 551 $self->{_components_length} = $components_len;
3028 551 $self->{_components_weight} = $components_weight;
3029 551 $self->{_components_alias} = $components_alias;
3030  
3031 551 my $best_pattern;
3032 # Same as in _score_pattern(); maybe should make it a module constant ? Maybe overkill ?
3033 551 my $perfect_component_score = 100;
3034 551 my $best_score = -1;
3035 # Merely for tracking and reporting
3036 551 my( $best_skeleton, $best_score_object );
3037 551 foreach my $skeleton ( @sorted_available_skeletons )
3038 {
3039 27522 my $pattern = $available_patterns->{ $skeleton };
3040 # Handle literal text inside single quotes
3041 27522 ▶ my $raw_pattern = $self->_remove_literal_text( $pattern ) ||
Condition50%1/2
$self->_remove_literal_text($pattern) || (return $self->pass_error)
l!l
275220
MC/DC0%0/1
$self->_remove_literal_text($pattern) || (return $self->pass_error)
$self->_remove_literal_text($pattern)
Truth table50%1/2
A
A= $self->_remove_literal_text($pattern)
Aresult
11
00
3042 return( $self->pass_error );
3043  
3044 # Generate a skeleton from the available pattern
3045 27522 ▶ my $pattern_skeleton = $self->_pattern_to_skeleton( $raw_pattern ) ||
Condition50%1/2
$self->_pattern_to_skeleton($raw_pattern) || (return $self->pass_error)
l!l
275220
MC/DC0%0/1
$self->_pattern_to_skeleton($raw_pattern) || (return $self->pass_error)
$self->_pattern_to_skeleton($raw_pattern)
Truth table50%1/2
A
A= $self->_pattern_to_skeleton($raw_pattern)
Aresult
11
00
3046 return( $self->pass_error );
3047 27522 ▶ my $pattern_object = $self->_new_skeleton_object(
Condition50%1/2
$self->_new_skeleton_object('skeleton', $skeleton, 'pattern_skeleton', $pattern_skeleton, 'pattern', $pattern, 'debug', $DateTime::Format::Intl::DEBUG) || (return $self->pass_error)
l!l
275220
MC/DC0%0/1
$self->_new_skeleton_object('skeleton', $skeleton, 'pattern_skeleton', $pattern_skeleton, 'pattern', $pattern, 'debug', $DateTime::Format::Intl::DEBUG) || (return $self->pass_error)
$self->_new_skeleton_object('skeleton', $skeleton, 'pattern_skeleton', $pattern_skeleton, 'pattern', $pattern, 'debug', $DateTime::Format::Intl::DEBUG)
Truth table50%1/2
A
A= $self->_new_skeleton_object('skeleton', $skeleton, 'pattern_skeleton', $pattern_skeleton, 'pattern', $pattern, 'debug', $DateTime::Format::Intl::DEBUG)
Aresult
11
00
3048 # Original skeleton provided by CLDR
3049 skeleton => $skeleton,
3050 # Skeleton derived from the format pattern
3051 pattern_skeleton => $pattern_skeleton,
3052 # Actual pattern for this format ID
3053 pattern => $pattern,
3054 debug => $DEBUG,
3055 ) || return( $self->pass_error );
3056  
3057  
3058 # Score how well the pattern matches the user's options
3059 27522 ▶ my $score_object = $self->_score_pattern(
Condition50%1/2
$self->_score_pattern('request_object', $request_object, 'pattern_object', $pattern_object, 'options', $opts) || (return $self->pass_error)
l!l
275220
MC/DC0%0/1
$self->_score_pattern('request_object', $request_object, 'pattern_object', $pattern_object, 'options', $opts) || (return $self->pass_error)
$self->_score_pattern('request_object', $request_object, 'pattern_object', $pattern_object, 'options', $opts)
Truth table50%1/2
A
A= $self->_score_pattern('request_object', $request_object, 'pattern_object', $pattern_object, 'options', $opts)
Aresult
11
00
3060 request_object => $request_object,
3061 pattern_object => $pattern_object,
3062 options => $opts,
3063 ) || return( $self->pass_error );
3064 27522 my $score = $score_object->score;
3065
3066
3067 # If the score is higher, update the best pattern
3068 27522 ▶ if( $score > $best_score )
Branch: 1 branch
BranchTrueFalseTotal
if ($score > $best_score) 1065 26457 27522
3069 {
3070 1065 $best_pattern = $pattern;
3071 1065 $best_score = $score;
3072 1065 $best_skeleton = $skeleton;
3073 1065 $best_score_object = $score_object;
3074 }
3075  
3076  
3077 # If the pattern score is equal or higher than the perfect component score, we got a perfect match and we stop checking.
3078 27522 ▶ if( $score > $perfect_component_score )
Branch: 1 branch
BranchTrueFalseTotal
if ($score > $perfect_component_score) 527 26995 27522
3079 {
3080 # Actually, we keep going, because we could find another perfect match
3081 # last;
3082 }
3083 }
3084  
3085 # No perfect match, and this is a singleton, most likely something that has no equivalent among the available patterns.
3086 # If so, the requested skeleton in itself is our perfect match
3087 551 ▶ my $request_tokens = $request_object->tokens || die( "No request tokens array reference set!" );
Condition50%1/2
$request_object->tokens || die('No request tokens array reference set!')
l!l
5510
MC/DC0%0/1
$request_object->tokens || die('No request tokens array reference set!')
$request_object->tokens
Truth table50%1/2
A
A= $request_object->tokens
Aresult
11
00
3088 551 ▶ if( $best_score < $perfect_component_score &&
Branch: 2 branches
BranchTrueFalseTotal
if ($best_score < $perfect_component_score and scalar @$request_tokens == 1 and not exists $$available_patterns{$request_tokens->[0]{'token'}} and not exists $$available_patterns{$request_tokens->[0]{'component'}}) { } 2 549 551
elsif ($best_score >= 0 && scalar @{$best_score_object->missing // [];} || $best_score < 0 and scalar @{$request_object->date_components // [];} and scalar @{$request_object->time_components // [];} and not $diff and not $args->{'subprocess'}) { } 20 1058 1078
Condition88%8/9
$best_score < $perfect_component_score and scalar @$request_tokens == 1 and not exists $$available_patterns{$request_tokens->[0]{"token"}} and not exists $$available_patterns{$request_tokens->[0]{"component"}}
!ll&&!rl&&r
54272
$best_score < $perfect_component_score and scalar @$request_tokens == 1 and not exists $$available_patterns{$request_tokens->[0]{"token"}}
!ll&&!rl&&r
54209
$best_score < $perfect_component_score and scalar @$request_tokens == 1
!ll&&!rl&&r
500429
MC/DC75%3/4
$best_score < $perfect_component_score and scalar @$request_tokens == 1 and not exists $$available_patterns{$request_tokens->[0]{"token"}} and not exists $$available_patterns{$request_tokens->[0]{"component"}}
$best_score < $perfect_component_score scalar @$request_tokens == 1 not exists $$available_patterns{$request_tokens->[0]{"token"}} not exists $$available_patterns{$request_tokens->[0]{"component"}}
Truth table80%4/5
A and B and not(C) and not(D)
A= $best_score < $perfect_component_scoreB= scalar @$request_tokens == 1C= not exists $$available_patterns{$request_tokens->[0]{"token"}}D= not exists $$available_patterns{$request_tokens->[0]{"component"}}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3089 scalar( @$request_tokens ) == 1 &&
3090 !exists( $available_patterns->{ $request_tokens->[0]->{token} } ) &&
3091 !exists( $available_patterns->{ $request_tokens->[0]->{component} } ) )
3092 {
3093 2 $best_score += $perfect_component_score;
3094 2 ▶ $best_skeleton = $best_pattern = ( $request_tokens->[0]->{component} x ( ref( $components_len->{ $request_tokens->[0]->{component} } ) eq 'ARRAY' ? $components_len->{ $request_tokens->[0]->{component} }->[0] : $components_len->{ $request_tokens->[0]->{component} } ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $$components_len{$request_tokens->[0]{'component'}} eq 'ARRAY' ? : 0 2 2
3095 2 $request_object->pattern( $best_pattern );
3096 2 $request_object->skeleton( $best_skeleton );
3097 2 ▶ $best_score_object = $self->_new_score_result(
Condition50%1/2
$self->_new_score_result('pattern_object', $request_object, 'request_object', $request_object, 'score', $best_score) || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->_new_score_result('pattern_object', $request_object, 'request_object', $request_object, 'score', $best_score) || (return $self->pass_error)
$self->_new_score_result('pattern_object', $request_object, 'request_object', $request_object, 'score', $best_score)
Truth table50%1/2
A
A= $self->_new_score_result('pattern_object', $request_object, 'request_object', $request_object, 'score', $best_score)
Aresult
11
00
3098 pattern_object => $request_object,
3099 request_object => $request_object,
3100 score => $best_score,
3101 ) || return( $self->pass_error );
3102 2 return( $best_score_object );
3103 }
3104 # Quoting from the LDML specifications:
3105 # "If a client-requested set of fields includes both date and time fields, and if the availableFormats data does not include a dateFormatItem whose skeleton matches the same set of fields, then the request should be handled as follows:
3106 # 1. Divide the request into a date fields part and a time fields part.
3107 # 2. For each part, find the matching dateFormatItem, and expand the pattern as above.
3108 # 3. Combine the patterns for the two dateFormatItems using the appropriate dateTimeFormat pattern, determined as follows from the requested date fields:
3109 # * If the requested date fields include wide month (MMMM, LLLL) and weekday name of any length (e.g. E, EEEE, c, cccc), use <dateTimeFormatLength type="full">
3110 # * Otherwise, if the requested date fields include wide month, use <dateTimeFormatLength type="long">
3111 # * Otherwise, if the requested date fields include abbreviated month (MMM, LLL), use <dateTimeFormatLength type="medium">
3112 # * Otherwise use <dateTimeFormatLength type="short">"
3113 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Missing_Skeleton_Fields>
3114 ▶ elsif( (
Condition86%13/15
$best_score >= 0 && scalar @{$best_score_object->missing // [];} || $best_score < 0 and scalar @{$request_object->date_components // [];} and scalar @{$request_object->time_components // [];} and not $diff and not $args->{"subprocess"}
!ll&&!rl&&r
529020
$best_score >= 0 && scalar @{$best_score_object->missing // [];} || $best_score < 0 and scalar @{$request_object->date_components // [];} and scalar @{$request_object->time_components // [];} and not $diff
!ll&&!rl&&r
529020
$best_score >= 0 && scalar @{$best_score_object->missing // [];} || $best_score < 0 and scalar @{$request_object->date_components // [];} and scalar @{$request_object->time_components // [];}
!ll
52623
$best_score >= 0 && scalar @{$best_score_object->missing // [];} || $best_score < 0 and scalar @{$request_object->date_components // [];}
!ll
52623
$best_score >= 0 and scalar @{$best_score_object->missing // [];} or $best_score < 0
l!l&&r!l&&!r
212526
$best_score >= 0 and scalar @{$best_score_object->missing // [];}
!ll
2547
MC/DC0%0/4
$best_score >= 0 && scalar @{$best_score_object->missing // [];} || $best_score < 0 and scalar @{$request_object->date_components // [];} and scalar @{$request_object->time_components // [];} and not $diff and not $args->{"subprocess"}
$best_score >= 0 $best_score < 0 not $diff not $args->{"subprocess"}
Truth table28%2/7
A or B and not(C) and not(D)
A= $best_score >= 0B= $best_score < 0C= not $diffD= not $args->{"subprocess"}
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
3115 547 ▶ ( $best_score >= 0 && scalar( @{$best_score_object->missing // []} ) ) ||
Condition50%1/2
$best_score_object->missing // []
l!l
5470
MC/DC0%0/1
$best_score_object->missing // []
$best_score_object->missing
Truth table50%1/2
A
A= $best_score_object->missing
Aresult
11
00
3116 $best_score < 0
3117 ) &&
3118 23 ▶ scalar( @{$request_object->date_components // []} ) &&
Condition50%1/2
$request_object->date_components // []
l!l
230
MC/DC0%0/1
$request_object->date_components // []
$request_object->date_components
Truth table50%1/2
A
A= $request_object->date_components
Aresult
11
00
3119 23 ▶ scalar( @{$request_object->time_components // []} ) &&
Condition50%1/2
$request_object->time_components // []
l!l
230
MC/DC0%0/1
$request_object->time_components // []
$request_object->time_components
Truth table50%1/2
A
A= $request_object->time_components
Aresult
11
00
3120 !$diff &&
3121 !$args->{subprocess} )
3122 {
3123 20 my @core_options = qw( calendar hour12 hourCycle locale numberingSystem timeZone );
3124 20 my @date_options = ( qw( era year month weekday day ), @core_options );
3125 20 my @time_options = ( qw( hour minute second timeZoneName ), @core_options );
3126 # "1. Divide the request into a date fields part and a time fields part."
3127 20 my $date_opts = +{ map{ $_ => $opts->{ $_ } } grep( exists( $opts->{ $_ } ), @date_options ) };
3128 20 my $time_opts = +{ map{ $_ => $opts->{ $_ } } grep( exists( $opts->{ $_ } ), @time_options ) };
3129 # "2. For each part, find the matching dateFormatItem, and expand the pattern as above."
3130 20 my $date_score_object = $self->_select_best_pattern(
3131 options => $date_opts,
3132 patterns => $available_patterns,
3133 # To avoid risk of recurring calls, we tag it
3134 subprocess => 1,
3135 );
3136 20 my $date_pat = $date_score_object->pattern_object->pattern;
3137 20 my $date_skel = $date_score_object->pattern_object->skeleton;
3138 20 ▶ my $has_missing_date_components = scalar( @{$date_score_object->missing // []} );
Condition50%1/2
$date_score_object->missing // []
l!l
200
MC/DC0%0/1
$date_score_object->missing // []
$date_score_object->missing
Truth table50%1/2
A
A= $date_score_object->missing
Aresult
11
00
3139 #
3140 # # If the result has some missing components, we need to add them
3141 # if( $has_missing_date_components )
3142 # {
3143 # $date_pat = $self->_append_components(
3144 # pattern => $date_pat,
3145 # missing => $date_score_object->missing,
3146 # );
3147 # }
3148  
3149 20 my $time_score_object = $self->_select_best_pattern(
3150 options => $time_opts,
3151 patterns => $available_patterns,
3152 # To avoid risk of recurring calls, we tag it
3153 subprocess => 1,
3154 );
3155 20 my $time_pat = $time_score_object->pattern_object->pattern;
3156 20 my $time_skel = $time_score_object->pattern_object->skeleton;
3157 20 ▶ my $has_missing_time_components = scalar( @{$time_score_object->missing // []} );
Condition50%1/2
$time_score_object->missing // []
l!l
200
MC/DC0%0/1
$time_score_object->missing // []
$time_score_object->missing
Truth table50%1/2
A
A= $time_score_object->missing
Aresult
11
00
3158 # 3. Combine the patterns for the two dateFormatItems using the appropriate dateTimeFormat pattern, determined as follows from the requested date fields:
3159 # * If the requested date fields include wide month (MMMM, LLLL) and weekday name of any length (e.g. E, EEEE, c, cccc), use <dateTimeFormatLength type="full">
3160 # * Otherwise, if the requested date fields include wide month, use <dateTimeFormatLength type="long">
3161 # * Otherwise, if the requested date fields include abbreviated month (MMM, LLL), use <dateTimeFormatLength type="medium">
3162 # * Otherwise use <dateTimeFormatLength type="short">"
3163 20 my $datetime_format_width;
3164 20 ▶ if( exists( $components_len->{'M'} ) &&
Branch: 3 branches
BranchTrueFalseTotal
if (exists $components_len->{'M'} and $components_len->{'M'} == 4 and exists $components_len->{'E'}) { } 6 14 20
elsif (exists $components_len->{'M'} and $components_len->{'M'} == 4) { } 4 10 14
elsif (exists $components_len->{'M'} and $components_len->{'M'} == 3) { } 4 6 10
Condition83%5/6
exists $components_len->{"M"} and $components_len->{"M"} == 4 and exists $components_len->{"E"}
!ll&&!rl&&r
1046
exists $components_len->{"M"} and $components_len->{"M"} == 4
!ll&&!rl&&r
01010
MC/DC66%2/3
exists $components_len->{"M"} and $components_len->{"M"} == 4 and exists $components_len->{"E"}
exists $components_len->{"M"} $components_len->{"M"} == 4 exists $components_len->{"E"}
Truth table75%3/4
A and B and C
A= exists $components_len->{"M"}B= $components_len->{"M"} == 4C= exists $components_len->{"E"}
ABCresult
0XX0
10X0
1100
1111
3165 # wide
3166 $components_len->{'M'} == 4 &&
3167 # any length, so we do not have to check the length
3168 exists( $components_len->{'E'} ) )
3169 {
3170 6 $datetime_format_width = 'full';
3171 }
3172 ▶ elsif( exists( $components_len->{'M'} ) &&
Condition66%2/3
exists $components_len->{"M"} and $components_len->{"M"} == 4
!ll&&!rl&&r
0104
MC/DC50%1/2
exists $components_len->{"M"} and $components_len->{"M"} == 4
exists $components_len->{"M"} $components_len->{"M"} == 4
Truth table66%2/3
A and B
A= exists $components_len->{"M"}B= $components_len->{"M"} == 4
ABresult
0X0
100
111
3173 # wide
3174 $components_len->{'M'} == 4 )
3175 {
3176 4 $datetime_format_width = 'long';
3177 }
3178 ▶ elsif( exists( $components_len->{'M'} ) &&
Condition66%2/3
exists $components_len->{"M"} and $components_len->{"M"} == 3
!ll&&!rl&&r
064
MC/DC50%1/2
exists $components_len->{"M"} and $components_len->{"M"} == 3
exists $components_len->{"M"} $components_len->{"M"} == 3
Truth table66%2/3
A and B
A= exists $components_len->{"M"}B= $components_len->{"M"} == 3
ABresult
0X0
100
111
3179 # abbreviated
3180 $components_len->{'M'} == 3 )
3181 {
3182 4 $datetime_format_width = 'medium';
3183 }
3184 else
3185 {
3186 6 $datetime_format_width = 'short';
3187 }
3188 20 my $datetime_format = $self->_get_datetime_format(
3189 width => $datetime_format_width,
3190 );
3191 20 ▶ return( $self->pass_error ) if( !defined( $datetime_format ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $datetime_format 0 20 20
3192 20 my $datetime_skel = $datetime_format;
3193 20 $datetime_format =~ s/\{1\}/$date_pat/;
3194 20 $datetime_format =~ s/\{0\}/$time_pat/;
3195 20 $datetime_skel =~ s/\{1\}/$date_skel/;
3196 20 $datetime_skel =~ s/\{0\}/$time_skel/;
3197 20 ▶ my $raw_pattern = $self->_remove_literal_text( $datetime_format ) ||
Condition50%1/2
$self->_remove_literal_text($datetime_format) || (return $self->pass_error)
l!l
200
MC/DC0%0/1
$self->_remove_literal_text($datetime_format) || (return $self->pass_error)
$self->_remove_literal_text($datetime_format)
Truth table50%1/2
A
A= $self->_remove_literal_text($datetime_format)
Aresult
11
00
3198 return( $self->pass_error );
3199 20 ▶ my $pattern_object = $self->_new_skeleton_object(
Condition50%1/2
$self->_new_skeleton_object('pattern', $datetime_format, 'skeleton', $datetime_skel, 'pattern_skeleton', $self->_pattern_to_skeleton($raw_pattern), 'debug', $DateTime::Format::Intl::DEBUG) || (return $self->pass_error)
l!l
200
MC/DC0%0/1
$self->_new_skeleton_object('pattern', $datetime_format, 'skeleton', $datetime_skel, 'pattern_skeleton', $self->_pattern_to_skeleton($raw_pattern), 'debug', $DateTime::Format::Intl::DEBUG) || (return $self->pass_error)
$self->_new_skeleton_object('pattern', $datetime_format, 'skeleton', $datetime_skel, 'pattern_skeleton', $self->_pattern_to_skeleton($raw_pattern), 'debug', $DateTime::Format::Intl::DEBUG)
Truth table50%1/2
A
A= $self->_new_skeleton_object('pattern', $datetime_format, 'skeleton', $datetime_skel, 'pattern_skeleton', $self->_pattern_to_skeleton($raw_pattern), 'debug', $DateTime::Format::Intl::DEBUG)
Aresult
11
00
3200 pattern => $datetime_format,
3201 skeleton => $datetime_skel,
3202 pattern_skeleton => $self->_pattern_to_skeleton( $raw_pattern ),
3203 debug => $DEBUG,
3204 ) || return( $self->pass_error );
3205 20 ▶ $best_score_object = $self->_new_score_result(
Branch: 2 branches
BranchTrueFalseTotal
defined $best_score_object ? : 18 2 20
$date_score_object->need_adjustment || $time_score_object->need_adjustment ? : 17 3 20
Condition80%4/5
$self->_new_score_result('score', defined $best_score_object ? $best_score_object->score : _max($date_score_object->score, $time_score_object->score), 'pattern_object', $pattern_object, 'request_object', $request_object, 'need_adjustment', $date_score_object->need_adjustment || $time_score_object->need_adjustment ? 1 : 0) || (return $self->pass_error)
l!l
200
$date_score_object->need_adjustment or $time_score_object->need_adjustment
l!l&&r!l&&!r
893
MC/DC0%0/1
$self->_new_score_result('score', defined $best_score_object ? $best_score_object->score : _max($date_score_object->score, $time_score_object->score), 'pattern_object', $pattern_object, 'request_object', $request_object, 'need_adjustment', $date_score_object->need_adjustment || $time_score_object->need_adjustment ? 1 : 0) || (return $self->pass_error)
$self->_new_score_result('score', defined $best_score_object ? $best_score_object->score : _max($date_score_object->score, $time_score_object->score), 'pattern_object', $pattern_object, 'request_object', $request_object, 'need_adjustment', $date_score_object->need_adjustment || $time_score_object->need_adjustment ? 1 : 0)
MC/DC100%2/2
$date_score_object->need_adjustment or $time_score_object->need_adjustment
$date_score_object->need_adjustment $time_score_object->need_adjustment
Truth table50%1/2
A
A= $self->_new_score_result('score', defined $best_score_object ? $best_score_object->score : _max($date_score_object->score, $time_score_object->score), 'pattern_object', $pattern_object, 'request_object', $request_object, 'need_adjustment', $date_score_object->need_adjustment || $time_score_object->need_adjustment ? 1 : 0)
Aresult
11
00
Truth table100%3/3
A or B
A= $date_score_object->need_adjustmentB= $time_score_object->need_adjustment
ABresult
1X1
011
000
3206 score => ( defined( $best_score_object ) ? $best_score_object->score : _max( $date_score_object->score, $time_score_object->score ) ),
3207 pattern_object => $pattern_object,
3208 request_object => $request_object,
3209 need_adjustment => ( ( $date_score_object->need_adjustment || $time_score_object->need_adjustment ) ? 1 : 0 ),
3210 ) || return( $self->pass_error );
3211 20 return( $best_score_object );
3212 }
3213
3214 529 my $has_missing_components = $best_score_object->has_missing;
3215 # If the result has some missing components, we need to add them
3216 529 ▶ if( $has_missing_components )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_missing_components) 3 526 529
3217 {
3218 3 my $pattern = $self->_append_components(
3219 # pattern => $pattern,
3220 pattern => $best_score_object->pattern_object->pattern,
3221 missing => $best_score_object->missing,
3222 );
3223 3 $best_score_object->pattern_object->pattern( $pattern );
3224 3 ▶ return( $self->pass_error ) if( !defined( $pattern ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 3 3
3225 }
3226  
3227 # "Once a best match is found between requested skeleton and dateFormatItem id, the corresponding dateFormatItem pattern is used, but with adjustments primarily to make the pattern field lengths match the skeleton field lengths."
3228 # <https://www.unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons>
3229 # No need to bother calling this method, if there is no need for adjustment
3230 # We do not append components on a datetime range, so we check if this is one with the $diff variable
3231 529 ▶ if( !$diff && $best_score_object->need_adjustment )
Branch: 1 branch
BranchTrueFalseTotal
if (not $diff and $best_score_object->need_adjustment) 75 454 529
Condition100%3/3
not $diff and $best_score_object->need_adjustment
!ll&&!rl&&r
21623875
MC/DC100%2/2
not $diff and $best_score_object->need_adjustment
not $diff $best_score_object->need_adjustment
Truth table100%3/3
not(A) and B
A= not $diffB= $best_score_object->need_adjustment
ABresult
0X0
100
111
3232 {
3233 75 ▶ my $pattern = $self->_adjust_pattern(
Condition50%1/2
$self->_adjust_pattern('pattern', $best_score_object->pattern_object->pattern, 'options', $opts, 'request_object', $best_score_object->request_object, 'pattern_object', $best_score_object->pattern_object) || (return $self->pass_error)
l!l
750
MC/DC0%0/1
$self->_adjust_pattern('pattern', $best_score_object->pattern_object->pattern, 'options', $opts, 'request_object', $best_score_object->request_object, 'pattern_object', $best_score_object->pattern_object) || (return $self->pass_error)
$self->_adjust_pattern('pattern', $best_score_object->pattern_object->pattern, 'options', $opts, 'request_object', $best_score_object->request_object, 'pattern_object', $best_score_object->pattern_object)
Truth table50%1/2
A
A= $self->_adjust_pattern('pattern', $best_score_object->pattern_object->pattern, 'options', $opts, 'request_object', $best_score_object->request_object, 'pattern_object', $best_score_object->pattern_object)
Aresult
11
00
3234 # pattern => $pattern,
3235 pattern => $best_score_object->pattern_object->pattern,
3236 options => $opts,
3237 request_object => $best_score_object->request_object,
3238 pattern_object => $best_score_object->pattern_object,
3239 ) || return( $self->pass_error );
3240 75 $best_score_object->pattern_object->pattern( $pattern );
3241 }
3242  
3243 529 ▶ return( $self->error( "No suitable date pattern found for given options" ) ) unless( $best_pattern );
Branch: 1 branch
BranchTrueFalseTotal
unless $best_pattern 0 529 529
3244 529 return( $best_score_object );
3245 }
3246  
3247 sub _set_cached_pattern
3248 513 ▶{
Subroutine _set_cached_pattern: called CC=2 SCAR=6.9
3249 513 my $self = shift( @_ );
3250 513 my( $locale, $key, $pattern ) = @_;
3251 513 ▶ $CACHE->{ $locale } = {} if( !exists( $CACHE->{ $locale } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $DateTime::Format::Intl::CACHE->{$locale} 14 499 513
3252 513 $CACHE->{ $locale }->{ $key } = $pattern;
3253 }
3254  
3255 sub _set_get_prop
3256 884 ▶{
Subroutine _set_get_prop: called CC=3 SCAR=11.4
3257 884 my $self = shift( @_ );
3258 884 ▶ my $prop = shift( @_ ) || die( "No object property was provided." );
Condition50%1/2
shift @_ || die('No object property was provided.')
l!l
8840
MC/DC0%0/1
shift @_ || die('No object property was provided.')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3259 884 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 884 884
3260 884 return( $self->{ $prop } );
3261 }
3262  
3263 # NOTE: $BROWSER_DEFAULTS
3264 {
3265 11 $BROWSER_DEFAULTS =
3266 {
3267 af => {
3268 day => "2-digit",
3269 hour => "2-digit",
3270 minute => "2-digit",
3271 month => "2-digit",
3272 second => "2-digit",
3273 },
3274 "af-NA" => {
3275 day => "2-digit",
3276 minute => "2-digit",
3277 month => "2-digit",
3278 second => "2-digit",
3279 },
3280 agq => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3281 ak => { minute => "2-digit", second => "2-digit" },
3282 am => { minute => "2-digit", second => "2-digit" },
3283 ar => { minute => "2-digit", second => "2-digit" },
3284 "ar-IL" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3285 "ar-KM" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3286 "ar-MA" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3287 as => {
3288 day => "2-digit",
3289 minute => "2-digit",
3290 month => "2-digit",
3291 second => "2-digit",
3292 },
3293 asa => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3294 ast => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3295 az => {
3296 day => "2-digit",
3297 hour => "2-digit",
3298 minute => "2-digit",
3299 month => "2-digit",
3300 second => "2-digit",
3301 },
3302 "az-Cyrl" => {
3303 day => "2-digit",
3304 hour => "2-digit",
3305 minute => "2-digit",
3306 month => "2-digit",
3307 second => "2-digit",
3308 },
3309 bas => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3310 be => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3311 bem => { minute => "2-digit", second => "2-digit" },
3312 bez => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3313 bg => {
3314 hour => "2-digit",
3315 minute => "2-digit",
3316 month => "2-digit",
3317 second => "2-digit",
3318 },
3319 bgc => { minute => "2-digit", second => "2-digit" },
3320 bho => {
3321 day => "2-digit",
3322 minute => "2-digit",
3323 month => "2-digit",
3324 second => "2-digit",
3325 },
3326 bm => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3327 bn => { minute => "2-digit", second => "2-digit" },
3328 bo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3329 "bo-IN" => { minute => "2-digit", second => "2-digit" },
3330 br => {
3331 day => "2-digit",
3332 hour => "2-digit",
3333 minute => "2-digit",
3334 month => "2-digit",
3335 second => "2-digit",
3336 },
3337 brx => {
3338 day => "2-digit",
3339 minute => "2-digit",
3340 month => "2-digit",
3341 second => "2-digit",
3342 },
3343 bs => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3344 "bs-Cyrl" => {
3345 day => "2-digit",
3346 hour => "2-digit",
3347 minute => "2-digit",
3348 month => "2-digit",
3349 second => "2-digit",
3350 },
3351 ca => { minute => "2-digit", second => "2-digit" },
3352 ccp => { minute => "2-digit", second => "2-digit" },
3353 ceb => { minute => "2-digit", second => "2-digit" },
3354 cgg => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3355 chr => { minute => "2-digit", second => "2-digit" },
3356 ckb => { minute => "2-digit", second => "2-digit" },
3357 "ckb-IR" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3358 cs => { minute => "2-digit", second => "2-digit" },
3359 cv => {
3360 day => "2-digit",
3361 hour => "2-digit",
3362 minute => "2-digit",
3363 month => "2-digit",
3364 second => "2-digit",
3365 },
3366 cy => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3367 da => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3368 dav => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3369 de => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3370 dje => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3371 doi => { minute => "2-digit", second => "2-digit" },
3372 dsb => { minute => "2-digit", second => "2-digit" },
3373 dua => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3374 dyo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3375 dz => { minute => "2-digit", second => "2-digit" },
3376 ebu => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3377 ee => { minute => "2-digit", second => "2-digit" },
3378 "ee-TG" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3379 el => { minute => "2-digit", second => "2-digit" },
3380 en => { minute => "2-digit", second => "2-digit" },
3381 "en-001" => {
3382 day => "2-digit",
3383 minute => "2-digit",
3384 month => "2-digit",
3385 second => "2-digit",
3386 },
3387 "en-150" => {
3388 day => "2-digit",
3389 hour => "2-digit",
3390 minute => "2-digit",
3391 month => "2-digit",
3392 second => "2-digit",
3393 },
3394 "en-AE" => {
3395 day => "2-digit",
3396 minute => "2-digit",
3397 month => "2-digit",
3398 second => "2-digit",
3399 },
3400 "en-AI" => {
3401 day => "2-digit",
3402 hour => "2-digit",
3403 minute => "2-digit",
3404 month => "2-digit",
3405 second => "2-digit",
3406 },
3407 "en-AU" => {
3408 day => "2-digit",
3409 minute => "2-digit",
3410 month => "2-digit",
3411 second => "2-digit",
3412 },
3413 "en-BE" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3414 "en-BI" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3415 "en-BW" => {
3416 day => "2-digit",
3417 hour => "2-digit",
3418 minute => "2-digit",
3419 month => "2-digit",
3420 second => "2-digit",
3421 },
3422 "en-BZ" => {
3423 day => "2-digit",
3424 hour => "2-digit",
3425 minute => "2-digit",
3426 month => "2-digit",
3427 second => "2-digit",
3428 },
3429 "en-CA" => {
3430 day => "2-digit",
3431 minute => "2-digit",
3432 month => "2-digit",
3433 second => "2-digit",
3434 },
3435 "en-CC" => {
3436 day => "2-digit",
3437 hour => "2-digit",
3438 minute => "2-digit",
3439 month => "2-digit",
3440 second => "2-digit",
3441 },
3442 "en-CH" => {
3443 day => "2-digit",
3444 hour => "2-digit",
3445 minute => "2-digit",
3446 month => "2-digit",
3447 second => "2-digit",
3448 },
3449 "en-CK" => {
3450 day => "2-digit",
3451 hour => "2-digit",
3452 minute => "2-digit",
3453 month => "2-digit",
3454 second => "2-digit",
3455 },
3456 "en-CM" => {
3457 day => "2-digit",
3458 hour => "2-digit",
3459 minute => "2-digit",
3460 month => "2-digit",
3461 second => "2-digit",
3462 },
3463 "en-CX" => {
3464 day => "2-digit",
3465 hour => "2-digit",
3466 minute => "2-digit",
3467 month => "2-digit",
3468 second => "2-digit",
3469 },
3470 "en-DG" => {
3471 day => "2-digit",
3472 hour => "2-digit",
3473 minute => "2-digit",
3474 month => "2-digit",
3475 second => "2-digit",
3476 },
3477 "en-DK" => {
3478 day => "2-digit",
3479 hour => "2-digit",
3480 minute => "2-digit",
3481 month => "2-digit",
3482 second => "2-digit",
3483 },
3484 "en-FI" => {
3485 day => "2-digit",
3486 minute => "2-digit",
3487 month => "2-digit",
3488 second => "2-digit",
3489 },
3490 "en-FK" => {
3491 day => "2-digit",
3492 hour => "2-digit",
3493 minute => "2-digit",
3494 month => "2-digit",
3495 second => "2-digit",
3496 },
3497 "en-GB" => {
3498 day => "2-digit",
3499 hour => "2-digit",
3500 minute => "2-digit",
3501 month => "2-digit",
3502 second => "2-digit",
3503 },
3504 "en-GG" => {
3505 day => "2-digit",
3506 hour => "2-digit",
3507 minute => "2-digit",
3508 month => "2-digit",
3509 second => "2-digit",
3510 },
3511 "en-GI" => {
3512 day => "2-digit",
3513 hour => "2-digit",
3514 minute => "2-digit",
3515 month => "2-digit",
3516 second => "2-digit",
3517 },
3518 "en-HK" => { minute => "2-digit", second => "2-digit" },
3519 "en-IE" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3520 "en-IL" => {
3521 day => "2-digit",
3522 minute => "2-digit",
3523 month => "2-digit",
3524 second => "2-digit",
3525 },
3526 "en-IM" => {
3527 day => "2-digit",
3528 hour => "2-digit",
3529 minute => "2-digit",
3530 month => "2-digit",
3531 second => "2-digit",
3532 },
3533 "en-IN" => { minute => "2-digit", second => "2-digit" },
3534 "en-IO" => {
3535 day => "2-digit",
3536 hour => "2-digit",
3537 minute => "2-digit",
3538 month => "2-digit",
3539 second => "2-digit",
3540 },
3541 "en-JE" => {
3542 day => "2-digit",
3543 hour => "2-digit",
3544 minute => "2-digit",
3545 month => "2-digit",
3546 second => "2-digit",
3547 },
3548 "en-JM" => {
3549 day => "2-digit",
3550 minute => "2-digit",
3551 month => "2-digit",
3552 second => "2-digit",
3553 },
3554 "en-KE" => {
3555 day => "2-digit",
3556 hour => "2-digit",
3557 minute => "2-digit",
3558 month => "2-digit",
3559 second => "2-digit",
3560 },
3561 "en-MG" => {
3562 day => "2-digit",
3563 hour => "2-digit",
3564 minute => "2-digit",
3565 month => "2-digit",
3566 second => "2-digit",
3567 },
3568 "en-MS" => {
3569 day => "2-digit",
3570 hour => "2-digit",
3571 minute => "2-digit",
3572 month => "2-digit",
3573 second => "2-digit",
3574 },
3575 "en-MT" => {
3576 day => "2-digit",
3577 hour => "2-digit",
3578 minute => "2-digit",
3579 month => "2-digit",
3580 second => "2-digit",
3581 },
3582 "en-MU" => {
3583 day => "2-digit",
3584 hour => "2-digit",
3585 minute => "2-digit",
3586 month => "2-digit",
3587 second => "2-digit",
3588 },
3589 "en-MV" => {
3590 day => "2-digit",
3591 hour => "2-digit",
3592 minute => "2-digit",
3593 month => "2-digit",
3594 second => "2-digit",
3595 },
3596 "en-NF" => {
3597 day => "2-digit",
3598 hour => "2-digit",
3599 minute => "2-digit",
3600 month => "2-digit",
3601 second => "2-digit",
3602 },
3603 "en-NG" => {
3604 day => "2-digit",
3605 hour => "2-digit",
3606 minute => "2-digit",
3607 month => "2-digit",
3608 second => "2-digit",
3609 },
3610 "en-NR" => {
3611 day => "2-digit",
3612 hour => "2-digit",
3613 minute => "2-digit",
3614 month => "2-digit",
3615 second => "2-digit",
3616 },
3617 "en-NU" => {
3618 day => "2-digit",
3619 hour => "2-digit",
3620 minute => "2-digit",
3621 month => "2-digit",
3622 second => "2-digit",
3623 },
3624 "en-NZ" => { minute => "2-digit", month => "2-digit", second => "2-digit" },
3625 "en-PK" => {
3626 day => "2-digit",
3627 minute => "2-digit",
3628 month => "2-digit",
3629 second => "2-digit",
3630 },
3631 "en-PN" => {
3632 day => "2-digit",
3633 hour => "2-digit",
3634 minute => "2-digit",
3635 month => "2-digit",
3636 second => "2-digit",
3637 },
3638 "en-RW" => {
3639 day => "2-digit",
3640 hour => "2-digit",
3641 minute => "2-digit",
3642 month => "2-digit",
3643 second => "2-digit",
3644 },
3645 "en-SC" => {
3646 day => "2-digit",
3647 hour => "2-digit",
3648 minute => "2-digit",
3649 month => "2-digit",
3650 second => "2-digit",
3651 },
3652 "en-SE" => {
3653 day => "2-digit",
3654 hour => "2-digit",
3655 minute => "2-digit",
3656 month => "2-digit",
3657 second => "2-digit",
3658 },
3659 "en-SG" => {
3660 day => "2-digit",
3661 minute => "2-digit",
3662 month => "2-digit",
3663 second => "2-digit",
3664 },
3665 "en-SH" => {
3666 day => "2-digit",
3667 hour => "2-digit",
3668 minute => "2-digit",
3669 month => "2-digit",
3670 second => "2-digit",
3671 },
3672 "en-SX" => {
3673 day => "2-digit",
3674 hour => "2-digit",
3675 minute => "2-digit",
3676 month => "2-digit",
3677 second => "2-digit",
3678 },
3679 "en-TK" => {
3680 day => "2-digit",
3681 hour => "2-digit",
3682 minute => "2-digit",
3683 month => "2-digit",
3684 second => "2-digit",
3685 },
3686 "en-TV" => {
3687 day => "2-digit",
3688 hour => "2-digit",
3689 minute => "2-digit",
3690 month => "2-digit",
3691 second => "2-digit",
3692 },
3693 "en-TZ" => {
3694 day => "2-digit",
3695 hour => "2-digit",
3696 minute => "2-digit",
3697 month => "2-digit",
3698 second => "2-digit",
3699 },
3700 "en-UG" => {
3701 day => "2-digit",
3702 hour => "2-digit",
3703 minute => "2-digit",
3704 month => "2-digit",
3705 second => "2-digit",
3706 },
3707 "en-ZA" => {
3708 day => "2-digit",
3709 hour => "2-digit",
3710 minute => "2-digit",
3711 month => "2-digit",
3712 second => "2-digit",
3713 },
3714 "en-ZW" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3715 eo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3716 es => { minute => "2-digit", second => "2-digit" },
3717 "es-419" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3718 "es-BO" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3719 "es-BR" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3720 "es-BZ" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3721 "es-CL" => {
3722 day => "2-digit",
3723 hour => "2-digit",
3724 minute => "2-digit",
3725 month => "2-digit",
3726 second => "2-digit",
3727 },
3728 "es-CO" => { minute => "2-digit", second => "2-digit" },
3729 "es-DO" => { minute => "2-digit", second => "2-digit" },
3730 "es-GT" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3731 "es-HN" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3732 "es-MX" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3733 "es-PA" => {
3734 day => "2-digit",
3735 minute => "2-digit",
3736 month => "2-digit",
3737 second => "2-digit",
3738 },
3739 "es-PE" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3740 "es-PH" => { minute => "2-digit", second => "2-digit" },
3741 "es-PR" => {
3742 day => "2-digit",
3743 minute => "2-digit",
3744 month => "2-digit",
3745 second => "2-digit",
3746 },
3747 "es-US" => { minute => "2-digit", second => "2-digit" },
3748 et => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3749 eu => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3750 ewo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3751 fa => { minute => "2-digit", second => "2-digit" },
3752 ff => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3753 "ff-Adlm" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3754 "ff-Adlm-GH" => { minute => "2-digit", second => "2-digit" },
3755 "ff-Adlm-GM" => { minute => "2-digit", second => "2-digit" },
3756 "ff-Adlm-LR" => { minute => "2-digit", second => "2-digit" },
3757 "ff-Adlm-MR" => { minute => "2-digit", second => "2-digit" },
3758 "ff-Adlm-SL" => { minute => "2-digit", second => "2-digit" },
3759 "ff-Latn-GH" => { minute => "2-digit", second => "2-digit" },
3760 "ff-Latn-GM" => { minute => "2-digit", second => "2-digit" },
3761 "ff-Latn-LR" => { minute => "2-digit", second => "2-digit" },
3762 "ff-Latn-MR" => { minute => "2-digit", second => "2-digit" },
3763 "ff-Latn-SL" => { minute => "2-digit", second => "2-digit" },
3764 fi => { minute => "2-digit", second => "2-digit" },
3765 fil => { minute => "2-digit", second => "2-digit" },
3766 fo => {
3767 day => "2-digit",
3768 hour => "2-digit",
3769 minute => "2-digit",
3770 month => "2-digit",
3771 second => "2-digit",
3772 },
3773 fr => {
3774 day => "2-digit",
3775 hour => "2-digit",
3776 minute => "2-digit",
3777 month => "2-digit",
3778 second => "2-digit",
3779 },
3780 "fr-BE" => {
3781 day => "2-digit",
3782 hour => "2-digit",
3783 minute => "2-digit",
3784 month => "2-digit",
3785 second => "2-digit",
3786 },
3787 "fr-CA" => {
3788 day => "2-digit",
3789 hour => "2-digit",
3790 minute => "2-digit",
3791 month => "2-digit",
3792 second => "2-digit",
3793 },
3794 "fr-CH" => {
3795 day => "2-digit",
3796 hour => "2-digit",
3797 minute => "2-digit",
3798 month => "2-digit",
3799 second => "2-digit",
3800 },
3801 "fr-DJ" => {
3802 day => "2-digit",
3803 minute => "2-digit",
3804 month => "2-digit",
3805 second => "2-digit",
3806 },
3807 "fr-DZ" => {
3808 day => "2-digit",
3809 minute => "2-digit",
3810 month => "2-digit",
3811 second => "2-digit",
3812 },
3813 "fr-MR" => {
3814 day => "2-digit",
3815 minute => "2-digit",
3816 month => "2-digit",
3817 second => "2-digit",
3818 },
3819 "fr-SY" => {
3820 day => "2-digit",
3821 minute => "2-digit",
3822 month => "2-digit",
3823 second => "2-digit",
3824 },
3825 "fr-TD" => {
3826 day => "2-digit",
3827 minute => "2-digit",
3828 month => "2-digit",
3829 second => "2-digit",
3830 },
3831 "fr-TN" => {
3832 day => "2-digit",
3833 minute => "2-digit",
3834 month => "2-digit",
3835 second => "2-digit",
3836 },
3837 "fr-VU" => {
3838 day => "2-digit",
3839 minute => "2-digit",
3840 month => "2-digit",
3841 second => "2-digit",
3842 },
3843 fur => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3844 fy => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3845 ga => {
3846 day => "2-digit",
3847 hour => "2-digit",
3848 minute => "2-digit",
3849 month => "2-digit",
3850 second => "2-digit",
3851 },
3852 gd => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3853 gl => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3854 gsw => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3855 gu => { minute => "2-digit", second => "2-digit" },
3856 guz => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3857 gv => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3858 ha => {
3859 day => "2-digit",
3860 hour => "2-digit",
3861 minute => "2-digit",
3862 month => "2-digit",
3863 second => "2-digit",
3864 },
3865 "ha-GH" => {
3866 day => "2-digit",
3867 minute => "2-digit",
3868 month => "2-digit",
3869 second => "2-digit",
3870 },
3871 haw => { minute => "2-digit", second => "2-digit" },
3872 he => { minute => "2-digit", second => "2-digit" },
3873 hi => { minute => "2-digit", second => "2-digit" },
3874 "hi-Latn" => { minute => "2-digit", second => "2-digit" },
3875 hr => {
3876 day => "2-digit",
3877 hour => "2-digit",
3878 minute => "2-digit",
3879 month => "2-digit",
3880 second => "2-digit",
3881 },
3882 "hr-BA" => {
3883 day => "2-digit",
3884 hour => "2-digit",
3885 minute => "2-digit",
3886 month => "2-digit",
3887 second => "2-digit",
3888 },
3889 hsb => { minute => "2-digit", second => "2-digit" },
3890 hu => {
3891 day => "2-digit",
3892 minute => "2-digit",
3893 month => "2-digit",
3894 second => "2-digit",
3895 },
3896 hy => {
3897 day => "2-digit",
3898 minute => "2-digit",
3899 month => "2-digit",
3900 second => "2-digit",
3901 },
3902 ia => {
3903 day => "2-digit",
3904 hour => "2-digit",
3905 minute => "2-digit",
3906 month => "2-digit",
3907 second => "2-digit",
3908 },
3909 id => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3910 ig => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3911 ii => {
3912 day => "2-digit",
3913 hour => "2-digit",
3914 minute => "2-digit",
3915 month => "2-digit",
3916 second => "2-digit",
3917 },
3918 is => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3919 it => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3920 "it-CH" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3921 ja => { minute => "2-digit", second => "2-digit" },
3922 jgo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3923 jmc => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3924 jv => {
3925 day => "2-digit",
3926 hour => "2-digit",
3927 minute => "2-digit",
3928 month => "2-digit",
3929 second => "2-digit",
3930 },
3931 ka => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3932 kab => { minute => "2-digit", second => "2-digit" },
3933 kam => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3934 kde => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3935 kea => {
3936 day => "2-digit",
3937 hour => "2-digit",
3938 minute => "2-digit",
3939 month => "2-digit",
3940 second => "2-digit",
3941 },
3942 kgp => {
3943 day => "2-digit",
3944 hour => "2-digit",
3945 minute => "2-digit",
3946 month => "2-digit",
3947 second => "2-digit",
3948 },
3949 khq => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3950 ki => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3951 kk => {
3952 day => "2-digit",
3953 hour => "2-digit",
3954 minute => "2-digit",
3955 month => "2-digit",
3956 second => "2-digit",
3957 },
3958 kkj => {
3959 day => "2-digit",
3960 hour => "2-digit",
3961 minute => "2-digit",
3962 month => "2-digit",
3963 second => "2-digit",
3964 },
3965 kl => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3966 kln => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3967 km => { minute => "2-digit", second => "2-digit" },
3968 kn => { minute => "2-digit", second => "2-digit" },
3969 ko => { minute => "2-digit", second => "2-digit" },
3970 kok => { minute => "2-digit", second => "2-digit" },
3971 ks => { minute => "2-digit", second => "2-digit" },
3972 "ks-Deva" => { minute => "2-digit", second => "2-digit" },
3973 ksb => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3974 ksf => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3975 ksh => {
3976 day => "2-digit",
3977 minute => "2-digit",
3978 month => "2-digit",
3979 second => "2-digit",
3980 },
3981 ku => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3982 kw => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3983 ky => {
3984 day => "2-digit",
3985 hour => "2-digit",
3986 minute => "2-digit",
3987 month => "2-digit",
3988 second => "2-digit",
3989 },
3990 lag => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3991 lb => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3992 lg => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3993 lkt => { minute => "2-digit", second => "2-digit" },
3994 ln => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3995 lo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
3996 "lrc-IQ" => { minute => "2-digit", second => "2-digit" },
3997 lt => {
3998 day => "2-digit",
3999 hour => "2-digit",
4000 minute => "2-digit",
4001 month => "2-digit",
4002 second => "2-digit",
4003 },
4004 lu => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4005 luo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4006 luy => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4007 lv => {
4008 hour => "2-digit",
4009 minute => "2-digit",
4010 month => "2-digit",
4011 second => "2-digit",
4012 },
4013 mai => { minute => "2-digit", second => "2-digit" },
4014 mas => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4015 mer => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4016 mfe => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4017 mg => {
4018 day => "2-digit",
4019 hour => "2-digit",
4020 minute => "2-digit",
4021 month => "2-digit",
4022 second => "2-digit",
4023 },
4024 mgh => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4025 mgo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4026 mi => {
4027 day => "2-digit",
4028 minute => "2-digit",
4029 month => "2-digit",
4030 second => "2-digit",
4031 },
4032 mk => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4033 ml => { minute => "2-digit", second => "2-digit" },
4034 mn => {
4035 day => "2-digit",
4036 hour => "2-digit",
4037 minute => "2-digit",
4038 month => "2-digit",
4039 second => "2-digit",
4040 },
4041 mni => { minute => "2-digit", second => "2-digit" },
4042 mr => { minute => "2-digit", second => "2-digit" },
4043 ms => { minute => "2-digit", second => "2-digit" },
4044 "ms-BN" => { minute => "2-digit", second => "2-digit" },
4045 "ms-ID" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4046 mt => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4047 mua => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4048 my => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4049 naq => { minute => "2-digit", second => "2-digit" },
4050 nd => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4051 ne => {
4052 day => "2-digit",
4053 hour => "2-digit",
4054 minute => "2-digit",
4055 month => "2-digit",
4056 second => "2-digit",
4057 },
4058 "ne-IN" => {
4059 day => "2-digit",
4060 minute => "2-digit",
4061 month => "2-digit",
4062 second => "2-digit",
4063 },
4064 nl => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4065 "nl-BE" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4066 nmg => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4067 nn => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4068 nnh => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4069 no => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4070 nus => { minute => "2-digit", second => "2-digit" },
4071 nyn => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4072 om => {
4073 day => "2-digit",
4074 minute => "2-digit",
4075 month => "2-digit",
4076 second => "2-digit",
4077 },
4078 "om-KE" => {
4079 day => "2-digit",
4080 hour => "2-digit",
4081 minute => "2-digit",
4082 month => "2-digit",
4083 second => "2-digit",
4084 },
4085 or => { minute => "2-digit", second => "2-digit" },
4086 os => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4087 pa => { minute => "2-digit", second => "2-digit" },
4088 "pa-Arab" => { minute => "2-digit", second => "2-digit" },
4089 pcm => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4090 pl => {
4091 hour => "2-digit",
4092 minute => "2-digit",
4093 month => "2-digit",
4094 second => "2-digit",
4095 },
4096 ps => {
4097 day => "2-digit",
4098 minute => "2-digit",
4099 month => "2-digit",
4100 second => "2-digit",
4101 },
4102 "ps-PK" => {
4103 day => "2-digit",
4104 minute => "2-digit",
4105 month => "2-digit",
4106 second => "2-digit",
4107 },
4108 pt => {
4109 day => "2-digit",
4110 hour => "2-digit",
4111 minute => "2-digit",
4112 month => "2-digit",
4113 second => "2-digit",
4114 },
4115 "pt-MO" => {
4116 day => "2-digit",
4117 minute => "2-digit",
4118 month => "2-digit",
4119 second => "2-digit",
4120 },
4121 "pt-PT" => {
4122 day => "2-digit",
4123 hour => "2-digit",
4124 minute => "2-digit",
4125 month => "2-digit",
4126 second => "2-digit",
4127 },
4128 qu => {
4129 day => "2-digit",
4130 hour => "2-digit",
4131 minute => "2-digit",
4132 month => "2-digit",
4133 second => "2-digit",
4134 },
4135 raj => { minute => "2-digit", second => "2-digit" },
4136 rm => {
4137 day => "2-digit",
4138 hour => "2-digit",
4139 minute => "2-digit",
4140 month => "2-digit",
4141 second => "2-digit",
4142 },
4143 rn => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4144 ro => {
4145 day => "2-digit",
4146 hour => "2-digit",
4147 minute => "2-digit",
4148 month => "2-digit",
4149 second => "2-digit",
4150 },
4151 rof => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4152 ru => {
4153 day => "2-digit",
4154 hour => "2-digit",
4155 minute => "2-digit",
4156 month => "2-digit",
4157 second => "2-digit",
4158 },
4159 rw => {
4160 day => "2-digit",
4161 hour => "2-digit",
4162 minute => "2-digit",
4163 month => "2-digit",
4164 second => "2-digit",
4165 },
4166 rwk => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4167 sa => { minute => "2-digit", second => "2-digit" },
4168 sah => {
4169 day => "2-digit",
4170 hour => "2-digit",
4171 minute => "2-digit",
4172 month => "2-digit",
4173 second => "2-digit",
4174 },
4175 saq => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4176 sat => { minute => "2-digit", second => "2-digit" },
4177 sbp => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4178 sc => {
4179 day => "2-digit",
4180 hour => "2-digit",
4181 minute => "2-digit",
4182 month => "2-digit",
4183 second => "2-digit",
4184 },
4185 sd => {
4186 day => "2-digit",
4187 minute => "2-digit",
4188 month => "2-digit",
4189 second => "2-digit",
4190 },
4191 "sd-Deva" => { minute => "2-digit", second => "2-digit" },
4192 "se-FI" => {
4193 day => "2-digit",
4194 hour => "2-digit",
4195 minute => "2-digit",
4196 month => "2-digit",
4197 second => "2-digit",
4198 },
4199 seh => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4200 ses => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4201 sg => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4202 shi => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4203 "shi-Latn" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4204 si => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4205 sk => { minute => "2-digit", second => "2-digit" },
4206 sl => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4207 smn => { minute => "2-digit", second => "2-digit" },
4208 sn => {
4209 day => "2-digit",
4210 hour => "2-digit",
4211 minute => "2-digit",
4212 month => "2-digit",
4213 second => "2-digit",
4214 },
4215 so => { minute => "2-digit", second => "2-digit" },
4216 "so-KE" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4217 sq => { minute => "2-digit", second => "2-digit" },
4218 "sq-MK" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4219 "sq-XK" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4220 sr => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4221 "sr-Latn" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4222 su => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4223 sv => {
4224 day => "2-digit",
4225 hour => "2-digit",
4226 minute => "2-digit",
4227 month => "2-digit",
4228 second => "2-digit",
4229 },
4230 sw => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4231 "sw-KE" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4232 ta => { minute => "2-digit", second => "2-digit" },
4233 "ta-LK" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4234 te => { minute => "2-digit", second => "2-digit" },
4235 teo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4236 tg => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4237 th => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4238 ti => { minute => "2-digit", second => "2-digit" },
4239 "ti-ER" => { minute => "2-digit", second => "2-digit" },
4240 tk => {
4241 day => "2-digit",
4242 hour => "2-digit",
4243 minute => "2-digit",
4244 month => "2-digit",
4245 second => "2-digit",
4246 },
4247 to => { minute => "2-digit", second => "2-digit" },
4248 "tr" => {
4249 day => "2-digit",
4250 hour => "2-digit",
4251 minute => "2-digit",
4252 month => "2-digit",
4253 second => "2-digit",
4254 },
4255 "tr-CY" => {
4256 day => "2-digit",
4257 minute => "2-digit",
4258 month => "2-digit",
4259 second => "2-digit",
4260 },
4261 tt => {
4262 day => "2-digit",
4263 hour => "2-digit",
4264 minute => "2-digit",
4265 month => "2-digit",
4266 second => "2-digit",
4267 },
4268 twq => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4269 tzm => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4270 ug => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4271 uk => {
4272 day => "2-digit",
4273 hour => "2-digit",
4274 minute => "2-digit",
4275 month => "2-digit",
4276 second => "2-digit",
4277 },
4278 ur => { minute => "2-digit", second => "2-digit" },
4279 uz => {
4280 day => "2-digit",
4281 hour => "2-digit",
4282 minute => "2-digit",
4283 month => "2-digit",
4284 second => "2-digit",
4285 },
4286 "uz-Arab" => {
4287 day => "2-digit",
4288 hour => "2-digit",
4289 minute => "2-digit",
4290 month => "2-digit",
4291 second => "2-digit",
4292 },
4293 "uz-Cyrl" => {
4294 day => "2-digit",
4295 hour => "2-digit",
4296 minute => "2-digit",
4297 month => "2-digit",
4298 second => "2-digit",
4299 },
4300 vai => { minute => "2-digit", second => "2-digit" },
4301 "vai-Latn" => { minute => "2-digit", second => "2-digit" },
4302 vi => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4303 vun => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4304 wae => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4305 wo => {
4306 day => "2-digit",
4307 hour => "2-digit",
4308 minute => "2-digit",
4309 month => "2-digit",
4310 second => "2-digit",
4311 },
4312 xh => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4313 xog => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4314 yav => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4315 yi => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4316 yo => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4317 yrl => {
4318 day => "2-digit",
4319 hour => "2-digit",
4320 minute => "2-digit",
4321 month => "2-digit",
4322 second => "2-digit",
4323 },
4324 "yrl-CO" => {
4325 day => "2-digit",
4326 minute => "2-digit",
4327 month => "2-digit",
4328 second => "2-digit",
4329 },
4330 "yrl-VE" => {
4331 day => "2-digit",
4332 minute => "2-digit",
4333 month => "2-digit",
4334 second => "2-digit",
4335 },
4336 yue => { minute => "2-digit", second => "2-digit" },
4337 "yue-Hans" => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4338 zgh => {
4339 day => "2-digit",
4340 hour => "2-digit",
4341 minute => "2-digit",
4342 month => "2-digit",
4343 second => "2-digit",
4344 },
4345 zh => { hour => "2-digit", minute => "2-digit", second => "2-digit" },
4346 "zh-Hans-HK" => { minute => "2-digit", second => "2-digit" },
4347 "zh-Hans-MO" => { minute => "2-digit", second => "2-digit" },
4348 "zh-Hans-SG" => { minute => "2-digit", second => "2-digit" },
4349 "zh-Hant" => { minute => "2-digit", second => "2-digit" },
4350 "zh-Hant-HK" => { minute => "2-digit", second => "2-digit" },
4351 zu => {
4352 day => "2-digit",
4353 hour => "2-digit",
4354 minute => "2-digit",
4355 month => "2-digit",
4356 second => "2-digit",
4357 },
4358 };
4359 }
4360  
4361 # NOTE: DateTime::Format::Intl::Exception class
4362 package DateTime::Format::Intl::Exception;
4363 BEGIN
4364 11 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
4365 11 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4366 11 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4367 11 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
4368 11 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
4369 '""' => 'as_string',
4370 0 ▶ bool => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4371 11 fallback => 1,
4372 11 );
4373 11 our $VERSION = 'v0.1.0';
4374 };
4375 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4376 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4377  
4378 sub new
4379 0 ▶{
Subroutine new: not called CC=12 SCAR=50.5
4380 0 my $this = shift( @_ );
4381 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
4382 0 my @info = caller;
4383 0 @$self{ qw( package file line ) } = @info[0..2];
4384 0 my $args = {};
4385 0 ▶ if( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 0 0 0
4386 {
4387 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::Intl::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
4388 {
4389 0 $args = shift( @_ );
4390 0 ▶ if( $args->{skip_frames} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"skip_frames"}) 0 0 0
4391 {
4392 0 @info = caller( int( $args->{skip_frames} ) );
4393 0 @$self{ qw( package file line ) } = @info[0..2];
4394 }
4395 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
4396 0 foreach my $k ( qw( package file line message code type retry_after ) )
4397 {
4398 0 ▶ $self->{ $k } = $args->{ $k } if( CORE::exists( $args->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{$k} 0 0 0
4399 }
4400 }
4401 ▶ elsif( ref( $_[0] ) && $_[0]->isa( 'DateTime::Format::Intl::Exception' ) )
Condition0%0/3
ref $_[0] and $_[0]->isa("DateTime::Format::Intl::Exception")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and $_[0]->isa("DateTime::Format::Intl::Exception")
ref $_[0] $_[0]->isa("DateTime::Format::Intl::Exception")
Truth table0%0/3
A and B
A= ref $_[0]B= $_[0]->isa("DateTime::Format::Intl::Exception")
ABresult
0X0
100
111
4402 {
4403 0 my $o = $args->{object} = shift( @_ );
4404 0 $self->{message} = $o->message;
4405 0 $self->{code} = $o->code;
4406 0 $self->{type} = $o->type;
4407 0 $self->{retry_after} = $o->retry_after;
4408 }
4409 else
4410 {
4411 0 die( "Unknown argument provided: '", overload::StrVal( $_[0] ), "'" );
4412 }
4413 }
4414 else
4415 {
4416 0 ▶ $args->{message} = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
4417 }
4418 0 return( $self );
4419 }
4420  
4421 # This is important as stringification is called by die, so as per the manual page, we need to end with new line
4422 # And will add the stack trace
4423 sub as_string
4424 0 ▶{
Subroutine as_string: not called CC=6 SCAR=33.9
4425 11 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
4426 0 my $self = shift( @_ );
4427 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
4428 0 my $str = $self->message;
4429 0 $str = "$str";
4430 0 $str =~ s/\r?\n$//g;
4431 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
4432 0 $self->{_cache_value} = $str;
4433 0 CORE::delete( $self->{_reset} );
4434 0 return( $str );
4435 }
4436  
4437 0 ▶sub code { return( shift->reset(@_)->_set_get_prop( 'code', @_ ) ); }
Subroutine code: not called CC=1 SCAR=6.9
4438  
4439 0 ▶sub file { return( shift->reset(@_)->_set_get_prop( 'file', @_ ) ); }
Subroutine file: not called CC=1 SCAR=6.9
4440  
4441 0 ▶sub line { return( shift->reset(@_)->_set_get_prop( 'line', @_ ) ); }
Subroutine line: not called CC=1 SCAR=6.9
4442  
4443 0 ▶sub message { return( shift->reset(@_)->_set_get_prop( 'message', @_ ) ); }
Subroutine message: not called CC=1 SCAR=6.9
4444  
4445 0 ▶sub package { return( shift->reset(@_)->_set_get_prop( 'package', @_ ) ); }
Subroutine package: not called CC=1 SCAR=6.9
4446  
4447 # From perlfunc docmentation on "die":
4448 # "If LIST was empty or made an empty string, and $@ contains an
4449 # object reference that has a "PROPAGATE" method, that method will
4450 # be called with additional file and line number parameters. The
4451 # return value replaces the value in $@; i.e., as if "$@ = eval {
4452 # $@->PROPAGATE(__FILE__, __LINE__) };" were called."
4453 sub PROPAGATE
4454 0 ▶{
Subroutine PROPAGATE: not called CC=3 SCAR=24.8
4455 0 my( $self, $file, $line ) = @_;
4456 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
4457 {
4458 0 my $clone = $self->clone;
4459 0 $clone->file( $file );
4460 0 $clone->line( $line );
4461 0 return( $clone );
4462 }
4463 0 return( $self );
4464 }
4465  
4466 sub reset
4467 0 ▶{
Subroutine reset: not called CC=3 SCAR=24.8
4468 0 my $self = shift( @_ );
4469 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
4470 {
4471 0 $self->{_reset} = scalar( @_ );
4472 }
4473 0 return( $self );
4474 }
4475  
4476 sub rethrow
4477 0 ▶{
Subroutine rethrow: not called CC=2 SCAR=17.9
4478 0 my $self = shift( @_ );
4479 0 ▶ return if( !ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
4480 0 die( $self );
4481 }
4482  
4483 0 ▶sub retry_after { return( shift->_set_get_prop( 'retry_after', @_ ) ); }
Subroutine retry_after: not called CC=1 SCAR=6.9
4484  
4485 sub throw
4486 0 ▶{
Subroutine throw: not called CC=2 SCAR=17.9
4487 0 my $self = shift( @_ );
4488 0 my $e;
4489 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
4490 {
4491 0 my $msg = shift( @_ );
4492 0 $e = $self->new({
4493 skip_frames => 1,
4494 message => $msg,
4495 });
4496 }
4497 else
4498 {
4499 0 $e = $self;
4500 }
4501 0 die( $e );
4502 }
4503  
4504 0 ▶sub type { return( shift->reset(@_)->_set_get_prop( 'type', @_ ) ); }
Subroutine type: not called CC=1 SCAR=6.9
4505  
4506 sub _set_get_prop
4507 0 ▶{
Subroutine _set_get_prop: not called CC=3 SCAR=24.8
4508 0 my $self = shift( @_ );
4509 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
4510 0 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
4511 0 return( $self->{ $prop } );
4512 }
4513  
4514 sub FREEZE
4515 0 ▶{
Subroutine FREEZE: not called CC=4 SCAR=30.0
4516 0 my $self = CORE::shift( @_ );
4517 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
4518 0 my $class = CORE::ref( $self );
4519 0 my %hash = %$self;
4520 # Return an array reference rather than a list so this works with Sereal and CBOR
4521 # On or before Sereal version 4.023, Sereal did not support multiple values returned
4522 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
4523 # But Storable want a list with the first element being the serialised element
4524 0 CORE::return( $class, \%hash );
4525 }
4526  
4527 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
4528  
4529 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
4530  
4531 # 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.
4532 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
4533 sub THAW
4534 0 ▶{
Subroutine THAW: not called CC=10 SCAR=47.0
4535 0 my( $self, undef, @args ) = @_;
4536 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
4537 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
4538 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
4539 0 my $new;
4540 # Storable pattern requires to modify the object it created rather than returning a new one
4541 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
4542 {
4543 0 foreach( CORE::keys( %$hash ) )
4544 {
4545 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
4546 }
4547 0 $new = $self;
4548 }
4549 else
4550 {
4551 0 $new = CORE::bless( $hash => $class );
4552 }
4553 0 CORE::return( $new );
4554 }
4555  
4556 0 ▶sub TO_JSON { return( shift->as_string ); }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
4557  
4558 {
4559 # NOTE: DateTime::Format::Intl::NullObject class
4560 package
4561 DateTime::Format::Intl::NullObject;
4562 BEGIN
4563 {
4564 11 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4565 11 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4566 11 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
4567 0 ▶ '""' => sub{ '' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4568 11 fallback => 1,
4569 11 );
4570 11 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
4571 };
4572 11 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4573 11 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4574  
4575 sub new
4576 0 ▶ {
Subroutine new: not called CC=3 SCAR=24.8
4577 0 my $this = shift( @_ );
4578 0 ▶ my $ref = @_ ? { @_ } : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
4579 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
4580 }
4581  
4582 sub AUTOLOAD
4583 0 ▶ {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
4584 0 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
4585 0 my $self = shift( @_ );
4586 0 ▶ if( Wanted::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (Wanted::want("OBJECT")) 0 0 0
4587 {
4588 0 rreturn( $self );
4589 }
4590 # Otherwise, we return undef; Empty return returns undef in scalar context and empty list in list context
4591 0 return;
4592 };
4593 }
4594  
4595 # NOTE: DateTime::Format::Intl::ScoreResult
4596 # This is a private class whose purpose is to contain detailed information about the evaluation of a pattern during scoring, and in particular which fields were missing.
4597 # The information about missing fields is key to whether we need to patch the date and time as specified by the LDML specifications at <https://www.unicode.org/reports/tr35/tr35-dates.html#Missing_Skeleton_Fields>
4598 {
4599 11 package
4600 DateTime::Format::Intl::ScoreResult;
4601 11 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4602 11 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4603 11 ▶ use vars qw( $DEBUG $ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
4604 11 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
4605  
4606 sub new
4607 27544 ▶ {
Subroutine new: called CC=13 SCAR=32.7
4608 27544 my $this = shift( @_ );
4609 27544 ▶ my $self = bless( {} => ( ref( $this ) || $this ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0275440
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
4610 # Whether there are any missing component that will need to ne appended
4611 27544 $self->{has_missing} = 0;
4612 # The components that will need to be appended
4613 27544 $self->{missing} = [];
4614 # Whether the pattern has components, but not at the right precision, and thus who will need to be adjusted
4615 # By default this value is set to undef, so we can differentiate if it has been set or not: 0 or 1
4616 27544 $self->{need_adjustment} = undef;
4617 27544 $self->{pattern_object} = undef;
4618 27544 $self->{request_object} = undef;
4619 27544 $self->{score} = 0;
4620  
4621 27544 my @args = @_;
4622 27544 ▶ if( scalar( @args ) == 1 &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1 and defined $args[0] and ref $args[0] eq 'HASH') { } 0 27544 27544
elsif (scalar(@args) % 2) { } 0 27544 27544
Condition33%2/6
scalar @args == 1 and defined $args[0] and ref $args[0] eq "HASH"
!ll&&!rl&&r
2754400
scalar @args == 1 and defined $args[0]
!ll&&!rl&&r
2754400
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 table25%1/4
A and B and C
A= scalar @args == 1B= defined $args[0]C= ref $args[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
4623 defined( $args[0] ) &&
4624 ref( $args[0] ) eq 'HASH' )
4625 {
4626 0 my $opts = shift( @args );
4627 0 @args = %$opts;
4628 }
4629 elsif( ( scalar( @args ) % 2 ) )
4630 {
4631 0 return( $self->error( sprintf( "Uneven number of parameters provided (%d). Should receive key => value pairs. Parameters provided are: %s", scalar( @args ), join( ', ', @args ) ) ) );
4632 }
4633
4634 27544 ▶ for( my $i = 0; $i < scalar( @args ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 137696 27544 165240
4635 {
4636 137696 ▶ if( $args[$i] eq 'fatal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($args[$i] eq "fatal") 0 137696 137696
4637 {
4638 0 $self->{fatal} = $args[$i + 1];
4639 0 last;
4640 }
4641 }
4642
4643 # Then, if the user provided with an hash or hash reference of options, we apply them
4644 27544 ▶ for( my $i = 0; $i < scalar( @args ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 137696 27544 165240
4645 {
4646 137696 my $name = $args[ $i ];
4647 137696 my $val = $args[ ++$i ];
4648 137696 my $meth = $self->can( $name );
4649 137696 ▶ if( !defined( $meth ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $meth) { } 0 137696 137696
elsif (not defined &$meth($self, $val)) { } 0 137696 137696
4650 {
4651 0 return( $self->error( "Unknown method \"${meth}\" provided." ) );
4652 }
4653 elsif( !defined( $meth->( $self, $val ) ) )
4654 {
4655 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
4656 {
4657 0 return( $self->pass_error );
4658 }
4659 }
4660 }
4661 27544 $self->{has_missing} = scalar( @{$self->{missing}} );
4662 27544 return( $self );
4663 }
4664  
4665 sub error
4666 0 ▶ {
Subroutine error: not called CC=8 SCAR=42.8
4667 0 my $self = shift( @_ );
4668 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
4669 {
4670 0 ▶ my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
4671 0 $self->{error} = $ERROR = DateTime::Format::Intl::Exception->new({
4672 skip_frames => 1,
4673 message => $msg,
4674 });
4675 0 ▶ if( $self->fatal )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 0 0 0
4676 {
4677 0 die( $self->{error} );
4678 }
4679 else
4680 {
4681 0 ▶ warn( $msg ) if( warnings::enabled( 'DateTime::Format::Intl' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Format::Intl") 0 0 0
4682 0 ▶ if( Wanted::want( 'ARRAY' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (Wanted::want('ARRAY')) { } 0 0 0
elsif (Wanted::want('OBJECT')) { } 0 0 0
4683 {
4684 0 rreturn( [] );
4685 }
4686 elsif( Wanted::want( 'OBJECT' ) )
4687 {
4688 0 rreturn( DateTime::Format::Intl::NullObject->new );
4689 }
4690 0 return;
4691 }
4692 }
4693 0 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
4694 }
4695
4696 0 ▶ sub fatal { return( shift->_set_get_prop( 'fatal', @_ ) ); }
Subroutine fatal: not called CC=1 SCAR=6.9
4697  
4698 745 ▶ sub has_missing { return( shift->{has_missing} ); }
Subroutine has_missing: called CC=1 SCAR=0.0
4699  
4700 28112 ▶ sub missing { return( shift->_set_get_prop( 'missing', @_ ) ); }
Subroutine missing: called CC=1 SCAR=0.0
4701  
4702 28103 ▶ sub need_adjustment { return( shift->_set_get_prop( 'need_adjustment', @_ ) ); }
Subroutine need_adjustment: called CC=1 SCAR=0.0
4703  
4704 sub pass_error
4705 0 ▶ {
Subroutine pass_error: not called CC=2 SCAR=17.9
4706 0 my $self = shift( @_ );
4707 0 ▶ if( Wanted::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (Wanted::want("OBJECT")) 0 0 0
4708 {
4709 0 rreturn( DateTime::Format::Intl::NullObject->new );
4710 }
4711 0 return;
4712 }
4713  
4714 28877 ▶ sub pattern_object { return( shift->_set_get_prop( 'pattern_object', @_ ) ); }
Subroutine pattern_object: called CC=1 SCAR=0.0
4715  
4716 27619 ▶ sub request_object { return( shift->_set_get_prop( 'request_object', @_ ) ); }
Subroutine request_object: called CC=1 SCAR=0.0
4717  
4718 55088 ▶ sub score { return( shift->_set_get_prop( 'score', @_ ) ); }
Subroutine score: called CC=1 SCAR=0.0
4719  
4720 sub _set_get_prop
4721 167799 ▶ {
Subroutine _set_get_prop: called CC=3 SCAR=11.0
4722 167799 my $self = shift( @_ );
4723 167799 ▶ my $prop = shift( @_ ) || die( "No object property was provided." );
Condition50%1/2
shift @_ || die('No object property was provided.')
l!l
1677990
MC/DC0%0/1
shift @_ || die('No object property was provided.')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
4724 167799 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 137696 30103 167799
4725 167799 return( $self->{ $prop } );
4726 }
4727 }
4728  
4729 # NOTE: DateTime::Format::Intl::Skeleton class
4730 # This object is used to represent a user requested skeleton, or an CLDR available skeleton
4731 # For the requested skeleton, there is obviously no pattern
4732 # For the available format there is a subtlety, whereby we have a tokens containing an array of elements representing the pattern, and we also have a skeleton_tokens representing an tokens for the actual skeleton
4733 {
4734 # Hide it from CPAN so it does not get registered
4735 11 package
4736 DateTime::Format::Intl::Skeleton;
4737 11 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4738 11 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4739 11 ▶ use vars qw( $DEBUG $ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
4740  
4741 sub new
4742 28093 ▶ {
Subroutine new: called CC=32 SCAR=45.5
4743 28093 my $this = shift( @_ );
4744 28093 ▶ my $self = bless( {} => ( ref( $this ) || $this ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0280930
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
4745 28093 $self->{components} = [];
4746 28093 $self->{date_components} = [];
4747 28093 $self->{is_interval} = 0;
4748 28093 $self->{patched_pattern} = undef;
4749 28093 $self->{patched_skeleton} = undef;
4750 28093 $self->{pattern} = undef;
4751 28093 $self->{pattern_skeleton} = undef;
4752 28093 $self->{skeleton} = undef;
4753 28093 $self->{skeleton_components} = [];
4754 28093 $self->{skeleton_date_components} = [];
4755 28093 $self->{skeleton_time_components} = [];
4756 28093 $self->{skeleton_tokens} = [];
4757 28093 $self->{time_components} = [];
4758 28093 $self->{tokens} = [];
4759 28093 $self->{debug} = $DateTime::Format::Intl::DEBUG;
4760  
4761 28093 my @args = @_;
4762 28093 ▶ if( scalar( @args ) == 1 &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1 and defined $args[0] and ref $args[0] eq 'HASH') { } 0 28093 28093
elsif (scalar(@args) % 2) { } 0 28093 28093
Condition33%2/6
scalar @args == 1 and defined $args[0] and ref $args[0] eq "HASH"
!ll&&!rl&&r
2809300
scalar @args == 1 and defined $args[0]
!ll&&!rl&&r
2809300
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 table25%1/4
A and B and C
A= scalar @args == 1B= defined $args[0]C= ref $args[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
4763 defined( $args[0] ) &&
4764 ref( $args[0] ) eq 'HASH' )
4765 {
4766 0 my $opts = shift( @args );
4767 0 @args = %$opts;
4768 }
4769 elsif( ( scalar( @args ) % 2 ) )
4770 {
4771 0 return( $self->error( sprintf( "Uneven number of parameters provided (%d). Should receive key => value pairs. Parameters provided are: %s", scalar( @args ), join( ', ', @args ) ) ) );
4772 }
4773  
4774 PREPROCESS:
4775 56186 ▶ for( my $i = 0; $i < scalar( @args ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 198855 28093 226948
4776 {
4777 198855 ▶ if( $args[$i] eq 'fatal' )
Branch: 2 branches
BranchTrueFalseTotal
if ($args[$i] eq 'fatal') { } 0 198855 198855
elsif ($args[$i] eq 'debug') { } 28093 170762 198855
4778 {
4779 0 $self->{fatal} = $args[$i + 1];
4780 0 splice( @args, $i, 2 );
4781 0 goto PREPROCESS;
4782 }
4783 elsif( $args[$i] eq 'debug' )
4784 {
4785 28093 $self->{debug} = $args[$i + 1];
4786 28093 splice( @args, $i, 2 );
4787 28093 goto PREPROCESS;
4788 }
4789 }
4790
4791 # Then, if the user provided with an hash or hash reference of options, we apply them
4792 28093 ▶ for( my $i = 0; $i < scalar( @args ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 85381 28093 113474
4793 {
4794 85381 my $name = $args[ $i ];
4795 85381 my $val = $args[ ++$i ];
4796 85381 my $meth = $self->can( $name );
4797 85381 ▶ if( !defined( $meth ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $meth) { } 0 85381 85381
elsif (not defined &$meth($self, $val)) { } 2204 83177 85381
4798 {
4799 0 return( $self->error( "Unknown method \"${name}\" provided." ) );
4800 }
4801 elsif( !defined( $meth->( $self, $val ) ) )
4802 {
4803 2204 ▶ if( defined( $val ) && $self->error )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $self->error) 0 2204 2204
Condition33%1/3
defined $val and $self->error
!ll&&!rl&&r
220400
MC/DC0%0/2
defined $val and $self->error
defined $val $self->error
Truth table33%1/3
A and B
A= defined $valB= $self->error
ABresult
0X0
100
111
4804 {
4805 0 return( $self->pass_error );
4806 }
4807 }
4808 }
4809  
4810 # TODO: We always use the option 'pattern_skeleton', so we should consider simplifying this
4811 28093 ▶ my $pattern_skeleton = $self->{pattern_skeleton} || $self->{skeleton};
Condition33%1/3
$self->{'pattern_skeleton'} || $self->{'skeleton'}
l!l&&r!l&&!r
2809300
MC/DC0%0/2
$self->{'pattern_skeleton'} || $self->{'skeleton'}
$self->{'pattern_skeleton'} $self->{'skeleton'}
Truth table33%1/3
A || B
A= $self->{'pattern_skeleton'}B= $self->{'skeleton'}
ABresult
1X1
011
000
4812 28093 ▶ if( scalar( @{$self->{tokens} // []} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{'tokens'} // [];} and scalar @{$self->{'components'} // [];} and scalar @{$self->{'date_components'} // [];} and scalar @{$self->{'time_components'} // [];}) { } 0 28093 28093
Condition62%5/8
scalar @{$self->{"tokens"} // [];} and scalar @{$self->{"components"} // [];} and scalar @{$self->{"date_components"} // [];} and scalar @{$self->{"time_components"} // [];}
!ll
280930
scalar @{$self->{"tokens"} // [];} and scalar @{$self->{"components"} // [];} and scalar @{$self->{"date_components"} // [];}
!ll
280930
scalar @{$self->{"tokens"} // [];} and scalar @{$self->{"components"} // [];}
!ll
280930
$self->{"tokens"} // []
l!l
27542551
MC/DC0%0/1
scalar @{$self->{"tokens"} // [];} and scalar @{$self->{"components"} // [];} and scalar @{$self->{"date_components"} // [];} and scalar @{$self->{"time_components"} // [];}
scalar @{$self->{"tokens"} // [];}
MC/DC100%1/1
$self->{"tokens"} // []
$self->{"tokens"}
Truth table50%1/2
A
A= scalar @{$self->{"tokens"} // [];}
Aresult
00
11
Truth table100%2/2
A
A= $self->{"tokens"}
Aresult
11
00
4813 0 ▶ scalar( @{$self->{components} // []} ) &&
Condition0%0/2
$self->{"components"} // []
l!l
00
MC/DC0%0/1
$self->{"components"} // []
$self->{"components"}
Truth table0%0/2
A
A= $self->{"components"}
Aresult
11
00
4814 0 ▶ scalar( @{$self->{date_components} // []} ) &&
Condition0%0/2
$self->{"date_components"} // []
l!l
00
MC/DC0%0/1
$self->{"date_components"} // []
$self->{"date_components"}
Truth table0%0/2
A
A= $self->{"date_components"}
Aresult
11
00
4815 0 ▶ scalar( @{$self->{time_components} // []} ) )
Condition0%0/2
$self->{"time_components"} // []
l!l
00
MC/DC0%0/1
$self->{"time_components"} // []
$self->{"time_components"}
Truth table0%0/2
A
A= $self->{"time_components"}
Aresult
11
00
4816 {
4817 }
4818 else
4819 {
4820 28093 my( $tokens, $components, $date_components, $time_components ) = $self->_split_skeleton( $pattern_skeleton );
4821 28093 $self->{tokens} = $tokens;
4822 # Collect the components in the requested skeleton
4823 28093 $self->{components} = $components;
4824 28093 $self->{date_components} = $date_components;
4825 28093 $self->{time_components} = $time_components;
4826 }
4827  
4828 28093 ▶ if( scalar( @{$self->{skeleton_tokens} // []} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @{$self->{'skeleton_tokens'} // [];} and scalar @{$self->{'skeleton_components'} // [];} and scalar @{$self->{'skeleton_date_components'} // [];} and scalar @{$self->{'skeleton_time_components'} // [];}) { } 0 28093 28093
elsif ($self->{'skeleton'}) { } 27542 551 28093
Condition50%4/8
scalar @{$self->{"skeleton_tokens"} // [];} and scalar @{$self->{"skeleton_components"} // [];} and scalar @{$self->{"skeleton_date_components"} // [];} and scalar @{$self->{"skeleton_time_components"} // [];}
!ll
280930
scalar @{$self->{"skeleton_tokens"} // [];} and scalar @{$self->{"skeleton_components"} // [];} and scalar @{$self->{"skeleton_date_components"} // [];}
!ll
280930
scalar @{$self->{"skeleton_tokens"} // [];} and scalar @{$self->{"skeleton_components"} // [];}
!ll
280930
$self->{"skeleton_tokens"} // []
l!l
280930
MC/DC0%0/1
scalar @{$self->{"skeleton_tokens"} // [];} and scalar @{$self->{"skeleton_components"} // [];} and scalar @{$self->{"skeleton_date_components"} // [];} and scalar @{$self->{"skeleton_time_components"} // [];}
scalar @{$self->{"skeleton_tokens"} // [];}
MC/DC0%0/1
$self->{"skeleton_tokens"} // []
$self->{"skeleton_tokens"}
Truth table50%1/2
A
A= scalar @{$self->{"skeleton_tokens"} // [];}
Aresult
00
11
Truth table50%1/2
A
A= $self->{"skeleton_tokens"}
Aresult
11
00
4829 0 ▶ scalar( @{$self->{skeleton_components} // []} ) &&
Condition0%0/2
$self->{"skeleton_components"} // []
l!l
00
MC/DC0%0/1
$self->{"skeleton_components"} // []
$self->{"skeleton_components"}
Truth table0%0/2
A
A= $self->{"skeleton_components"}
Aresult
11
00
4830 0 ▶ scalar( @{$self->{skeleton_date_components} // []} ) &&
Condition0%0/2
$self->{"skeleton_date_components"} // []
l!l
00
MC/DC0%0/1
$self->{"skeleton_date_components"} // []
$self->{"skeleton_date_components"}
Truth table0%0/2
A
A= $self->{"skeleton_date_components"}
Aresult
11
00
4831 0 ▶ scalar( @{$self->{skeleton_time_components} // []} ) )
Condition0%0/2
$self->{"skeleton_time_components"} // []
l!l
00
MC/DC0%0/1
$self->{"skeleton_time_components"} // []
$self->{"skeleton_time_components"}
Truth table0%0/2
A
A= $self->{"skeleton_time_components"}
Aresult
11
00
4832 {
4833 }
4834 # For datetime format skeletons
4835 elsif( $self->{skeleton} )
4836 {
4837 27542 my( $skel_tokens, $skel_components, $skel_date_components, $skel_time_components ) = $self->_split_skeleton( $self->{skeleton} );
4838 27542 $self->{skeleton_components} = $skel_components;
4839 27542 $self->{skeleton_date_components} = $skel_date_components;
4840 27542 $self->{skeleton_time_components} = $skel_time_components;
4841 27542 $self->{skeleton_tokens} = $skel_tokens;
4842 }
4843 28093 return( $self );
4844 }
4845  
4846 # Array reference of single characters, i.e. component or symbol
4847 28073 ▶ sub components { return( shift->_set_get_prop( 'components', @_ ) ); }
Subroutine components: called CC=1 SCAR=0.0
4848  
4849 574 ▶ sub date_components { return( shift->_set_get_prop( 'date_components', @_ ) ); }
Subroutine date_components: called CC=1 SCAR=0.0
4850  
4851 sub error
4852 0 ▶ {
Subroutine error: not called CC=8 SCAR=42.8
4853 0 my $self = shift( @_ );
4854 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
4855 {
4856 0 ▶ my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
4857 0 $self->{error} = $ERROR = DateTime::Format::Intl::Exception->new({
4858 skip_frames => 1,
4859 message => $msg,
4860 });
4861 0 ▶ if( $self->fatal )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 0 0 0
4862 {
4863 0 die( $self->{error} );
4864 }
4865 else
4866 {
4867 0 ▶ warn( $msg ) if( warnings::enabled( 'DateTime::Format::Intl' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Format::Intl") 0 0 0
4868 0 ▶ if( Wanted::want( 'ARRAY' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (Wanted::want('ARRAY')) { } 0 0 0
elsif (Wanted::want('OBJECT')) { } 0 0 0
4869 {
4870 0 rreturn( [] );
4871 }
4872 elsif( Wanted::want( 'OBJECT' ) )
4873 {
4874 0 rreturn( DateTime::Format::Intl::NullObject->new );
4875 }
4876 0 return;
4877 }
4878 }
4879 0 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
4880 }
4881
4882 0 ▶ sub fatal { return( shift->_set_get_prop( 'fatal', @_ ) ); }
Subroutine fatal: not called CC=1 SCAR=6.9
4883  
4884 0 ▶ sub is_interval { return( shift->_set_get_prop( 'is_interval', @_ ) ); }
Subroutine is_interval: not called CC=1 SCAR=6.9
4885  
4886 sub pass_error
4887 0 ▶ {
Subroutine pass_error: not called CC=2 SCAR=17.9
4888 0 my $self = shift( @_ );
4889 0 ▶ if( Wanted::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (Wanted::want("OBJECT")) 0 0 0
4890 {
4891 0 rreturn( DateTime::Format::Intl::NullObject->new );
4892 }
4893 0 return;
4894 }
4895  
4896 # If the resulting best pattern has missing components, as per the LDML, it is patched
4897 # If it has been patched, this returns the patched pattern; undef by default
4898 0 ▶ sub patched_pattern { return( shift->_set_get_prop( 'patched_pattern', @_ ) ); }
Subroutine patched_pattern: not called CC=1 SCAR=6.9
4899  
4900 # Same as patched_pattern, but for skeleton
4901 0 ▶ sub patched_skeleton { return( shift->_set_get_prop( 'patched_skeleton', @_ ) ); }
Subroutine patched_skeleton: not called CC=1 SCAR=6.9
4902  
4903 # The actual pattern
4904 55773 ▶ sub pattern { return( shift->_set_get_prop( 'pattern', @_ ) ); }
Subroutine pattern: called CC=1 SCAR=0.0
4905  
4906 # This is the skeleton derived from the pattern, so it does not necessarily match the actual skeleton
4907 83688 ▶ sub pattern_skeleton { return( shift->_set_get_prop( 'pattern_skeleton', @_ ) ); }
Subroutine pattern_skeleton: called CC=1 SCAR=0.0
4908  
4909 # Real skeleton from Unicode CLDR
4910 # It may be empty if this object is used for representing the user requested options
4911 28095 ▶ sub skeleton { return( shift->_set_get_prop( 'skeleton', @_ ) ); }
Subroutine skeleton: called CC=1 SCAR=0.0
4912  
4913 # For datetime format skeletons: array reference of single characters, i.e. component or symbol
4914 0 ▶ sub skeleton_components { return( shift->_set_get_prop( 'skeleton_components', @_ ) ); }
Subroutine skeleton_components: not called CC=1 SCAR=6.9
4915  
4916 0 ▶ sub skeleton_date_components { return( shift->_set_get_prop( 'skeleton_date_components', @_ ) ); }
Subroutine skeleton_date_components: not called CC=1 SCAR=6.9
4917  
4918 0 ▶ sub skeleton_time_components { return( shift->_set_get_prop( 'skeleton_time_components', @_ ) ); }
Subroutine skeleton_time_components: not called CC=1 SCAR=6.9
4919  
4920 # For datetime format skeletons: the array reference of tokens for the skeleton (not the pattern skeleton), i.e. each array entry is an hash with the properties 'component', 'len' and 'token'
4921 27597 ▶ sub skeleton_tokens { return( shift->_set_get_prop( 'skeleton_tokens', @_ ) ); }
Subroutine skeleton_tokens: called CC=1 SCAR=0.0
4922  
4923 574 ▶ sub time_components { return( shift->_set_get_prop( 'time_components', @_ ) ); }
Subroutine time_components: called CC=1 SCAR=0.0
4924  
4925 # The array reference of tokens, i.e. each array entry is an hash with the properties 'component', 'len' and 'token'
4926 56221 ▶ sub tokens { return( shift->_set_get_prop( 'tokens', @_ ) ); }
Subroutine tokens: called CC=1 SCAR=0.0
4927  
4928 sub _set_get_prop
4929 280595 ▶ {
Subroutine _set_get_prop: called CC=3 SCAR=11.0
4930 280595 my $self = shift( @_ );
4931 280595 ▶ my $prop = shift( @_ ) || die( "No object property was provided." );
Condition50%1/2
shift @_ || die('No object property was provided.')
l!l
2805950
MC/DC0%0/1
shift @_ || die('No object property was provided.')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
4932 280595 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 85463 195132 280595
4933 280595 return( $self->{ $prop } );
4934 }
4935  
4936 sub _split_skeleton
4937 55635 ▶ {
Subroutine _split_skeleton: called CC=8 SCAR=20.8
4938 55635 my $self = shift( @_ );
4939 55635 my $skel = shift( @_ );
4940 55635 $skel =~ s/[^a-zA-Z]+//g;
4941 55635 my $tokens = [];
4942 55635 my $components = [];
4943 55635 my $date_elements =
4944 {
4945 'c' => 1,
4946 'd' => 1,
4947 'D' => 1,
4948 'e' => 1,
4949 'E' => 1,
4950 'F' => 1,
4951 'g' => 1,
4952 'G' => 1,
4953 'L' => 1,
4954 'M' => 1,
4955 'q' => 1,
4956 'Q' => 1,
4957 'r' => 1,
4958 'u' => 1,
4959 'U' => 1,
4960 'w' => 1,
4961 'W' => 1,
4962 'y' => 1,
4963 'Y' => 1,
4964 };
4965 55635 my $time_elements =
4966 {
4967 'h' => 1,
4968 'H' => 1,
4969 'j' => 1,
4970 'k' => 1,
4971 'K' => 1,
4972 'm' => 1,
4973 'O' => 1,
4974 's' => 1,
4975 'S' => 1,
4976 'v' => 1,
4977 'V' => 1,
4978 'x' => 1,
4979 'X' => 1,
4980 'z' => 1,
4981 'Z' => 1,
4982 };
4983 55635 my $date_components = [];
4984 55635 my $time_components = [];
4985 55635 foreach my $component ( split( //, $skel ) )
4986 {
4987 256357 ▶ if( scalar( @$tokens ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tokens and $tokens->[-1]{'component'} eq $component) { } 92808 163549 256357
Condition100%3/3
scalar @$tokens and $tokens->[-1]{"component"} eq $component
!ll&&!rl&&r
5563510791492808
MC/DC100%2/2
scalar @$tokens and $tokens->[-1]{"component"} eq $component
scalar @$tokens $tokens->[-1]{"component"} eq $component
Truth table100%3/3
A and B
A= scalar @$tokensB= $tokens->[-1]{"component"} eq $component
ABresult
0X0
100
111
4988 $tokens->[-1]->{component} eq $component )
4989 {
4990 92808 $tokens->[-1]->{token} .= $component;
4991 }
4992 else
4993 {
4994 163549 ▶ if( exists( $time_elements->{ $component } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $time_elements->{$component}) { } 38565 124984 163549
elsif (exists $date_elements->{$component}) { } 117615 7369 124984
4995 {
4996 38565 push( @$time_components, $component );
4997 }
4998 elsif( exists( $date_elements->{ $component } ) )
4999 {
5000 117615 push( @$date_components, $component );
5001 }
5002 163549 push( @$components, $component );
5003 163549 ▶ $tokens->[-1]->{len} = length( $tokens->[-1]->{token} ) if( scalar( @$tokens ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$tokens 107914 55635 163549
5004 163549 push( @$tokens, { component => $component, token => $component });
5005 }
5006 }
5007 55635 ▶ $tokens->[-1]->{len} = length( $tokens->[-1]->{token} ) if( scalar( @$tokens ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$tokens 55635 0 55635
5008 55635 return( $tokens, $components, $date_components, $time_components );
5009 }
5010 }
5011  
5012 11 1;
5013 # NOTE: POD
5014 __END__
↑ Summary