| 1 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Inflator::CompoundDateTime; | ||||||||||||||||||||||||||||
| 4 | 5 | $HTML::FormFu::Inflator::CompoundDateTime::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: CompoundDateTime inflator | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | extends 'HTML::FormFu::Inflator'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use HTML::FormFu::Constants qw( $EMPTY_STR ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use List::Util 1.33 qw( none ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | has strptime => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 19 | 5 | has field_order => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 5 | my @known_fields = qw( year month day hour minute second nanosecond time_zone ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | sub inflator { | ||||||||||||||||||||||||||
|
Subroutine
inflator: called CC=12 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 2 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | return if !defined $value || $value eq $EMPTY_STR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $value or $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
MC/DC0%0/2
not defined $value or $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
not defined $value
$value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
Truth table33%1/3
not(A) or B
A= not defined $valueB= $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | my ( $multi, @fields ) = @{ $self->parent->get_fields }; | |||||||||||||||||||||||||||
| 29 | 2 | my %input; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | if ( defined( my $order = $self->field_order ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | for my $order (@$order) { | |||||||||||||||||||||||||||
| 33 | croak "unknown DateTime field_order name" | ||||||||||||||||||||||||||||
| 34 | 3 | ▶ | if none { $order eq $_ } @known_fields; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | my $field = shift @fields; | |||||||||||||||||||||||||||
| 37 | 3 | my $name = $field->name; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | $input{$order} = $value->{$name}; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||
| 43 | 1 | for my $name ( keys %$value ) { | |||||||||||||||||||||||||||
| 44 | croak "unknown DateTime field name" | ||||||||||||||||||||||||||||
| 45 | 3 | ▶ | if none { $name eq $_ } @known_fields; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | %input = %$value; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | my $dt; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | eval { $dt = DateTime->new(%input) }; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | return $value if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | if ( defined $self->strptime ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 2 | my $strptime = $self->strptime; | |||||||||||||||||||||||||||
| 59 | 2 | my %args; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | if ( ( reftype($strptime) || '' ) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
builtin::reftype($strptime) || ''
MC/DC0%0/1
builtin::reftype($strptime) || ''
builtin::reftype($strptime)
Truth table50%1/2
A
A= builtin::reftype($strptime)
| |||||||||||||||||||||||||||||
| 62 | 0 | %args = %$strptime; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||
| 65 | 2 | %args = ( pattern => $strptime ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | my $formatter = DateTime::Format::Strptime->new(%args); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | $dt->set_formatter($formatter); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 2 | return $dt; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||