/usr/share/perl5/DateTime/Format/Natural/Compat.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 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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | package DateTime::Format::Natural::Compat;
use strict;
use warnings;
use boolean qw(true false);
use DateTime ();
our ($VERSION, $Pure);
$VERSION = '0.07';
BEGIN
{
if (eval "require Date::Calc") {
Date::Calc->import(qw(
Add_Delta_Days
Day_of_Week
Days_in_Month
Decode_Day_of_Week
Decode_Month
Nth_Weekday_of_Month_Year
check_date
check_time
));
$Pure = false;
}
else {
$Pure = true;
}
}
sub _Add_Delta_Days
{
my $self = shift;
if ($Pure) {
my ($year, $day) = @_;
my $dt = DateTime->from_day_of_year(year => $year, day_of_year => $day);
return ($dt->year, $dt->month, $dt->mday);
}
else {
my ($year, $day) = @_;
return Add_Delta_Days($year, 1, 1, $day - 1);
}
}
sub _Day_of_Week
{
my $self = shift;
if ($Pure) {
return $self->{datetime}->wday;
}
else {
return Day_of_Week(@_);
}
}
sub _Days_in_Month
{
my $self = shift;
if ($Pure) {
my ($year, $month) = @_;
my $dt = DateTime->last_day_of_month(year => $year, month => $month);
return $dt->day;
}
else {
return Days_in_Month(@_);
}
}
sub _Decode_Day_of_Week
{
my $self = shift;
if ($Pure) {
my ($day) = @_;
return $self->{data}->{weekdays}->{$day};
}
else {
return Decode_Day_of_Week(@_);
}
}
sub _Decode_Month
{
my $self = shift;
if ($Pure) {
my ($month) = @_;
return $self->{data}->{months}->{$month};
}
else {
return Decode_Month(@_);
}
}
sub _Nth_Weekday_of_Month_Year
{
my $self = shift;
if ($Pure) {
my ($year, $month, $weekday, $count) = @_;
my $dt = $self->{datetime}->clone;
$dt->set_year($year);
$dt->set_month($month);
$dt->set_day(1);
$dt->set_day($dt->day + 1)
while ($weekday ne $dt->dow);
$dt->set_day($dt->day + 7 * ($count - 1));
return ($dt->year, $dt->month, $dt->day);
}
else {
return Nth_Weekday_of_Month_Year(@_);
}
}
sub _check_date
{
my $self = shift;
if ($Pure) {
my ($year, $month, $day) = @_;
local $@;
eval {
my $dt = $self->{datetime}->clone;
$dt->set(year => $year, month => $month, day => $day);
};
return !$@;
}
else {
return check_date(@_);
}
}
sub _check_time
{
my $self = shift;
if ($Pure) {
my ($hour, $minute, $second) = @_;
local $@;
eval {
my $dt = $self->{datetime}->clone;
$dt->set(hour => $hour, minute => $minute, second => $second);
};
return !$@;
}
else {
return check_time(@_);
}
}
1;
__END__
=head1 NAME
DateTime::Format::Natural::Compat - Methods with more than one implementation
=head1 SYNOPSIS
Please see the DateTime::Format::Natural documentation.
=head1 DESCRIPTION
The C<DateTime::Format::Natural::Compat> class defines methods which must retain
more than one possible implementation due to compatibility issues on certain
platforms.
=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
|