/usr/share/perl5/DateTime/Format/Natural/Rewrite.pm is in libdatetime-format-natural-perl 1.02-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 | package DateTime::Format::Natural::Rewrite;
use strict;
use warnings;
our $VERSION = '0.06';
sub _rewrite
{
my $self = shift;
my ($date_string) = @_;
$self->_rewrite_regular($date_string);
$self->_rewrite_aliases($date_string);
$self->_rewrite_conditional($date_string);
}
sub _rewrite_regular
{
my $self = shift;
my ($date_string) = @_;
$$date_string =~ tr/,//d;
$$date_string =~ s/\s+?(am|pm)\b/$1/gi;
}
sub _rewrite_conditional
{
my $self = shift;
my ($date_string) = @_;
my $rewrite = $self->{data}->{rewrite};
REWRITE: {
if ($$date_string =~ /$rewrite->{at}{match}/g) {
my $last_token = $1;
my @regexes = (
(map $self->{data}->__RE($_), qw(time time_am time_pm)),
$rewrite->{at}{daytime},
);
foreach my $regex (@regexes) {
if ($last_token =~ $regex) {
$$date_string =~ s/\G/:00/ if $last_token =~ /^\d{1,2}$/;
$$date_string =~ s/$rewrite->{at}{subst}//;
redo REWRITE;
}
}
}
}
}
sub _rewrite_aliases
{
my $self = shift;
my ($date_string) = @_;
my $aliases = $self->{data}->{aliases};
if ($$date_string =~ /\s+/) {
foreach my $type (qw(words tokens)) {
foreach my $alias (keys %{$aliases->{$type}}) {
if ($alias =~ /^\w+$/) {
$$date_string =~ s/\b $alias \b/$aliases->{$type}{$alias}/gix;
}
else {
$$date_string =~ s/(?:^|(?<=\s)) $alias (?:(?=\s)|$)/$aliases->{$type}{$alias}/gix;
}
}
}
}
else {
foreach my $alias (keys %{$aliases->{words}}) {
$$date_string =~ s/^ $alias $/$aliases->{words}{$alias}/ix;
}
foreach my $alias (keys %{$aliases->{short}}) {
$$date_string =~ s/(?<=\d) $alias $/$aliases->{short}{$alias}/ix;
}
}
}
1;
__END__
=head1 NAME
DateTime::Format::Natural::Rewrite - Aliasing and rewriting of date strings
=head1 SYNOPSIS
Please see the DateTime::Format::Natural documentation.
=head1 DESCRIPTION
The C<DateTime::Format::Natural::Rewrite> class handles aliases and regular
rewrites of date strings.
=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
|