line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::split_date; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12559
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
108768
|
|
|
2
|
|
|
|
|
10
|
|
4
|
2
|
|
|
2
|
|
316
|
use Moo; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
6
|
|
5
|
2
|
|
|
2
|
|
1104
|
use Catmandu::Fix::Has; |
|
2
|
|
|
|
|
1269
|
|
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $DATE_REGEX = qr{ |
8
|
|
|
|
|
|
|
^([0-9]{4}) |
9
|
|
|
|
|
|
|
(?: [:-] ([0-9]{1,2}) |
10
|
|
|
|
|
|
|
(?: [:-] ([0-9]{1,2}) )? |
11
|
|
|
|
|
|
|
)? |
12
|
|
|
|
|
|
|
}x; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Catmandu::Fix::SimpleGetValue'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub emit_value { |
19
|
3
|
|
|
3
|
0
|
18926
|
my ($self, $var, $fixer) = @_; |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
8
|
my $date_re = $fixer->capture($DATE_REGEX); |
22
|
3
|
|
|
|
|
155
|
my $perl = <<EOF; |
23
|
|
|
|
|
|
|
if( is_string(${var}) && ${var} =~ ${date_re} ){ |
24
|
|
|
|
|
|
|
${var} = {}; |
25
|
|
|
|
|
|
|
${var}->{year} = \${1}; |
26
|
|
|
|
|
|
|
${var}->{month} = 1*\${2} if \${2}; |
27
|
|
|
|
|
|
|
${var}->{day} = 1*\${3} if \${3}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
EOF |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
__END__ |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Catmandu::Fix::split_date - split a date field into year, month and date |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# {date => "2001-09-11"} |
43
|
|
|
|
|
|
|
split_date('date') |
44
|
|
|
|
|
|
|
# => { date => { year => 2001, month => "9", day => "11" } } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# { datestamp => "2001:09" } |
47
|
|
|
|
|
|
|
split_date('datestamp') |
48
|
|
|
|
|
|
|
# => { datestamp => { year => 2001, month => "9" } } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
The date field is expanded if it contains a year, optionally followed by |
53
|
|
|
|
|
|
|
numeric month and day, each separated by C<-> or C<:>. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 AUTHOR |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Nicolas Franck, C<< <nicolas.franck at ugent.be> >> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SEE ALSO |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
L<Catmandu::Fix> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |