| 1 | package DateTime::Format::Natural::Duration; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 27 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 27 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | 27 | ▶ | use DateTime::Format::Natural::Duration::Checks; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 27 | ▶ | use List::Util 1.33 qw(all); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 27 | our $VERSION = '0.08'; | |||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | sub _pre_duration | ||||||||||||||||||
| 12 | 1258 | ▶ | { | ||||||||||||||||
|
Subroutine
_pre_duration: called CC=7 SCAR=19.5
| |||||||||||||||||||
| 13 | 1258 | my $self = shift; | |||||||||||||||||
| 14 | 1258 | my ($date_strings) = @_; | |||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | my $check_if = sub | ||||||||||||||||||
| 17 | 3637 | ▶ | { | ||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||
| 18 | 3637 | my $sub = '_' . shift; | |||||||||||||||||
| 19 | 3637 | my $class = join '::', (__PACKAGE__, 'Checks'); | |||||||||||||||||
| 20 | 3637 | ▶ | my $check = $class->can($sub) or die "$sub() not found in $class"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | 3637 | return $check->($self->{data}->{duration}, $date_strings, @_); | |||||||||||||||||
| 23 | 1258 | }; | |||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 1258 | my ($present, $extract, $adjust, @indexes); | |||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | 1258 | ▶ | if ($check_if->('for', \$present)) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 28 | 55 | @{$self->{insert}}{qw(datetime trace)} = do { | |||||||||||||||||
| 29 | 55 | my $dt = $self->parse_datetime($present); | |||||||||||||||||
| 30 | 55 | ($dt, $self->{traces}[0]); | |||||||||||||||||
| 31 | }; | ||||||||||||||||||
| 32 | 55 | ▶ | if ($self->{running_tests}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 33 | 48 | $self->{insert}{truncated} = $self->_get_truncated; | |||||||||||||||||
| 34 | } | ||||||||||||||||||
| 35 | } | ||||||||||||||||||
| 36 | elsif ($check_if->('first_to_last', \$extract)) { | ||||||||||||||||||
| 37 | 27 | ▶ | if (my ($complete) = $date_strings->[1] =~ $extract) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 38 | 27 | $date_strings->[0] .= " $complete"; | |||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | } | ||||||||||||||||||
| 41 | elsif ($check_if->('from_count_to_count', \$extract, \$adjust, \@indexes)) { | ||||||||||||||||||
| 42 | 899 | ▶ | if (my ($complete) = $date_strings->[$indexes[0]] =~ $extract) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 43 | 899 | $adjust->($date_strings, $indexes[1], $complete); | |||||||||||||||||
| 44 | } | ||||||||||||||||||
| 45 | } | ||||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | sub _post_duration | ||||||||||||||||||
| 49 | 1258 | ▶ | { | ||||||||||||||||
|
Subroutine
_post_duration: called CC=4 SCAR=13.9
| |||||||||||||||||||
| 50 | 1258 | my $self = shift; | |||||||||||||||||
| 51 | 1258 | my ($queue, $traces, $truncated) = @_; | |||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | 1258 | my %assign = ( | |||||||||||||||||
| 54 | datetime => $queue, | ||||||||||||||||||
| 55 | trace => $traces, | ||||||||||||||||||
| 56 | truncated => $truncated, | ||||||||||||||||||
| 57 | ); | ||||||||||||||||||
| 58 | 1258 | ▶ | delete $assign{truncated} unless $self->{running_tests}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | 1258 | ▶ | if (all { exists $self->{insert}{$_} } keys %assign) { | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||
| 61 | 55 | unshift @{$assign{$_}}, $self->{insert}{$_} foreach keys %assign; | |||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | } | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | sub _save_state | ||||||||||||||||||
| 66 | 2297 | ▶ | { | ||||||||||||||||
|
Subroutine
_save_state: called CC=3 SCAR=11.0
| |||||||||||||||||||
| 67 | 2297 | my $self = shift; | |||||||||||||||||
| 68 | 2297 | my %args = @_; | |||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | 2297 | ▶ | return if %{$self->{state}}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | 2294 | ▶ | unless ($args{valid_expression}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 73 | 3 | %{$self->{state}} = %args; | |||||||||||||||||
| 74 | } | ||||||||||||||||||
| 75 | } | ||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | sub _restore_state | ||||||||||||||||||
| 78 | 1258 | ▶ | { | ||||||||||||||||
|
Subroutine
_restore_state: called CC=5 SCAR=16.1
| |||||||||||||||||||
| 79 | 1258 | my $self = shift; | |||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | 1258 | my %state = %{$self->{state}}; | |||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | 1258 | ▶ | if (%state) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 84 | $state{valid_expression} | ||||||||||||||||||
| 85 | 3 | ▶ | ? $self->_set_valid_exp | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 86 | : $self->_unset_valid_exp; | ||||||||||||||||||
| 87 | |||||||||||||||||||
| 88 | $state{failure} | ||||||||||||||||||
| 89 | 3 | ▶ | ? $self->_set_failure | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 90 | : $self->_unset_failure; | ||||||||||||||||||
| 91 | |||||||||||||||||||
| 92 | defined $state{error} | ||||||||||||||||||
| 93 | ? $self->_set_error($state{error}) | ||||||||||||||||||
| 94 | 3 | ▶ | : $self->_unset_error; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 95 | } | ||||||||||||||||||
| 96 | } | ||||||||||||||||||
| 97 | |||||||||||||||||||
| 98 | 27 | 1; | |||||||||||||||||
| 99 | __END__ | ||||||||||||||||||