| 1 | package DateTimeX::Factory; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use 5.010_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | our $VERSION = '1.00'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | new => 0, | |||||||||||||||||||||||||||
| 10 | rw => [qw/default_options/], | ||||||||||||||||||||||||||||
| 11 | 4 | ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 7 | my ($class, %default_options) = @_; | |||||||||||||||||||||||||||
| 18 | 7 | bless {default_options => \%default_options}, $class; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub create {shift->_call_factory_method('new' => @_)} | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | sub now {shift->_call_factory_method('now' => @_)} | ||||||||||||||||||||||||||
|
Subroutine
now: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | sub from_epoch {shift->_call_factory_method('from_epoch' => @_)} | ||||||||||||||||||||||||||
|
Subroutine
from_epoch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 9 | ▶ | sub today {shift->_call_factory_method('today' => @_)} | ||||||||||||||||||||||||||
|
Subroutine
today: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | sub last_day_of_month {shift->_call_factory_method('last_day_of_month' => @_)} | ||||||||||||||||||||||||||
|
Subroutine
last_day_of_month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | sub from_day_of_year {shift->_call_factory_method('from_day_of_year' => @_)} | ||||||||||||||||||||||||||
|
Subroutine
from_day_of_year: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 24 | ▶ | sub _call_factory_method { | ||||||||||||||||||||||||||
|
Subroutine
_call_factory_method: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 24 | my ($self, $method, @params) = @_; | |||||||||||||||||||||||||||
| 30 | 24 | DateTime->$method(%{$self->default_options}, @params); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 12 | ▶ | sub strptime { | ||||||||||||||||||||||||||
|
Subroutine
strptime: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 12 | my ($self, $string, $pattern) = @_; | |||||||||||||||||||||||||||
| 35 | return DateTime::Format::Strptime->new( | ||||||||||||||||||||||||||||
| 36 | pattern => $pattern, | ||||||||||||||||||||||||||||
| 37 | 12 | %{$self->default_options}, | |||||||||||||||||||||||||||
| 38 | )->parse_datetime($string); | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | ▶ | sub from_mysql_datetime { | ||||||||||||||||||||||||||
|
Subroutine
from_mysql_datetime: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 3 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 3 | ▶ | return if !defined $string || $string eq '0000-00-00 00:00:00'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $string or $string eq "0000-00-00 00:00:00"
MC/DC0%0/2
not defined $string or $string eq "0000-00-00 00:00:00"
not defined $string
$string eq "0000-00-00 00:00:00"
Truth table33%1/3
not(A) or B
A= not defined $stringB= $string eq "0000-00-00 00:00:00"
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | return $self->strptime($string, '%Y-%m-%d %H:%M:%S'); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | ▶ | sub from_ymd { | ||||||||||||||||||||||||||
|
Subroutine
from_ymd: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 6 | my ($self, $string, $delimiter) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | ▶ | $delimiter //= '-'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$delimiter //= "-"
MC/DC100%1/1
$delimiter //= "-"
$delimiter
Truth table100%2/2
A
A= $delimiter
| |||||||||||||||||||||||||||||
| 53 | 6 | return $self->strptime($string, join($delimiter, '%Y','%m','%d')); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | ▶ | sub from_mysql_date { | ||||||||||||||||||||||||||
|
Subroutine
from_mysql_date: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 3 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | ▶ | return if !defined $string || $string eq '0000-00-00'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $string or $string eq "0000-00-00"
MC/DC0%0/2
not defined $string or $string eq "0000-00-00"
not defined $string
$string eq "0000-00-00"
Truth table33%1/3
not(A) or B
A= not defined $stringB= $string eq "0000-00-00"
| |||||||||||||||||||||||||||||
| 60 | 3 | return $self->from_ymd($string); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 3 | ▶ | sub yesterday {shift->today(@_)->subtract(days => 1)} | ||||||||||||||||||||||||||
|
Subroutine
yesterday: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | sub tommorow {shift->today(@_)->add(days => 1)} | ||||||||||||||||||||||||||
|
Subroutine
tommorow: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | 1; | |||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||