Natural/Duration.pm

filter: Statementstmt 100% 55 / 55 Branchbran 86.6% 26 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 95.7% 91 / 95 CC 17 SCAR 14.3
CC
17
Cov
95%
_pre_duration
7.0
_restore_state
5.0
_post_duration
4.0
CRAP 4.2
« Natural/Lang/EN.pm ↑ Summary Natural/Utils.pm »
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
BranchTrueFalseTotal
my $check = $class->can($sub) or die "$sub() not found in $class" 3637 0 3637
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
BranchTrueFalseTotal
if (&$check_if('for', \$present)) { } 55 1203 1258
elsif (&$check_if('first_to_last', \$extract)) { } 27 1176 1203
elsif (&$check_if('from_count_to_count', \$extract, \$adjust, \@indexes)) { } 899 277 1176
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
BranchTrueFalseTotal
if ($self->{"running_tests"}) 48 7 55
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
BranchTrueFalseTotal
if (my($complete) = $date_strings->[1] =~ /$extract/) 27 0 27
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
BranchTrueFalseTotal
if (my($complete) = $$date_strings[$indexes[0]] =~ /$extract/) 899 0 899
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
BranchTrueFalseTotal
unless $self->{"running_tests"} 268 990 1258
59  
60 1258 ▶ if (all { exists $self->{insert}{$_} } keys %assign) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { exists $self->{"insert"}{$_}; } , keys %assign)) 55 1203 1258
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
BranchTrueFalseTotal
if %{$self->{"state"};} 3 2294 2297
71  
72 2294 ▶ unless ($args{valid_expression}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"valid_expression"}) 3 2291 2294
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
BranchTrueFalseTotal
if (%state) 3 1255 1258
84 $state{valid_expression}
85 3 ▶ ? $self->_set_valid_exp
Branch: 1 branch
BranchTrueFalseTotal
$state{'valid_expression'} ? : 0 3 3
86 : $self->_unset_valid_exp;
87  
88 $state{failure}
89 3 ▶ ? $self->_set_failure
Branch: 1 branch
BranchTrueFalseTotal
$state{'failure'} ? : 1 2 3
90 : $self->_unset_failure;
91  
92 defined $state{error}
93 ? $self->_set_error($state{error})
94 3 ▶ : $self->_unset_error;
Branch: 1 branch
BranchTrueFalseTotal
defined $state{'error'} ? : 1 2 3
95 }
96 }
97  
98 27 1;
99 __END__
« Natural/Lang/EN.pm ↑ Summary Natural/Utils.pm »