| 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
| |||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | if ( $_ eq 'formatter' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 18 | 2 | $args{$_} = shift @args; | |||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | if ( $args{formatter} && ref($args{formatter}) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$args{"formatter"} and ref $args{"formatter"}
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"}
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||