blib/lib/DateTimeX/TO_JSON.pm

filter: Statementstmt 100% 27 / 27 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 97.9% 47 / 48 CC 6 SCAR 12.0
CC
6
Cov
97%
import
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
↑ Summary
1 # ABSTRACT: Adds a TO_JSON method to DateTime
2  
3 package DateTimeX::TO_JSON;
4 3 $DateTimeX::TO_JSON::VERSION = '0.0.2';
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
11 3 my ($class, @args) = @_;
12  
13 ## Only deal with formatter just now but might deal with more later
14 ## such as importing DateTime itself
15 3 my %args;
16 3 ▶ while ($_ = shift @args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = shift @args) 2 3 5
17 2 ▶ if ( $_ eq 'formatter' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "formatter") 2 0 2
18 2 $args{$_} = shift @args;
19 }
20 }
21  
22 3 ▶ if ( $args{formatter} && ref($args{formatter}) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'formatter'} and ref $args{'formatter'}) { } 1 2 3
elsif ($args{'formatter'}) { } 1 1 2
Condition100%3/3
$args{"formatter"} and ref $args{"formatter"}
!ll&&!rl&&r
111
MC/DC100%2/2
$args{"formatter"} and ref $args{"formatter"}
$args{"formatter"} ref $args{"formatter"}
Truth table100%3/3
A and B
A= $args{"formatter"}B= ref $args{"formatter"}
ABresult
0X0
100
111
23 1 ▶ *DateTime::TO_JSON = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
24 1 $args{formatter}->format_datetime($_[0]);
25 }
26 1 }
27 elsif ( $args{formatter} ) {
28 1 Class::Load::load_class $args{formatter};
29 1 ▶ *DateTime::TO_JSON = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 1 $args{formatter}->new->format_datetime($_[0]);
31 }
32 1 }
33 else {
34 1 ▶ *DateTime::TO_JSON = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 1 $_[0]->datetime;
36 }
37 1 }
38 }
39  
40 3 1;
41  
42 __END__
↑ Summary