DBI/Filter/Duration.pm

filter: Statementstmt 100% 30 / 30 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 88.1% 52 / 59 CC 7 SCAR 10.7
CC
7
Cov
91%
decode
4.2
encode
4.0
BEGIN
1.0
CRAP 2.9
« DBI/HasFilters.pm ↑ Summary DBI/Filter/base64.pm »
1 package Jifty::DBI::Filter::Duration;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base qw|Jifty::DBI::Filter|;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Time::Duration qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Time::Duration::Parse qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Jifty::DBI::Filter::Duration - Encodes time durations
13  
14 =head1 DESCRIPTION
15  
16 =head2 encode
17  
18 If value is defined, then encode it using
19 L<Time::Duration::Parse/parse_duration>, otherwise do nothing. If the value
20 can't be parsed, then set it to undef.
21  
22 =cut
23  
24 sub encode {
25 11 ▶ my $self = shift;
Subroutine encode: called CC=4 SCAR=13.9
Pod documented
26  
27 11 my $value_ref = $self->value_ref;
28 11 ▶ return unless defined $$value_ref and length $$value_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$value_ref and length $$value_ref 5 6 11
Condition66%2/3
defined $$value_ref and length $$value_ref
!ll&&!rl&&r
506
MC/DC50%1/2
defined $$value_ref and length $$value_ref
defined $$value_ref length $$value_ref
Truth table66%2/3
A and B
A= defined $$value_refB= length $$value_ref
ABresult
0X0
100
111
29  
30 6 my ($parsed) = eval { Time::Duration::Parse::parse_duration($$value_ref) };
31  
32 6 ▶ if ( not $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@) { } 5 1 6
33 5 $$value_ref = $parsed;
34 5 return 1;
35 }
36 else {
37 1 $$value_ref = undef;
38 1 return;
39 }
40 }
41  
42 =head2 decode
43  
44 If value is defined, then decode it using
45 L<Time::Duration/duration_exact> and L<Time::Duration/concise>,
46 otherwise do nothing.
47  
48 =cut
49  
50 sub decode {
51 11 ▶ my $self = shift;
Subroutine decode: called CC=4 SCAR=14.5
Pod documented
52  
53 11 my $value_ref = $self->value_ref;
54 11 ▶ return unless defined $$value_ref and length $$value_ref
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$value_ref and length $$value_ref and $$value_ref =~ /^\s*\d+\s*$/ 0 5 5
Condition66%4/6
defined $$value_ref and length $$value_ref and $$value_ref =~ /^\s*\d+\s*$/
!ll&&!rl&&r
605
defined $$value_ref and length $$value_ref
!ll&&!rl&&r
605
MC/DC33%1/3
defined $$value_ref and length $$value_ref and $$value_ref =~ /^\s*\d+\s*$/
defined $$value_ref length $$value_ref $$value_ref =~ /^\s*\d+\s*$/
Truth table50%2/4
A and B and C
A= defined $$value_refB= length $$value_refC= $$value_ref =~ /^\s*\d+\s*$/
ABCresult
0XX0
10X0
1100
1111
55 and $$value_ref =~ /^\s*\d+\s*$/;
56  
57 5 $$value_ref = Time::Duration::concise(Time::Duration::duration_exact($$value_ref));
58 }
59  
60 =head1 SEE ALSO
61  
62 L<Jifty::DBI::Filter>, L<Time::Duration>, L<Time::Duration::Parse>
63  
64 =cut
65  
66 1 1;
« DBI/HasFilters.pm ↑ Summary DBI/Filter/base64.pm »