/usr/share/perl5/DateTime/Format/Natural/Test.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 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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | package DateTime::Format::Natural::Test;
use strict;
use warnings;
use base qw(Exporter);
use boolean qw(true);
use File::Find;
use File::Spec::Functions qw(abs2rel);
use List::MoreUtils qw(any);
use Module::Util qw(fs_path_to_module);
use Test::More;
our ($VERSION, @EXPORT_OK, %EXPORT_TAGS, %time, $case_strings, $time_entries);
my @set;
$VERSION = '0.10';
@set = qw(%time $case_strings $time_entries _run_tests _result_string _message);
@EXPORT_OK = (qw(_find_modules _find_files), @set);
%EXPORT_TAGS = ('set' => [ @set ]);
%time = map { split /:/ }
split /\n/,
do { local $/ = '__END__';
local $_ = <DATA>;
chomp;
$_ };
$case_strings = sub { ($_[0], lc $_[0], uc $_[0]) };
$time_entries = sub
{
my ($string, $result) = @_;
my $subst = sub
{
my ($str, $res, $entries) = @_;
if ($str =~ /\{(?: |at)\}/) {
my @strings;
if ($str =~ /\{ \}/) {
foreach my $space ('', ' ') {
(my $str_new = $str) =~ s/\{ \}/$space/;
push @strings, $str_new;
}
}
if ($str =~ /\{at\}/) {
@strings = ($str) unless @strings;
my @strings_new;
foreach my $string (@strings) {
foreach my $at ('', ' at') {
(my $str_new = $string) =~ s/ \{at\}/$at/;
push @strings_new, $str_new;
}
}
@strings = @strings_new;
}
push @$entries, [ $_, $res ] foreach @strings;
}
else {
push @$entries, [ $str, $res ];
}
};
my @entries;
if ($string =~ /\{(?:min_)?sec\}/) {
my ($desc, @values);
my $sec = sprintf '%02d', int rand(60);
local $1;
if ($string =~ /\{(min_sec)\}/) {
@values = (
[ '', '00:00' ], # hour
[ ':00', '00:00' ], # minute
[ ":00:$sec", "00:$sec" ], # second
);
$desc = $1;
}
elsif ($string =~ /\{(sec)\}/) {
@values = (
[ '', '00' ], # minute
[ ":$sec", $sec ], # second
);
$desc = $1;
}
foreach my $value (@values) {
(my $str = $string) =~ s/\{$desc\}/$value->[0]/;
(my $res = $result) =~ s/\{$desc\}/$value->[1]/;
$subst->($str, $res, \@entries);
}
}
else {
$subst->($string, $result, \@entries);
}
return @entries;
};
sub _run_tests
{
my ($tests, $sets, $check) = @_;
$tests *= 3; # case tests
local $@;
if (eval "require Date::Calc") {
plan tests => $tests * 2;
foreach my $set (@$sets) {
$check->(@$set);
}
}
else {
plan tests => $tests;
}
$DateTime::Format::Natural::Compat::Pure = true;
foreach my $set (@$sets) {
$check->(@$set);
}
}
sub _result_string
{
my ($dt) = @_;
my $string = sprintf(
'%02d.%02d.%4d %02d:%02d:%02d',
map $dt->$_, qw(day month year hour min sec)
);
return $string;
}
sub _message
{
my ($msg) = @_;
my $how = $DateTime::Format::Natural::Compat::Pure
? '(using DateTime)'
: '(using Date::Calc)';
return "$msg $how";
}
sub _find_modules
{
my ($lib, $modules, $exclude) = @_;
_gather_data($lib, undef, $modules, $exclude);
}
sub _find_files
{
my ($lib, $files, $exclude) = @_;
_gather_data($lib, $files, undef, $exclude);
}
sub _gather_data
{
my ($lib, $files, $modules, $exclude) = @_;
my ($save_files, $save_modules) = map defined, ($files, $modules);
my $ext = qr/\.pm$/;
find(sub {
return unless $_ =~ $ext;
my $rel_path = abs2rel($File::Find::name, $lib);
my $module = fs_path_to_module($rel_path) or return;
return if any { $module =~ /${_}$/ } @$exclude;
if ($save_files) {
push @$files, $File::Find::name;
}
elsif ($save_modules) {
push @$modules, $module;
}
}, $lib);
}
1;
__DATA__
year:2006
month:11
day:24
hour:1
minute:13
second:8
__END__
=head1 NAME
DateTime::Format::Natural::Test - Common test routines/data
=head1 SYNOPSIS
Please see the DateTime::Format::Natural documentation.
=head1 DESCRIPTION
The C<DateTime::Format::Natural::Test> class exports common test routines.
=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
|