Natural/Utils.pm

filter: Statementstmt 94.8% 55 / 58 Branchbran 90.0% 9 / 10 Conditioncond 83.3% 10 / 12 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 90.6% 87 / 96 CC 11 SCAR 13.5
CC
11
Cov
92%
_trace_string
7.0
_valid
3.1
trim
3.0
CRAP 3.9
« Natural/Duration.pm ↑ Summary Natural/Calc.pm »
1 package DateTime::Format::Natural::Utils;
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 27 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use boolean qw(true false);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 27 our ($VERSION, @EXPORT_OK);
9  
10 27 $VERSION = '0.08';
11 27 @EXPORT_OK = qw(trim);
12  
13 sub _valid_date
14 3422 ▶{
Subroutine _valid_date: called CC=1 SCAR=0.0
15 3422 my $self = shift;
16 3422 return $self->_valid(@_,
17 { units => [ qw(year month day) ],
18 error => '(date is not valid)',
19 type => 'date',
20 },
21 );
22 }
23  
24 sub _valid_time
25 9217 ▶{
Subroutine _valid_time: called CC=1 SCAR=0.0
26 9217 my $self = shift;
27 9217 return $self->_valid(@_,
28 { units => [ qw(hour minute second) ],
29 error => '(time is not valid)',
30 type => 'time',
31 },
32 );
33 }
34  
35 sub _valid
36 12639 ▶{
Subroutine _valid: called CC=3 SCAR=11.2
37 12639 my $self = shift;
38 12639 my $opts = pop;
39 12639 my %values = @_;
40  
41 12639 delete $values{nanosecond}; # always valid
42  
43 12639 my %set = map { $_ => $self->{datetime}->$_ } @{$opts->{units}};
44  
45 12639 ▶ while (my ($unit, $value) = each %values) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %values) 25010 12639 37649
46 25010 $set{$unit} = $value;
47 }
48  
49 12639 my $checker = '_check' . "_$opts->{type}";
50  
51 12639 ▶ if ($self->$checker(map $set{$_}, @{$opts->{units}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$checker(map($set{$_}, @{$$opts{'units'};}))) { } 12639 0 12639
52 12639 return true;
53 }
54 else {
55 0 $self->_set_failure;
56 0 $self->_set_error($opts->{error});
57 0 return false;
58 }
59 }
60  
61 sub _trace_string
62 12003 ▶{
Subroutine _trace_string: called CC=7 SCAR=19.5
63 12003 my $self = shift;
64  
65 12003 my ($trace, $modified, $keyword) = map $self->{$_}, qw(trace modified keyword);
66  
67 12003 ▶ $trace ||= [];
Condition50%1/2
$trace ||= []
l!l
120030
MC/DC0%0/1
$trace ||= []
$trace
Truth table50%1/2
A
A= $trace
Aresult
11
00
68 12003 ▶ $modified ||= {};
Condition100%2/2
$modified ||= {}
l!l
11543460
MC/DC100%1/1
$modified ||= {}
$modified
Truth table100%2/2
A
A= $modified
Aresult
11
00
69 12003 ▶ $keyword ||= '';
Condition100%2/2
$keyword ||= ""
l!l
11453550
MC/DC100%1/1
$keyword ||= ""
$keyword
Truth table100%2/2
A
A= $keyword
Aresult
11
00
70  
71 12003 ▶ return undef unless (@$trace || %$modified || length $keyword);
Branch: 1 branch
BranchTrueFalseTotal
unless @$trace or %$modified or length $keyword 362 11641 12003
Condition83%5/6
@$trace or %$modified or length $keyword
l!l&&r!l&&!r
116410362
@$trace or %$modified
l!l&&r!l&&!r
11453188362
MC/DC66%2/3
@$trace or %$modified or length $keyword
@$trace %$modified length $keyword
Truth table75%3/4
A or B or C
A= @$traceB= %$modifiedC= length $keyword
ABCresult
1XX1
01X1
0011
0000
72  
73 11641 my $i;
74 11641 my %order = map { $_ => $i++ } @{$self->{data}->__units('ordered')};
75  
76 return join "\n", grep length, $keyword, @$trace,
77 34483 map { my $unit = $_; "$unit: $modified->{$unit}" }
78 11641 sort { $order{$a} <=> $order{$b} }
79 keys %$modified;
80 }
81  
82 sub trim
83 13685 ▶{
Subroutine trim: called CC=3 SCAR=11.0
Pod undocumented
84 13685 ▶ local $_ = ref $_[0] eq 'SCALAR' ? ${$_[0]} : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'SCALAR' ? : 13474 211 13685
85  
86 13685 s/^\s+//;
87 13685 s/\s+$//;
88  
89 13685 ▶ return ref $_[0] eq 'SCALAR' ? do { ${$_[0]} = $_; '' } : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'SCALAR' ? : 13474 211 13685
90 }
91  
92 27 1;
93 __END__
« Natural/Duration.pm ↑ Summary Natural/Calc.pm »