r75021 - in /branches/upstream/libdatetime-format-natural-perl/current: ./ lib/DateTime/Format/ lib/DateTime/Format/Natural/ lib/DateTime/Format/Natural/Lang/ scripts/ t/
ansgar at users.alioth.debian.org
ansgar at users.alioth.debian.org
Thu Jun 2 11:10:29 UTC 2011
Author: ansgar
Date: Thu Jun 2 11:10:22 2011
New Revision: 75021
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=75021
Log:
[svn-upgrade] new version libdatetime-format-natural-perl (0.96)
Modified:
branches/upstream/libdatetime-format-natural-perl/current/Build.PL
branches/upstream/libdatetime-format-natural-perl/current/Changes
branches/upstream/libdatetime-format-natural-perl/current/META.yml
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Wrappers.pm
branches/upstream/libdatetime-format-natural-perl/current/scripts/dateparse
branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_success.t
branches/upstream/libdatetime-format-natural-perl/current/t/10-parse_failure.t
branches/upstream/libdatetime-format-natural-perl/current/t/11-parse_assert.t
Modified: branches/upstream/libdatetime-format-natural-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/Build.PL?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/Build.PL (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/Build.PL Thu Jun 2 11:10:22 2011
@@ -31,11 +31,7 @@
'Test::MockTime' => 0,
'Test::More' => 0,
},
- recommends => {
- 'Date::Calc' => 0,
- 'Test::Pod' => '1.14',
- 'Test::Pod::Coverage' => '1.04',
- },
+ recommends => { 'Date::Calc' => 0 },
script_files => [ 'scripts/dateparse' ],
license => 'perl',
create_readme => 1,
Modified: branches/upstream/libdatetime-format-natural-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/Changes?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/Changes (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/Changes Thu Jun 2 11:10:22 2011
@@ -1,4 +1,35 @@
Revision history for Perl extension DateTime::Format::Natural.
+
+0.96 2011-06-01 <schubiger at cpan.org>
+
+ - Merged development version to stable.
+
+0.95_03 2011-05-30 <schubiger at cpan.org>
+
+ - Add the extract switch to dateparse and document it.
+
+ - Change dateparse's prefer_future option to be not negatable.
+
+0.95_02 2011-05-28 <schubiger at cpan.org>
+
+ - Reorder the nested extract loop iterating through the grammar
+ entries to process only one subentry for all matching tokens.
+
+ - Move the check for a date when extracting expressions to a method.
+
+ - Add assert tests for extract_datetime(): one for the context
+ dependant return and another for the nested extract loop fix.
+
+ - Improve code visually of the parse success and failure test files.
+
+0.95_01 2011-05-19 <schubiger at cpan.org>
+
+ - Do no longer recommend Test::Pod and Test::Pod::Coverage.
+
+ - Use quantifier which matches 1 or more times when extracting
+ subroutine or method names.
+
+ - Assign a list instead of pushing a string for time entries.
0.95 2011-05-14 <schubiger at cpan.org>
Modified: branches/upstream/libdatetime-format-natural-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/META.yml?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/META.yml (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/META.yml Thu Jun 2 11:10:22 2011
@@ -1,6 +1,6 @@
---
name: DateTime-Format-Natural
-version: 0.95
+version: 0.96
author:
- 'Steven Schubiger <schubiger at cpan.org>'
abstract: Create machine readable date/time with natural parsing logic
@@ -28,14 +28,12 @@
boolean: 0
recommends:
Date::Calc: 0
- Test::Pod: 1.14
- Test::Pod::Coverage: 1.04
configure_requires:
Module::Build: 0.340201
provides:
DateTime::Format::Natural:
file: lib/DateTime/Format/Natural.pm
- version: 0.95
+ version: 0.96
DateTime::Format::Natural::Calc:
file: lib/DateTime/Format/Natural/Calc.pm
version: 1.38
@@ -50,7 +48,7 @@
version: 0.01
DateTime::Format::Natural::Extract:
file: lib/DateTime/Format/Natural/Extract.pm
- version: 0.04
+ version: 0.05
DateTime::Format::Natural::Formatted:
file: lib/DateTime/Format/Natural/Formatted.pm
version: 0.07
@@ -59,7 +57,7 @@
version: 0.06
DateTime::Format::Natural::Lang::Base:
file: lib/DateTime/Format/Natural/Lang/Base.pm
- version: 1.07
+ version: 1.08
DateTime::Format::Natural::Lang::EN:
file: lib/DateTime/Format/Natural/Lang/EN.pm
version: 1.53
@@ -68,13 +66,13 @@
version: 0.05
DateTime::Format::Natural::Test:
file: lib/DateTime/Format/Natural/Test.pm
- version: 0.09
+ version: 0.10
DateTime::Format::Natural::Utils:
file: lib/DateTime/Format/Natural/Utils.pm
version: 0.05
DateTime::Format::Natural::Wrappers:
file: lib/DateTime/Format/Natural/Wrappers.pm
- version: 0.02
+ version: 0.03
generated_by: Module::Build version 0.340201
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm Thu Jun 2 11:10:22 2011
@@ -19,7 +19,7 @@
use Scalar::Util qw(blessed);
use Storable qw(dclone);
-our $VERSION = '0.95';
+our $VERSION = '0.96';
validation_options(
on_fail => sub
@@ -51,7 +51,7 @@
my %presets = (
lang => 'en',
format => 'd/m/y',
- prefer_future => false,
+ prefer_future => false,
time_zone => 'floating',
);
foreach my $opt (keys %presets) {
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm Thu Jun 2 11:10:22 2011
@@ -5,7 +5,7 @@
use base qw(DateTime::Format::Natural::Formatted);
use boolean qw(true false);
-our $VERSION = '0.04';
+our $VERSION = '0.05';
sub _extract_expressions
{
@@ -42,31 +42,35 @@
my $date_index;
for (my $i = 0; $i < @tokens; $i++) {
next if $skip{$i};
- my ($formatted) = $tokens[$i] =~ $self->{data}->__regexes('format');
- my %count = $self->_count_separators($formatted);
- if ($self->_check_formatted('ymd', \%count)) {
- $date_index = $i;
- $skip{$i} = true;
+ if ($self->_check_for_date($tokens[$i], $i, \$date_index)) {
last;
}
}
OUTER:
- foreach my $keyword (sort { $lengths{$b} <=> $lengths{$a} } keys %entries) {
+ foreach my $keyword (sort { $lengths{$b} <=> $lengths{$a} } grep { $lengths{$_} <= @tokens } keys %entries) {
my @grammar = @{$entries{$keyword}};
my $types = shift @grammar;
my $pos = 0;
my @indexes;
- for (my $i = 0; $i < @tokens; $i++) {
- next if $skip{$i};
- last unless defined $types->[$pos];
- foreach my $expression (@grammar) {
- my $definition = $expression->[0];
+ my $date_index;
+ foreach my $expression (@grammar) {
+ my $definition = $expression->[0];
+ my $matched = false;
+ for (my $i = 0; $i < @tokens; $i++) {
+ next if $skip{$i};
+ last unless defined $types->[$pos];
+ if ($self->_check_for_date($tokens[$i], $i, \$date_index)) {
+ next;
+ }
if ($types->[$pos] eq 'SCALAR' && defined $definition->{$pos} && $tokens[$i] =~ /^$definition->{$pos}$/i
or $types->[$pos] eq 'REGEXP' && $tokens[$i] =~ $definition->{$pos}
&& (@indexes ? ($i - $indexes[-1] == 1) : true)
) {
+ $matched = true;
push @indexes, $i;
$pos++;
+ }
+ elsif ($matched) {
last;
}
}
@@ -76,7 +80,7 @@
my $expression = join ' ', (defined $date_index ? $tokens[$date_index] : (), @tokens[@indexes]);
my $start_index = defined $date_index ? $indexes[0] - 1 : $indexes[0];
push @expressions, [ [ $start_index, $indexes[-1] ], $expression ];
- $skip{$_} = true foreach @indexes;
+ $skip{$_} = true foreach (defined $date_index ? $date_index : (), @indexes);
$seen_expression = true;
last OUTER;
}
@@ -84,6 +88,7 @@
}
if (defined $date_index && !$seen_expression) {
push @expressions, [ [ ($date_index) x 2 ], $tokens[$date_index] ];
+ $skip{$date_index} = true;
$seen_expression = true;
}
} while ($seen_expression);
@@ -126,6 +131,22 @@
return grep !$exclude->($_), @final_expressions;
}
+sub _check_for_date
+{
+ my $self = shift;
+ my ($token, $index, $date_index) = @_;
+
+ my ($formatted) = $token =~ $self->{data}->__regexes('format');
+ my %count = $self->_count_separators($formatted);
+ if ($self->_check_formatted('ymd', \%count)) {
+ $$date_index = $index;
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
1;
__END__
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm Thu Jun 2 11:10:22 2011
@@ -5,7 +5,7 @@
our ($VERSION, $AUTOLOAD);
-$VERSION = '1.07';
+$VERSION = '1.08';
sub __new
{
@@ -33,7 +33,7 @@
{
my ($self, $exp) = @_;
- my ($caller, $sub) = $AUTOLOAD =~ /^(.*)::(.*)$/;
+ my ($caller, $sub) = $AUTOLOAD =~ /^(.+)::(.+)$/;
if (substr($sub, 0, 2) eq '__') {
$sub =~ s/^__//;
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm Thu Jun 2 11:10:22 2011
@@ -14,7 +14,7 @@
our ($VERSION, @EXPORT_OK, %EXPORT_TAGS, %time, $case_strings, $time_entries);
my @set;
-$VERSION = '0.09';
+$VERSION = '0.10';
@set = qw(%time $case_strings $time_entries _run_tests _result_string _message);
@EXPORT_OK = (qw(_find_modules _find_files), @set);
@@ -45,7 +45,7 @@
}
}
if ($str =~ /\{at\}/) {
- push @strings, $str unless @strings;
+ @strings = ($str) unless @strings;
my @strings_new;
foreach my $string (@strings) {
foreach my $at ('', ' at') {
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Wrappers.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Wrappers.pm?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Wrappers.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Wrappers.pm Thu Jun 2 11:10:22 2011
@@ -3,7 +3,7 @@
use strict;
use warnings;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
sub _add
{
@@ -22,7 +22,7 @@
my $self = shift;
my ($unit, $value) = @_;
- my ($method) = (caller(1))[3] =~ /.*::(.*)$/;
+ my ($method) = (caller(1))[3] =~ /.+::(.+)$/;
$method =~ s/^_//;
$unit .= 's' unless $unit =~ /s$/;
Modified: branches/upstream/libdatetime-format-natural-perl/current/scripts/dateparse
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/scripts/dateparse?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/scripts/dateparse (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/scripts/dateparse Thu Jun 2 11:10:22 2011
@@ -11,6 +11,7 @@
use constant LANG_DEFAULT => 'en';
my %args;
+my $extract;
my $lang;
my @supported_languages = qw(en);
my $trace;
@@ -26,10 +27,11 @@
sub parse_switches
{
my %opts;
- GetOptions(\%opts, qw(f|format=s
+ GetOptions(\%opts, qw(e|extract
+ f|format=s
h|help
l|lang=s
- p|prefer_future!
+ p|prefer_future
s|supported
t|time_zone=s
T|trace
@@ -46,8 +48,9 @@
{
my $opts = shift;
- $lang = $opts->{l} || LANG_DEFAULT;
- $trace = $opts->{T} || false;
+ $extract = $opts->{e} || false;
+ $lang = $opts->{l} || LANG_DEFAULT;
+ $trace = $opts->{T} || false;
my %table = (
l => 'lang',
@@ -67,6 +70,7 @@
{
print <<USAGE;
Usage: $0 [switches]
+ -e, --extract extract expressions
-f, --format=<format> format of numeric dates
-h, --help this help screen
-l, --lang=<code> language code
@@ -119,19 +123,25 @@
next;
}
- my @dt = $parser->parse_datetime_duration(string => $input);
- my @traces = $parser->trace;
+ my @expressions = $extract ? $parser->extract_datetime($input) : ($input);
- if ($parser->success) {
- foreach my $dt (@dt) {
- printf("%02d.%02d.%4d %02d:%02d:%02d\n", map $dt->$_, qw(day month year hour min sec));
- if ($trace && @traces) {
- print shift @traces, "\n";
+ warn "no parsable expressions extracted\n" unless @expressions;
+
+ foreach my $expression (@expressions) {
+ my @dt = $parser->parse_datetime_duration(string => $expression);
+ my @traces = $parser->trace;
+
+ if ($parser->success) {
+ foreach my $dt (@dt) {
+ printf("%02d.%02d.%4d %02d:%02d:%02d\n", map $dt->$_, qw(day month year hour min sec));
+ if ($trace && @traces) {
+ print shift @traces, "\n";
+ }
}
}
- }
- else {
- warn $parser->error, "\n";
+ else {
+ warn $parser->error, "\n";
+ }
}
}
}
@@ -143,6 +153,7 @@
=head1 SYNOPSIS
Usage: dateparse [switches]
+ -e, --extract extract expressions
-f, --format=<format> format of numeric dates
-h, --help this help screen
-l, --lang=<code> language code
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_success.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_success.t?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_success.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_success.t Thu Jun 2 11:10:22 2011
@@ -39,14 +39,19 @@
'saturday 3 months ago at 5',
);
-foreach my $list (\@ordinal_number, \@durations, \@filtered, \@formatted, \@rewrite) {
+foreach my $list (\@ordinal_number,
+ \@durations,
+ \@filtered,
+ \@formatted,
+ \@rewrite)
+{
check($list);
}
sub check
{
- my $aref = shift;
- foreach my $string (@$aref) {
+ my $list = shift;
+ foreach my $string (@$list) {
check_success($string);
}
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/10-parse_failure.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/10-parse_failure.t?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/10-parse_failure.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/10-parse_failure.t Thu Jun 2 11:10:22 2011
@@ -358,16 +358,19 @@
'22rd may 2011 9:35pm',
]);
-check(\@with_suffix);
-check(\@without_suffix);
-check(\@meridiem_exceeds);
-check(\@meridiem_zero);
-check(\@ordinal_number);
+foreach my $list (\@with_suffix,
+ \@without_suffix,
+ \@meridiem_exceeds,
+ \@meridiem_zero,
+ \@ordinal_number)
+{
+ check($list);
+}
sub check
{
- my $aref = shift;
- my ($error, $checks) = @$aref;
+ my $list = shift;
+ my ($error, $checks) = @$list;
foreach my $string (@$checks) {
check_fail($error, $string);
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/11-parse_assert.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/11-parse_assert.t?rev=75021&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/11-parse_assert.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/11-parse_assert.t Thu Jun 2 11:10:22 2011
@@ -5,7 +5,7 @@
use boolean qw(true false);
use DateTime::Format::Natural;
-use Test::More tests => 6;
+use Test::More tests => 9;
{
# Assert for prefixed dates that an extracted unit which is
@@ -54,3 +54,22 @@
$parser->parse_datetime('2011-j6n-04');
ok(!$parser->success && !$warnings, 'formatted date with non-letter in month name');
}
+
+{
+ # Assert that extract_datetime() returns expressions depending on context.
+ my $parser = DateTime::Format::Natural->new;
+ my $string = 'monday until friday';
+ my $expression = $parser->extract_datetime($string);
+ is($expression, 'monday', 'extract_datetime scalar');
+ my @expressions = $parser->extract_datetime($string);
+ is_deeply(\@expressions, [qw(monday friday)], 'extract_datetime list');
+}
+
+{
+ # Assert that extract_datetime() looping through a grammar entry does not
+ # match in more than one subentry for all tokens (previously broken for
+ # this input string with the weekday_time grammar entry, at least).
+ my $parser = DateTime::Format::Natural->new;
+ my @expressions = $parser->extract_datetime('8am 4pm');
+ is_deeply(\@expressions, [qw(8am 4pm)], 'extract with single grammar subentry');
+}
More information about the Pkg-perl-cvs-commits
mailing list