line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Natural::Utils; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
251
|
use strict; |
|
26
|
|
|
|
|
82
|
|
|
26
|
|
|
|
|
841
|
|
4
|
26
|
|
|
26
|
|
180
|
use warnings; |
|
26
|
|
|
|
|
66
|
|
|
26
|
|
|
|
|
963
|
|
5
|
26
|
|
|
26
|
|
178
|
use base qw(Exporter); |
|
26
|
|
|
|
|
85
|
|
|
26
|
|
|
|
|
4084
|
|
6
|
26
|
|
|
26
|
|
237
|
use boolean qw(true false); |
|
26
|
|
|
|
|
82
|
|
|
26
|
|
|
|
|
354
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.08'; |
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(trim); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _valid_date |
14
|
|
|
|
|
|
|
{ |
15
|
3365
|
|
|
3365
|
|
6380
|
my $self = shift; |
16
|
3365
|
|
|
|
|
18682
|
return $self->_valid(@_, |
17
|
|
|
|
|
|
|
{ units => [ qw(year month day) ], |
18
|
|
|
|
|
|
|
error => '(date is not valid)', |
19
|
|
|
|
|
|
|
type => 'date', |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _valid_time |
25
|
|
|
|
|
|
|
{ |
26
|
9043
|
|
|
9043
|
|
17839
|
my $self = shift; |
27
|
9043
|
|
|
|
|
46964
|
return $self->_valid(@_, |
28
|
|
|
|
|
|
|
{ units => [ qw(hour minute second) ], |
29
|
|
|
|
|
|
|
error => '(time is not valid)', |
30
|
|
|
|
|
|
|
type => 'time', |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _valid |
36
|
|
|
|
|
|
|
{ |
37
|
12408
|
|
|
12408
|
|
22313
|
my $self = shift; |
38
|
12408
|
|
|
|
|
20455
|
my $opts = pop; |
39
|
12408
|
|
|
|
|
36006
|
my %values = @_; |
40
|
|
|
|
|
|
|
|
41
|
12408
|
|
|
|
|
24850
|
delete $values{nanosecond}; # always valid |
42
|
|
|
|
|
|
|
|
43
|
12408
|
|
|
|
|
20261
|
my %set = map { $_ => $self->{datetime}->$_ } @{$opts->{units}}; |
|
37224
|
|
|
|
|
214081
|
|
|
12408
|
|
|
|
|
27174
|
|
44
|
|
|
|
|
|
|
|
45
|
12408
|
|
|
|
|
108719
|
while (my ($unit, $value) = each %values) { |
46
|
24458
|
|
|
|
|
85218
|
$set{$unit} = $value; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
12408
|
|
|
|
|
34206
|
my $checker = '_check' . "_$opts->{type}"; |
50
|
|
|
|
|
|
|
|
51
|
12408
|
50
|
|
|
|
22111
|
if ($self->$checker(map $set{$_}, @{$opts->{units}})) { |
|
12408
|
|
|
|
|
70641
|
|
52
|
12408
|
|
|
|
|
38271
|
return true; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
0
|
|
|
|
|
0
|
$self->_set_failure; |
56
|
0
|
|
|
|
|
0
|
$self->_set_error($opts->{error}); |
57
|
0
|
|
|
|
|
0
|
return false; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _trace_string |
62
|
|
|
|
|
|
|
{ |
63
|
11699
|
|
|
11699
|
|
22775
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
11699
|
|
|
|
|
58214
|
my ($trace, $modified, $keyword) = map $self->{$_}, qw(trace modified keyword); |
66
|
|
|
|
|
|
|
|
67
|
11699
|
|
50
|
|
|
34081
|
$trace ||= []; |
68
|
11699
|
|
100
|
|
|
26608
|
$modified ||= {}; |
69
|
11699
|
|
100
|
|
|
26525
|
$keyword ||= ''; |
70
|
|
|
|
|
|
|
|
71
|
11699
|
100
|
100
|
|
|
33587
|
return undef unless (@$trace || %$modified || length $keyword); |
|
|
|
66
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
11339
|
|
|
|
|
17071
|
my $i; |
74
|
11339
|
|
|
|
|
18015
|
my %order = map { $_ => $i++ } @{$self->{data}->__units('ordered')}; |
|
90712
|
|
|
|
|
188667
|
|
|
11339
|
|
|
|
|
68783
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return join "\n", grep length, $keyword, @$trace, |
77
|
33492
|
|
|
|
|
55609
|
map { my $unit = $_; "$unit: $modified->{$unit}" } |
|
33492
|
|
|
|
|
138298
|
|
78
|
11339
|
|
|
|
|
62491
|
sort { $order{$a} <=> $order{$b} } |
|
33935
|
|
|
|
|
70454
|
|
79
|
|
|
|
|
|
|
keys %$modified; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub trim |
83
|
|
|
|
|
|
|
{ |
84
|
13381
|
100
|
|
13381
|
0
|
40150
|
local $_ = ref $_[0] eq 'SCALAR' ? ${$_[0]} : $_[0]; |
|
13170
|
|
|
|
|
29871
|
|
85
|
|
|
|
|
|
|
|
86
|
13381
|
|
|
|
|
45060
|
s/^\s+//; |
87
|
13381
|
|
|
|
|
42631
|
s/\s+$//; |
88
|
|
|
|
|
|
|
|
89
|
13381
|
100
|
|
|
|
33453
|
return ref $_[0] eq 'SCALAR' ? do { ${$_[0]} = $_; '' } : $_; |
|
13170
|
|
|
|
|
22333
|
|
|
13170
|
|
|
|
|
27858
|
|
|
13170
|
|
|
|
|
35571
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
DateTime::Format::Natural::Utils - Handy utility functions/methods |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Please see the DateTime::Format::Natural documentation. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The C<DateTime::Format::Natural::Utils> class consists of utility functions/methods. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L<DateTime::Format::Natural> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Steven Schubiger <schubiger@cpan.org> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LICENSE |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This program is free software; you may redistribute it and/or |
118
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
See L<http://dev.perl.org/licenses/> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |