blib/lib/Template/Plugin/DateTime.pm

filter: Statementstmt 100% 37 / 37 Branchbran 90.0% 9 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 94.9% 56 / 59 CC 8 SCAR 15.6
CC
8
Cov
96%
new
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.7
↑ Summary
1 package Template::Plugin::DateTime;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Template::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use vars qw($AUTHORITY $VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 BEGIN
10 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $VERSION = '0.06002';
12 1 $AUTHORITY = 'cpan:DMAKI';
13 1 @ISA = (qw(Template::Plugin));
14 }
15  
16 sub new
17 10 ▶{
Subroutine new: called CC=8 SCAR=20.8
Pod documented
18 10 my $class = shift;
19 10 my $context = shift;
20  
21 10 ▶ my %args = ref($_[0]) eq 'HASH' ? %{$_[0]} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 10 0 10
22  
23 # boolean args: now, today, last_day_of_month
24 10 foreach my $arg (qw(now today last_day_of_month)){
25 23 ▶ if (delete $args{$arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args{$arg}) 5 18 23
26 5 return DateTime->$arg(%args);
27 }
28 }
29  
30 # args that require to proxy the parameter: from_epoch, from_object
31 5 ▶ if (my $epoch = delete $args{from_epoch}) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $epoch = delete $args{'from_epoch'}) { } 1 4 5
elsif (my $object = delete $args{'from_object'}) { } 1 3 4
elsif (my $timestr = delete $args{'from_string'}) { } 1 2 3
32 1 return DateTime->from_epoch(epoch => $epoch, %args);
33 } elsif (my $object = delete $args{from_object}) {
34 1 return DateTime->from_object(object => $object, %args);
35 } elsif (my $timestr = delete $args{from_string}) {
36 1 ▶ my $pattern = delete $args{pattern} || '%Y-%m-%d %H:%M:%S';
Condition50%1/2
delete $args{'pattern'} || '%Y-%m-%d %H:%M:%S'
l!l
10
MC/DC0%0/1
delete $args{'pattern'} || '%Y-%m-%d %H:%M:%S'
delete $args{'pattern'}
Truth table50%1/2
A
A= delete $args{'pattern'}
Aresult
11
00
37 1 my $parser = DateTime::Format::Strptime->new( pattern => $pattern, %args);
38 1 my $dt = $parser->parse_datetime($timestr);
39 1 return $dt;
40 }
41  
42 # none of the above, use regular call to new.
43 2 return DateTime->new(%args);
44 }
45  
46 1 1;
47  
48 __END__
↑ Summary