/usr/share/perl5/DateTime/Format/Natural/Helpers.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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | package DateTime::Format::Natural::Helpers;
use strict;
use warnings;
use base qw(Exporter);
use boolean qw(true false);
use constant REAL_FLAG => true;
use constant VIRT_FLAG => false;
our ($VERSION, @EXPORT_OK, %flag);
$VERSION = '0.06';
@EXPORT_OK = qw(%flag);
my @flags = (
{ weekday_name => REAL_FLAG },
{ weekday_num => REAL_FLAG },
{ month_name => REAL_FLAG },
{ month_num => REAL_FLAG },
{ time_am => REAL_FLAG },
{ time_pm => REAL_FLAG },
{ last_this_next => VIRT_FLAG },
{ yes_today_tom => VIRT_FLAG },
{ noon_midnight => VIRT_FLAG },
{ morn_aftern_even => VIRT_FLAG },
{ before_after_from => VIRT_FLAG },
);
{
my $i;
%flag = map { (keys %$_)[0] => $i++ } @flags;
}
sub _helper
{
my $self = shift;
my ($flags, $string) = @_;
foreach my $flag (@$flags) {
my $name = (keys %{$flags[$flag]})[0];
if ($flags[$flag]->{$name}) {
my $helper = "_$name";
$self->$helper(\$string);
}
else {
$string = $self->{data}->{conversion}->{$name}->{lc $string};
}
}
return $string;
}
sub _weekday_name
{
my $self = shift;
my ($arg) = @_;
my $helper = $self->{data}->{helpers};
if ($$arg =~ $helper->{suffix}) {
$$arg =~ s/$helper->{suffix}//;
}
$helper->{normalize}->($arg);
if ($helper->{abbreviated}->($arg)) {
$$arg = $self->{data}->{weekdays_abbrev}->{$$arg};
}
}
sub _weekday_num
{
my $self = shift;
my ($arg) = @_;
$$arg = $self->_Decode_Day_of_Week($$arg);
}
sub _month_name
{
my $self = shift;
my ($arg) = @_;
my $helper = $self->{data}->{helpers};
$helper->{normalize}->($arg);
if ($helper->{abbreviated}->($arg)) {
$$arg = $self->{data}->{months_abbrev}->{$$arg};
}
}
sub _month_num
{
my $self = shift;
my ($arg) = @_;
$$arg = $self->_Decode_Month($$arg);
}
sub _time_am
{
my $self = shift;
my ($arg) = @_;
$self->_time_meridiem($arg, 'am');
}
sub _time_pm
{
my $self = shift;
my ($arg) = @_;
$self->_time_meridiem($arg, 'pm');
}
sub _time_meridiem
{
my $self = shift;
my ($time, $period) = @_;
my ($hour) = split /:/, $$time;
my %hours = (
am => $hour - (($hour == 12) ? 12 : 0),
pm => $hour + (($hour == 12) ? 0 : 12),
);
$$time =~ s/^ \d+? (?:(?=\:)|$)/$hours{$period}/x;
}
1;
__END__
=head1 NAME
DateTime::Format::Natural::Helpers - Various helper methods
=head1 SYNOPSIS
Please see the DateTime::Format::Natural documentation.
=head1 DESCRIPTION
The C<DateTime::Format::Natural::Helpers> class defines helper methods.
=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
|