| 1 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Inflator::DateTime; | ||||||||||||||||||||||||||||
| 4 | 27 | $HTML::FormFu::Inflator::DateTime::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: DateTime inflator | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 27 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 27 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 27 | extends 'HTML::FormFu::Inflator'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 27 | ▶ | use HTML::FormFu::Constants qw( $EMPTY_STR ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 27 | ▶ | use DateTime::Format::Builder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 27 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 27 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 27 | has strptime => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 17 | 27 | has time_zone => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has _builder => ( | ||||||||||||||||||||||||||||
| 20 | is => 'rw', | ||||||||||||||||||||||||||||
| 21 | 26 | ▶ | default => sub { DateTime::Format::Builder->new }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 27 | lazy => 1, | |||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 26 | ▶ | sub parser { | ||||||||||||||||||||||||||
|
Subroutine
parser: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 26 | my ( $self, $arg ) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 26 | ▶ | if ( exists $arg->{regex} && !ref $arg->{regex} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $arg->{"regex"} and not ref $arg->{"regex"}
MC/DC100%2/2
exists $arg->{"regex"} and not ref $arg->{"regex"}
exists $arg->{"regex"}
not ref $arg->{"regex"}
Truth table100%3/3
A and not(B)
A= exists $arg->{"regex"}B= not ref $arg->{"regex"}
| |||||||||||||||||||||||||||||
| 29 | 1 | $arg->{regex} = qr/$arg->{regex}/; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 26 | $self->_builder->parser($arg); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 26 | return $self; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 27 | ▶ | sub inflator { | ||||||||||||||||||||||||||
|
Subroutine
inflator: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 27 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 27 | ▶ | return if !defined $value || $value eq $EMPTY_STR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
MC/DC100%2/2
not defined $value or $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
not defined $value
$value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 25 | my $dt = $self->_builder->parse_datetime($value); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 22 | ▶ | if ( defined $self->time_zone ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 1 | $dt->set_time_zone( $self->time_zone ); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 22 | ▶ | if ( defined $self->strptime ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 11 | my $strptime = $self->strptime; | |||||||||||||||||||||||||||
| 50 | 11 | my %args; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 11 | ▶ | if ( ( reftype($strptime) || '' ) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
builtin::reftype($strptime) || ''
MC/DC100%1/1
builtin::reftype($strptime) || ''
builtin::reftype($strptime)
Truth table100%2/2
A
A= builtin::reftype($strptime)
| |||||||||||||||||||||||||||||
| 53 | 2 | %args = %$strptime; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||
| 56 | 9 | %args = ( pattern => $strptime ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # Make strptime format the date with the specified time_zone, | ||||||||||||||||||||||||||||
| 60 | # this is most likely what the user wants | ||||||||||||||||||||||||||||
| 61 | 11 | ▶ | if ( defined $self->time_zone ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | $args{time_zone} = $self->time_zone; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 11 | ▶ | if ( !exists $args{locale} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $args{"locale"} and defined(my $locale = $self->locale)
MC/DC0%0/2
not exists $args{"locale"} and defined(my $locale = $self->locale)
not exists $args{"locale"}
defined(my $locale = $self->locale)
Truth table33%1/3
not(A) and B
A= not exists $args{"locale"}B= defined(my $locale = $self->locale)
| |||||||||||||||||||||||||||||
| 66 | && defined( my $locale = $self->locale ) ) | ||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | 0 | $args{locale} = $locale; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 11 | my $formatter = DateTime::Format::Strptime->new(%args); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 11 | $dt->set_formatter($formatter); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 22 | return $dt; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 2 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | my $clone = $self->SUPER::clone(@_); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | $clone->_builder( $self->_builder->clone ); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | return $clone; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 27 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 27 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||