Transform.pm

filter: Statementstmt 55.2% 285 / 516 Branchbran 63.0% 87 / 138 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 24 / 24 Podpod 100% 2 / 2 totaltotal 57.9% 400 / 690 CC 77 SCAR 40.6
CC
77
Cov
57%
_re
148.6
_expand_compound_formats
72.6
_transform_functions
51.3
CRAP 57.9
« Transform/Functions.pm ↑ Summary Transform/Extensions.pm »
1 package Date::Transform;
2
3 # Object Model
4 #
5 # transform
6 # + source
7 # + filter
8 # + destination
9
10 # use lib 'C:/Documents and Settings/Christopher Brown/Desktop/CPAN';
11
12 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 # use Data::Dumper;
18 # use Benchmark qw(:all);
19 1 ▶use Switch 'Perl5', 'Perl6';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
22
23 1 ▶use Date::Transform::Closures; # Functions that create the closures.
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Date::Transform::Functions; # Functions used in the closures
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Date::Transform::Extensions; # Contains Extensions to Other Modules
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Date::Transform::Constants; # Contains Constant Definitions
Subroutine BEGIN: called CC=1 SCAR=0.0
27
28 1 require Exporter;
29 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 our @ISA = qw(Exporter);
31
32 # Items to export into callers namespace by default. Note: do not export
33 # names by default without a very good reason. Use EXPORT_OK instead.
34 # Do not simply export all your public functions/methods/constants.
35
36 # This allows declaration use Date::Manip::Transform ':all';
37 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
38 # will save memory.
39
40 1 our %EXPORT_TAGS = ( 'all' => [qw()] );
41 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
42 1 our @EXPORT = qw( @CONSTANTS );
43
44 1 our $VERSION = '0.11';
45
46 # Preloaded methods go here.
47
48 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.9
Pod documented
49
50 1 my $type = shift;
51 1 ▶ my $class = ref($type) || $type;
Condition33%1/3
ref $type || $type
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $type || $type
ref $type $type
Truth table33%1/3
A || B
A= ref $typeB= $type
ABresult
1X1
011
000
52 1 my $self;
53
54 # Arguments
55
56 1 ▶ if ( scalar(@_) < 2 ) { # Make sure that both arguments are given.
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ < 2) 0 1 1
57 0 carp("Both an input and an output arguments must be supplied.\n");
58 0 die;
59 }
60
61 1 $self->{source}->{format} = shift;
62 1 $self->{destination}->{format} = shift;
63
64 # Bless and return the object.
65 1 bless $self, $class;
66
67 1 $self->_initialize();
68
69 1 return $self;
70
71 }
72
73 ## SUBROUTINE: _initialize
74 ## Creates Transformation Function
75 1 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
76
77 1 my $self = shift;
78
79 # Expand Input & Output Formats
80 # From here on out we should deal exclusively with expanded formats.
81 $self->{source}->{expanded_format} =
82 1 _expand_compound_formats( $self->{source}->{format} );
83 $self->{destination}->{expanded_format} =
84 1 _expand_compound_formats( $self->{destination}->{format} );
85
86 ## We can check the expanded output format for validity by making sure that none of the %_ are
87 ## other than those acceptable to strftime function. We can raise an error if they are detected.
88 ##
89
90 ## CREATE PLACE for POSIX ARRAY OF DATE
91 ## sec, min, hour, mday, mon, year, wday
92 ## {filter} will be the array passed to Posix::strftime
93 1 my $ixhash_obj = Tie::IxHash->new();
94 1 $ixhash_obj->STORE( 'format', $self->{destination}->{expanded_format} );
95 1 $self->{filter}->{input} = $ixhash_obj;
96
97 # Generate records of the formats and orders.
98 # Retrieve input formats and order of formats.
99 $self->{source}->{formats} =
100 1 _parse_format_string( $self->{source}->{expanded_format} );
101 $self->{destination}->{formats} =
102 1 _parse_format_string( $self->{destination}->{expanded_format} );
103
104 1 $self->_crosscheck
105 ; # Does the input data supply everything for necessary for the output.
106 1 $self->_regexp; # Create regexp for matching.
107 1 $self->_transform_functions; # Create functions for mapping.
108
109 } # END SUBROUTINE: _initialize
110
111 ## SUBROUTINE: transform
112 ## Transforms the supplied date.
113 1 ▶sub transform {
Subroutine transform: called CC=4 SCAR=13.9
Pod documented
114
115 1 my $self = shift;
116 1 my $input = shift;
117
118 ## Set Defaults.
119 ## my @array = $self->{filter}->{input}->Values;
120
121 ## $matches will hold the values from the matched regular expression.
122 1 my $matches = Tie::IxHash->new();
123
124 ## SHOULD WE DO A CASE INSENSITIVE MATCH -- Default: Yes.
125
126 1 ▶ if ( $input =~ /$self->{filter}->{regexp}/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /$self->{'filter'}{'regexp'}/i) { } 1 0 1
127
128 ## TEMPORARILY DISABLE strict 'refs' SO THAT WE CAN USE $$n.
129 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
130
131 ## Create Values from RegularExpression to Store in Cache.
132 ## Foreach of the input formats,
133 ## name => value from regexp
134
135 ## THIS IS THE SECOND MOST LIMITING STEP @ 1100/sec
136 1 foreach ( $self->{source}->{formats}->Keys ) {
137 $matches->Push( $_,
138 7 ${ $self->{source}->{formats}->IndexFromKey($_) + 1 } );
139 }
140
141 ## REENABLE strict
142 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
143
144 ## SET matches to object.
145 1 $self->{filter}->{matches} = $matches;
146
147 ## PERFORM EACH OF THE TRANSFORMATIONS
148 ## THIS IS THE TIME LIMITING STEP @ 900/sec
149 1 foreach my $transformation ( @{ $self->{filter}->{transformations} } ) {
150 6 $self->$transformation;
151 }
152
153 }
154 else {
155 carp(
156 "No date matched input string, \"$input\".\nUsing Regular Expression: ",
157 0 $self->{filter}->{regexp}, ".\n"
158 );
159 }
160
161 1 return POSIX::strftime( $self->{filter}->{input}->Values );
162
163 } # END SUBROUTINE: transform
164
165 ## SUBROUTINE: _transform_functions
166 ## Creates and stores the closures to be used in the transformation
167 1 ▶sub _transform_functions {
Subroutine _transform_functions: called CC=22 SCAR=39.4
168
169 1 my $self = shift;
170
171 1 my $required = $self->{filter}->{requirements};
172 1 my $supplied = $self->{source}->{formats};
173 1 my $filter = $self->{filter}->{input};
174 1 my $transformations = $self->{filter}->{transformations};
175
176 ## 1. SECONDS
177 1 ▶ if ( exists $required->{'S'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $required->{"S"}) 1 0 1
178
179 # Generate second code.
180
181 1 ▶ if ( $supplied->EXISTS('S') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($supplied->EXISTS('S')) { } 1 0 1
182
183 1 my $f1 = mk_passthru('S');
184 1 my $function = mk_set_filter_input( 'S', $f1 );
185
186 1 push ( @{ $self->{filter}->{transformations} }, $function );
187
188 }
189 else {
190
191 # SET DEFAULTS
192
193 }
194
195 }
196
197 ## 2. MINUTES
198 1 ▶ if ( $required->{'M'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($required->{"M"}) 1 0 1
199
200 1 ▶ if ( $supplied->EXISTS('M') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($supplied->EXISTS("M")) 1 0 1
201
202 1 my $f1 = mk_passthru('M');
203 1 my $function = mk_set_filter_input( 'M', $f1 );
204
205 1 push ( @{ $self->{filter}->{transformations} }, $function );
206
207 }
208
209 }
210
211 ## 3. HOURS
212 1 ▶ if ( exists $required->{'H'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $required->{"H"}) 1 0 1
213
214 1 my $function;
215
216 1 ▶ if ( $supplied->EXISTS('H') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($supplied->EXISTS('H')) { } 0 1 1
elsif ($supplied->EXISTS('k')) { } 0 1 1
elsif ($supplied->EXISTS('i') and $supplied->EXISTS('p')) { } 1 0 1
217
218 0 my $f1 = mk_passthru('H');
219 0 $function = mk_set_filter_input( 'H', $f1 );
220
221 }
222 elsif ( $supplied->EXISTS('k') ) {
223
224 0 my $f1 = mk_passthru('k');
225 0 $function = mk_set_filter_input( 'H', $f1 );
226
227 }
228 ▶ elsif ( $supplied->EXISTS('i') and $supplied->EXISTS('p') ) {
Condition33%1/3
$supplied->EXISTS("i") and $supplied->EXISTS("p")
!ll&&!rl&&r
001
MC/DC0%0/2
$supplied->EXISTS("i") and $supplied->EXISTS("p")
$supplied->EXISTS("i") $supplied->EXISTS("p")
Truth table33%1/3
A and B
A= $supplied->EXISTS("i")B= $supplied->EXISTS("p")
ABresult
0X0
100
111
229
230 1 my $f = \&iI_p_to_strftime_H;
231 1 my $f1 = mk_function( $f, 'i', 'p' );
232 1 $function = mk_set_filter_input( 'H', $f1 );
233
234 #= '$self->{filter}->{input}->[3] = $' . $supplied->IndexFromKey('H');
235 #$function = '$self->{filter}->{input}->[3] = $' . $supplied->IndexFromKey('H') . ' + 12' if ($ 0);
236
237 }
238
239 1 push ( @{ $self->{filter}->{transformations} }, $function );
240 }
241
242 ## 4. MONTHDAY
243 1 ▶ if ( exists $required->{'d'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $required->{"d"}) 1 0 1
244
245 1 my $function;
246
247 1 ▶ if ( $supplied->EXISTS('d') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($supplied->EXISTS('d')) { } 0 1 1
elsif ($supplied->EXISTS('e')) { } 1 0 1
248
249 0 my $f1 = mk_passthru('d');
250 0 $function = mk_set_filter_input( 'd', $f1 );
251
252 }
253 elsif ( $supplied->EXISTS('e') ) {
254
255 1 my $f1 = mk_passthru('e');
256 1 $function = mk_set_filter_input( 'd', $f1 );
257
258 }
259
260 1 push ( @{ $self->{filter}->{transformations} }, $function );
261
262 }
263
264 ## 5. MONTH
265 1 ▶ if ( exists $required->{'m'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $required->{"m"}) 1 0 1
266
267 1 my $function;
268
269 1 ▶ if ( $supplied->EXISTS('m') ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($supplied->EXISTS('m')) { } 0 1 1
elsif ($supplied->EXISTS('f')) { } 0 1 1
elsif ($supplied->EXISTS('b')) { } 0 1 1
elsif ($supplied->EXISTS('h')) { } 0 1 1
elsif ($supplied->EXISTS('B')) { } 1 0 1
270
271 0 my $f = \&m_to_strftime_m;
272 0 my $f1 = mk_function( $f, 'm' );
273 0 $function = mk_set_filter_input( 'm', $f1 );
274
275 }
276 elsif ( $supplied->EXISTS('f') ) {
277
278 0 my $f = \&m_to_strftime_m;
279 0 my $f1 = mk_function( $f, 'f' );
280 0 $function = mk_set_filter_input( 'm', $f1 );
281
282 }
283 elsif ( $supplied->EXISTS('b') ) {
284
285 0 my $f = \&bh_to_strftime_m;
286 0 my $f1 = mk_function( $f, 'b' );
287 0 $function = mk_set_filter_input( 'm', $f1 );
288
289 }
290 elsif ( $supplied->EXISTS('h') ) {
291
292 0 my $f = \&bh_to_strftime_m;
293 0 my $f1 = mk_function( $f, 'h' );
294 0 $function = mk_set_filter_input( 'm', $f1 );
295
296 }
297 elsif ( $supplied->EXISTS('B') ) {
298
299 1 my $f = \&B_to_strftime_m;
300 1 my $f1 = mk_function( $f, 'B' );
301 1 $function = mk_set_filter_input( 'm', $f1 );
302
303 }
304
305 1 push ( @{ $self->{filter}->{transformations} }, $function );
306
307 }
308
309 ## 6. YEAR
310 1 ▶ if ( exists $required->{'Y'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $required->{"Y"}) 1 0 1
311
312 1 my $function;
313
314 1 ▶ if ( $supplied->EXISTS('y') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($supplied->EXISTS('y')) { } 1 0 1
elsif ($supplied->EXISTS('Y')) { } 0 0 0
315
316 1 my $f1 = mk_passthru('y');
317 1 $function = mk_set_filter_input( 'y', $f1 );
318
319 }
320 elsif ( $supplied->EXISTS('Y') ) {
321
322 0 my $f = \&Y_to_strftime_y;
323 0 my $f1 = mk_function( $f, 'Y' );
324 0 $function = mk_set_filter_input( 'y', $f1 );
325 }
326
327 1 push ( @{ $self->{filter}->{transformations} }, $function );
328
329 }
330
331 1 return 1;
332
333 }
334
335 ## SUBROUTINE: _regexp
336 ## Creates the regexp used in the transformation
337 1 ▶sub _regexp {
Subroutine _regexp: called CC=2 SCAR=6.9
338
339 ## Converts input format into regular expression format.
340 1 my $self = shift;
341
342 1 my $regexp = $self->{source}->{expanded_format};
343
344 # Replace Special Characters
345 1 $regexp =~ s/\%n/\\n/g;
346 1 $regexp =~ s/\%t/\\t/g;
347 1 $regexp =~ s/\%\%/\\%/g;
348 1 $regexp =~ s/\%\+/\\+/g;
349
350 1 foreach ( $self->{source}->{formats}->Keys ) {
351 7 my $re_replacement = "(" . &_re($_) . ")";
352 7 $regexp =~ s/\%($_)/$re_replacement/eg;
353 }
354
355 1 $self->{filter}->{regexp} = $regexp;
356
357 # return $regexp;
358
359 } # END SUBROUTINE: _regexp
360
361 ## SUBROUTINE: _crosscheck
362 ## ensures that the input string supplies all the necessary information
363 ## for the requested output. Requires some complex logic (not implemented yet.)
364 1 ▶sub _crosscheck {
Subroutine _crosscheck: called CC=3 SCAR=11.3
365
366 # Checks to see if the necessary data elements the input_format supplies enough data.
367
368 1 my $self = shift;
369
370 # my %strftime_requirements;
371 # my @req;
372
373 # What are the output requirements.
374 1 my %or = _strftime_requirements( $self->{destination}->{formats}->Keys );
375 1 $self->{filter}->{requirements} = \%or;
376
377 # What are the input supplied.
378 1 my %is = _strftime_requirements( $self->{source}->{formats}->Keys );
379
380 # $self->{source}->{supplied} = \%is;
381
382 # Crosscheck outputs requested vs inputs supplied.
383 #my %is = map { $_ => 1 } @is;
384
385 1 foreach my $or ( sort keys %or ) {
386
387 6 ▶ if ( !$is{$or} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is{$or}) 0 6 6
388 0 carp
389 "WARNING: %$or is required by the output, but not supplied by the input.\n";
390
391 # die("\n") unless ( $is{$or} );
392 }
393
394 }
395
396 }
397
398 ## SUBROUTINE: _parse_format_string
399 ## Given a date string => href of elements in the string, aref of order of elements
400 ## Because we reverse the format string ... walking it backwards ... if an element
401 ## appears more than once, the REAL first occurence will be captured.
402 2 ▶sub _parse_format_string {
Subroutine _parse_format_string: called CC=3 SCAR=11.0
403
404 # Format String => href Elements in Sting, aref order of elements
405
406 2 my $format = shift;
407 2 my $index = 0;
408
409 2 my $ixhash_obj = Tie::IxHash->new();
410
411 2 $format = reverse($format); # REVERSE THE ORDER OF FORMAT.
412
413 # my $elements;
414 # my $order;
415
416 2 my ( $r1, $r2 );
417
418 2 $r1 = chop($format);
419
420 2 ▶ while ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 76 2 78
421
422 76 $r2 = $r1;
423 76 $r1 = chop($format);
424
425 # Test for format field.
426 76 ▶ if ( $r2 eq '%' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r2 eq "%") 39 37 76
427
428 # $elements->{$r1} = undef; # These will become storage recepticles later.
429 # push @{$order}, $r1;
430
431 # Since date information might appear twice in the string, we only want to take the first instance.
432 # next if ( $ixhash_obj->[0]->{$r1} );
433 # Make sure to put the new formats at the front of object.
434 39 $ixhash_obj->Push( $r1 => $index );
435 39 $r1 = chop($format);
436
437 39 $index++;
438 }
439
440 }
441
442 2 return $ixhash_obj;
443
444 }
445
446 ########################
447
448 ## SUBROUTINE: _expand_compound_formats
449 ## Expands compound formats to full formats.
450 2 ▶sub _expand_compound_formats {
Subroutine _expand_compound_formats: called CC=17 SCAR=42.8
451
452 2 my $format = shift;
453 2 my ( $expansion, $new_format );
454
455 2 $format = reverse $format;
456
457 2 my ( $r1, $r2 );
458 2 $r1 = chop $format;
459
460 2 ▶ while ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 54 2 56
461
462 54 $r2 = $r1;
463 54 $r1 = chop($format);
464
465 54 my $expansion;
466
467 # Test for format field.
468 54 ▶ if ( $r2 eq '%' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r2 eq '%') { } 28 26 54
469
470 28 given($r1) {
471
472 # COMPUND FORMATS
473
474 0 ▶ when [ "T", "X" ] { $expansion = "%H:%M:%S"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["T", "X"])) 1 27 28
475 0 ▶ when "c" { $expansion = "%a %b %e %H:%M:%S %z %Y"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("c")) 1 26 27
476 0 ▶ when [ "C", "u" ] { $expansion = "%a %b %e %H:%M:%S %z %Y"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["C", "u"])) 0 26 26
477 0 ▶ when "g" { $expansion = "%a, %d %b %Y %H:%M:%S %z"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("g")) 0 26 26
478 0 ▶ when [ "D", "x" ] { $expansion = "%m/%d/%y"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["D", "x"])) 1 25 26
479
480 0 ▶ when "r" { $expansion = "%I:%M:%S %p"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("r")) 0 25 25
481 0 ▶ when "R" { $expansion = "%H:%M"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("R")) 0 25 25
482 0 ▶ when "V" { $expansion = "%m%d%H%M%y"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("V")) 0 25 25
483 0 ▶ when "Q" { $expansion = "%Y%m%d"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("Q")) 0 25 25
484 0 ▶ when "q" { $expansion = "%Y%m%d%H%M%S"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("q")) 0 25 25
485 0 ▶ when "P" { $expansion = "%Y%m%d%H:%M:%S"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("P")) 0 25 25
486 0 ▶ when "F" { $expansion = "%A, %B %e, %Y"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("F")) 0 25 25
487 0 ▶ when "J" { $expansion = "%G-%W-%w"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("J")) 0 25 25
488 0 ▶ when "K" { $expansion = "%Y-%j"; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case('K')) { } 0 25 25
489
490 # when "" { $re = '' } # MORE.
491 # when "l" { $re = "[" . join( ' ', _re(b,e,R) ) . '|' . join( ' ', _re(b,e,Y) ) . "]" }
492 # Omitted for now, but logic can be included to solve the problem.
493
494 # Don't expand non compound factors
495 25 else { $expansion .= $r2 . $r1; }
496
497 25 } # End SWITCH
498
499 28 $r1 = chop($format);
500
501 }
502 else {
503
504 26 $expansion = $r2;
505
506 } # END if
507
508 54 $new_format .= $expansion;
509
510 } # END format WHILE
511
512 2 return $new_format;
513
514 }
515
516 ## SUBROUTINE: _strftime_requirements
517 ## Given a series of formats that are requested,
518 ## This function determines what is required by
519 ## strftime to suppy those requirements.
520 2 ▶sub _strftime_requirements {
Subroutine _strftime_requirements: called CC=9 SCAR=23.9
521
522 # OUTPUT REQUIREMENTS
523 # my $format;
524 2 my @formats = @_;
525 2 my @req;
526
527 2 foreach my $format (@formats) {
528
529 27 given($format) {
530
531 # Year
532 0 ▶ when [ "Y", "y", "G", "L" ] { push ( @req, 'Y' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["Y", "y", "G", "L"])) 3 24 27
533
534 # Month
535 0 ▶ when [ "m", "f", "b", "h", "B" ] { push ( @req, 'm' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["m", "f", "b", "h", "B"])) 4 20 24
536
537 # Week/Day of the year, Day of the week
538 20 ▶ when [ "U", "W", "j", "v", "a", "A", "w" ] {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["U", "W", "j", "v", "a", "A", "w"])) 6 14 20
539 6 push ( @req, 'Y', 'm', 'd' );
540 0 }
541
542 # Day of the Month
543 0 ▶ when [ "d", "e", "E" ] { push ( @req, 'd' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["d", "e", "E"])) 3 11 14
544
545 # Hour
546 0 ▶ when [ "H", "k", "i", "l", "p" ] { push ( @req, 'H' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["H", "k", "i", "l", "p"])) 4 7 11
547
548 # Minute
549 0 ▶ when ["M"] { push ( @req, 'M' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["M"])) 2 5 7
550
551 # Second
552 0 ▶ when ["S"] { push ( @req, 'S' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["S"])) 2 3 5
553
554 3 } # END SWITCH BLOCK
555
556 } # END @formats LOOP
557
558 # Remove duplicates from requirements
559 2 my %req = map { $_ => 1 } @req;
560
561 2 return %req; # return (keys(%req));
562
563 }
564
565 7 ▶sub _re {
Subroutine _re: called CC=22 SCAR=50.0
566
567 # Generate regular expression for the given format(s)
568 # In general the regular expressions should be
569 # restrictive and fast.
570 #
571
572 7 my $format = shift;
573
574 # my $regexp;
575
576 7 my $re;
577
578 7 given($format) {
579
580 # YEAR
581 0 ▶ when "y" { $re = '\d{2}'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("y")) 1 6 7
582 0 ▶ when [ "Y", "G", "L" ] { $re = '\d{4}'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["Y", "G", "L"])) 0 6 6
583
584 #Month
585 0 ▶ when "m" { $re = '[01]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("m")) 0 6 6
586 0 ▶ when "f" { $re = '\d{1}|1[0-2]'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("f")) 0 6 6
587 0 ▶ when [ "b", "h" ] {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["b", "h"])) 0 6 6
588 0 $re = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec';
589 0 }
590 6 ▶ when "B" {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("B")) 1 5 6
591 1 $re =
592 'January|February|March|April|May|June|July|August|September|October|November|December';
593 0 }
594 0 ▶ when [ "U", "W" ] { $re = '[0-5]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(["U", "W"])) 0 5 5
595
596 # Day
597 0 ▶ when "j" { $re = '[0-3]\d{2}'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("j")) 0 5 5
598 0 ▶ when "d" { $re = '[0-3]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("d")) 0 5 5
599 0 ▶ when "e" { $re = '[ |0|1|2|3]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("e")) 1 4 5
600 0 ▶ when "v" { $re = ' S| M| T| W|Th|F|Sa'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("v")) 0 4 4
601 0 ▶ when "a" { $re = 'Sun|Mon|Tue|Wed|Thu|Fri|Sat'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("a")) 0 4 4
602 0 ▶ when "A" {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("A")) 0 4 4
603 0 $re = 'Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday';
604 0 }
605 0 ▶ when "w" { $re = '1-7'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("w")) 0 4 4
606 0 ▶ when "E" { $re = '\d{1,2}st|nd|rd|th'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("E")) 0 4 4
607
608 # Hours
609 0 ▶ when "H" { $re = '[0-2]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("H")) 0 4 4
610 0 ▶ when "k" { $re = '[ 12]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("k")) 0 4 4
611 0 ▶ when "i" { $re = '[ 1]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("i")) 1 3 4
612 0 ▶ when "I" { $re = '[01]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("I")) 0 3 3
613 0 ▶ when "p" { $re = 'AM|PM'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("p")) 1 2 3
614
615 0 ▶ when [ "M", "S" ] { $re = '[0-6]\d'; }
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(['M', 'S'])) { } 2 0 2
616
617 0 else { carp "No Regular Expression found for POSIX format -- $format"; }
618
619 0 } # END case BLOCK
620
621 7 return $re
622
623 } # END SUBROUTINE _re
624
625 # Autoload methods go after =cut, and are processed by the autosplit program.
626
627 1 1;
628
629 __END__;
« Transform/Functions.pm ↑ Summary Transform/Extensions.pm »