| 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
Condition66%2/3
defined $$value_ref and length $$value_ref
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
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | my ($parsed) = eval { Time::Duration::Parse::parse_duration($$value_ref) }; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | if ( not $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
defined $$value_ref and length $$value_ref and $$value_ref =~ /^\s*\d+\s*$/
defined $$value_ref and length $$value_ref
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*$/
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||