line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jifty::DBI::Filter::Duration; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use base qw|Jifty::DBI::Filter|; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
61
|
|
7
|
1
|
|
|
1
|
|
3
|
use Time::Duration qw(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
8
|
1
|
|
|
1
|
|
3
|
use Time::Duration::Parse qw(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
129
|
|
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, 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
|
|
|
11
|
1
|
16
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
11
|
|
|
|
|
26
|
my $value_ref = $self->value_ref; |
28
|
11
|
100
|
66
|
|
|
151
|
return unless defined $$value_ref and length $$value_ref; |
29
|
|
|
|
|
|
|
|
30
|
6
|
|
|
|
|
13
|
my ($parsed) = eval { Time::Duration::Parse::parse_duration($$value_ref) }; |
|
6
|
|
|
|
|
24
|
|
31
|
|
|
|
|
|
|
|
32
|
6
|
100
|
|
|
|
427
|
if ( not $@ ) { |
33
|
5
|
|
|
|
|
12
|
$$value_ref = $parsed; |
34
|
5
|
|
|
|
|
25
|
return 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
1
|
|
|
|
|
1
|
$$value_ref = undef; |
38
|
1
|
|
|
|
|
11
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 decode |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
If value is defined, then decode it using |
45
|
|
|
|
|
|
|
L and L, |
46
|
|
|
|
|
|
|
otherwise do nothing. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub decode { |
51
|
11
|
|
|
11
|
1
|
12
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
11
|
|
|
|
|
53
|
my $value_ref = $self->value_ref; |
54
|
11
|
50
|
66
|
|
|
117
|
return unless defined $$value_ref and length $$value_ref |
|
|
|
66
|
|
|
|
|
55
|
|
|
|
|
|
|
and $$value_ref =~ /^\s*\d+\s*$/; |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
22
|
$$value_ref = Time::Duration::concise(Time::Duration::duration_exact($$value_ref)); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SEE ALSO |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
L, L, L |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |