/usr/share/perl5/DateTime/Format/Natural/Duration.pm is in libdatetime-format-natural-perl 1.04-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | package DateTime::Format::Natural::Duration;
use strict;
use warnings;
use DateTime::Format::Natural::Duration::Checks;
use List::MoreUtils qw(all);
our $VERSION = '0.06';
sub _pre_duration
{
my $self = shift;
my ($date_strings) = @_;
my $check_if = sub
{
my $sub = shift;
my $class = join '::', (__PACKAGE__, 'Checks');
my $check = $class->can($sub) or die "$sub() not found in $class";
return $check->($self->{data}->{duration}, $date_strings, @_);
};
my ($present, $extract, $adjust, @indexes);
if ($check_if->('for', \$present)) {
@{$self->{insert}}{qw(datetime trace)} = do {
my $dt = $self->parse_datetime($present);
($dt, $self->{traces}[0]);
};
}
elsif ($check_if->('first_to_last', \$extract)) {
if (my ($complete) = $date_strings->[1] =~ $extract) {
$date_strings->[0] .= " $complete";
}
}
elsif ($check_if->('from_count_to_count', \$extract, \$adjust, \@indexes)) {
if (my ($complete) = $date_strings->[$indexes[0]] =~ $extract) {
$adjust->($date_strings, $indexes[1], $complete);
}
}
}
sub _post_duration
{
my $self = shift;
my ($queue, $traces) = @_;
my %assign = (
datetime => $queue,
trace => $traces,
);
if (all { exists $self->{insert}{$_} } keys %assign) {
unshift @{$assign{$_}}, $self->{insert}{$_} foreach keys %assign;
}
}
sub _save_state
{
my $self = shift;
my %args = @_;
return if %{$self->{state}};
unless ($args{valid_expression}) {
%{$self->{state}} = %args;
}
}
sub _restore_state
{
my $self = shift;
my %state = %{$self->{state}};
if (%state) {
$state{valid_expression}
? $self->_set_valid_exp
: $self->_unset_valid_exp;
$state{failure}
? $self->_set_failure
: $self->_unset_failure;
defined $state{error}
? $self->_set_error($state{error})
: $self->_unset_error;
}
}
1;
__END__
=head1 NAME
DateTime::Format::Natural::Duration - Duration hooks and state handling
=head1 SYNOPSIS
Please see the DateTime::Format::Natural documentation.
=head1 DESCRIPTION
The C<DateTime::Format::Natural::Duration> class contains code to alter
tokens before parsing and to insert DateTime objects in the resulting
queue. Furthermore, there's code to save the state of the first failing
parse and restore it after the duration has been processed.
=head1 SEE ALSO
L<DateTime::Format::Natural>
=head1 AUTHOR
Steven Schubiger <schubiger@cpan.org>
=head1 LICENSE
This program is free software; you may redistribute it and/or
modify it under the same terms as Perl itself.
See L<http://dev.perl.org/licenses/>
=cut
|