line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jifty::DBI::Filter::Duration; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base qw|Jifty::DBI::Filter|; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
250
|
|
7
|
1
|
|
|
1
|
|
8
|
use Time::Duration qw(); |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
19
|
|
8
|
1
|
|
|
1
|
|
7
|
use Time::Duration::Parse qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
538
|
|
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
|
22
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
11
|
|
|
|
|
38
|
my $value_ref = $self->value_ref; |
28
|
11
|
100
|
66
|
|
|
143
|
return unless defined $$value_ref and length $$value_ref; |
29
|
|
|
|
|
|
|
|
30
|
6
|
|
|
|
|
14
|
my ($parsed) = eval { Time::Duration::Parse::parse_duration($$value_ref) }; |
|
6
|
|
|
|
|
34
|
|
31
|
|
|
|
|
|
|
|
32
|
6
|
100
|
|
|
|
971
|
if ( not $@ ) { |
33
|
5
|
|
|
|
|
15
|
$$value_ref = $parsed; |
34
|
5
|
|
|
|
|
33
|
return 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
1
|
|
|
|
|
4
|
$$value_ref = undef; |
38
|
1
|
|
|
|
|
25
|
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
|
26
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
11
|
|
|
|
|
47
|
my $value_ref = $self->value_ref; |
54
|
11
|
50
|
66
|
|
|
149
|
return unless defined $$value_ref and length $$value_ref |
|
|
|
66
|
|
|
|
|
55
|
|
|
|
|
|
|
and $$value_ref =~ /^\s*\d+\s*$/; |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
32
|
$$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; |