r39912 - in /branches/upstream/libdatetime-format-strptime-perl/current: Changes MANIFEST META.yml Makefile.PL lib/DateTime/Format/Strptime.pm t/004_locale_defaults.t t/009_regexp.t

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Tue Jul 14 22:24:29 UTC 2009


Author: gregoa
Date: Tue Jul 14 22:24:24 2009
New Revision: 39912

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=39912
Log:
[svn-upgrade] Integrating new upstream version, libdatetime-format-strptime-perl (1.1000)

Added:
    branches/upstream/libdatetime-format-strptime-perl/current/t/009_regexp.t
Modified:
    branches/upstream/libdatetime-format-strptime-perl/current/Changes
    branches/upstream/libdatetime-format-strptime-perl/current/MANIFEST
    branches/upstream/libdatetime-format-strptime-perl/current/META.yml
    branches/upstream/libdatetime-format-strptime-perl/current/Makefile.PL
    branches/upstream/libdatetime-format-strptime-perl/current/lib/DateTime/Format/Strptime.pm
    branches/upstream/libdatetime-format-strptime-perl/current/t/004_locale_defaults.t

Modified: branches/upstream/libdatetime-format-strptime-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-strptime-perl/current/Changes?rev=39912&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-strptime-perl/current/Changes (original)
+++ branches/upstream/libdatetime-format-strptime-perl/current/Changes Tue Jul 14 22:24:24 2009
@@ -219,3 +219,9 @@
 	- Makefile.PL changes for Windows users as per issue #16
 
 1.0901 2009-05-16 -- Official release of above
+
+1.1000 2009-07-13 -- Regex Pattern
+	- If the pattern you pass in is a regular expression, that will be honored.
+	- Changed the locale tests to use require the latest version of Locale until the target stops moving.
+	
+		

Modified: branches/upstream/libdatetime-format-strptime-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-strptime-perl/current/MANIFEST?rev=39912&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-strptime-perl/current/MANIFEST (original)
+++ branches/upstream/libdatetime-format-strptime-perl/current/MANIFEST Tue Jul 14 22:24:24 2009
@@ -13,4 +13,5 @@
 t/006_locales.t
 t/007_edge.t
 t/008_epoch.t
+t/009_regexp.t
 t/more/001_all_locales.t

Modified: branches/upstream/libdatetime-format-strptime-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-strptime-perl/current/META.yml?rev=39912&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-strptime-perl/current/META.yml (original)
+++ branches/upstream/libdatetime-format-strptime-perl/current/META.yml Tue Jul 14 22:24:24 2009
@@ -3,7 +3,7 @@
         version: 1.3
         url: http://module-build.sourceforge.net/META-spec-v1.3.html
 name:           DateTime-Format-Strptime
-version:        1.0901
+version:        1.1000
 abstract:       Parse and format strp and strf time patterns
 author:
         - Rick Measham <rickm at cpan.org>
@@ -12,7 +12,7 @@
 requires:
         Params::Validate:              0.64
         DateTime:                      0.4304
-        DateTime::Locale:              0.41
+        DateTime::Locale:              0.43
         DateTime::TimeZone:            0.79
 resources:
         licence:        http://dev.perl.org/licenses/

Modified: branches/upstream/libdatetime-format-strptime-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-strptime-perl/current/Makefile.PL?rev=39912&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-strptime-perl/current/Makefile.PL (original)
+++ branches/upstream/libdatetime-format-strptime-perl/current/Makefile.PL Tue Jul 14 22:24:24 2009
@@ -28,7 +28,7 @@
     ABSTRACT     => 'Parse and format strp and strf time patterns',
     PREREQ_PM    => {
        'DateTime'           => '0.4304',
-       'DateTime::Locale'   => '0.41',
+       'DateTime::Locale'   => '0.43',
        'DateTime::TimeZone' => '0.79',
        'Params::Validate'   => '0.64',
     },
@@ -38,7 +38,7 @@
 return $^O eq 'MSWin32'?
 <<'MAKE_FRAG'
 test_more :: pure_all
-set PERL_DL_NON_LAZY=1 & $(FULLPERLRUN) "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" t/more/*.t
+	set PERL_DL_NON_LAZY=1 & $(FULLPERLRUN) "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" t/more/*.t
 MAKE_FRAG
 :
 <<'MAKE_FRAG';

Modified: branches/upstream/libdatetime-format-strptime-perl/current/lib/DateTime/Format/Strptime.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-strptime-perl/current/lib/DateTime/Format/Strptime.pm?rev=39912&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-strptime-perl/current/lib/DateTime/Format/Strptime.pm (original)
+++ branches/upstream/libdatetime-format-strptime-perl/current/lib/DateTime/Format/Strptime.pm Tue Jul 14 22:24:24 2009
@@ -5,14 +5,14 @@
 use DateTime;
 use DateTime::Locale;
 use DateTime::TimeZone;
-use Params::Validate qw( validate SCALAR BOOLEAN OBJECT CODEREF );
+use Params::Validate qw( validate SCALAR SCALARREF BOOLEAN OBJECT CODEREF );
 use Carp;
 
 use Exporter;
 use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %ZONEMAP %FORMATS $CROAK $errmsg);
 
 @ISA = 'Exporter';
-$VERSION = '1.0901';
+$VERSION = '1.1000';
 @EXPORT_OK = qw( &strftime &strptime );
 @EXPORT = ();
 
@@ -124,7 +124,7 @@
 
 sub new {
     my $class = shift;
-	my %args = validate( @_, {	pattern		=> { type => SCALAR },
+	my %args = validate( @_, {	pattern		=> { type => SCALAR | SCALARREF },
 								time_zone	=> { type => SCALAR | OBJECT, optional => 1 },
                                 locale      => { type => SCALAR | OBJECT, default => 'English' },
 								on_error	=> { type => SCALAR | CODEREF, default => 'undef' },
@@ -598,6 +598,9 @@
 sub _build_parser {
 	my $self = shift;
 	my $regex = my $field_list = shift;
+	if( ref $regex eq 'Regexp' ){
+		$field_list =~ s/^\(\?-xism:(.+)\)$/$1/;
+	}
 	my @fields = $field_list =~ m/(%\{\w+\}|%\d*.)/g;
 	$field_list = join('', at fields);
 
@@ -630,17 +633,17 @@
 
 	$regex =~ s/%x/$self->{_locale}->default_date_format/eg;
 	$field_list =~ s/%x/$default_date_format/eg;
-	# %x id the locale's default date format.
+	# %x is the locale's default date format.
 
 	$regex =~ s/%X/$self->{_locale}->default_time_format/eg;
 	$field_list =~ s/%X/$default_time_format/eg;
-	# %x id the locale's default time format.
-
-	# I'm absolutely certain there's a better way to do this:
-	#$regex=~s|([\/\.\-])|\\$1|g;
-	$regex = quotemeta( $regex );
-	$regex =~ s/(?<!\\)\\%/%/g;
-	$regex =~ s/%\\\{([^\}]+)\\\}/%{$1}/g;
+	# %x is the locale's default time format.
+
+	if( ref $regex ne 'Regexp' ){
+		$regex = quotemeta( $regex );
+		$regex =~ s/(?<!\\)\\%/%/g;
+		$regex =~ s/%\\\{([^\}]+)\\\}/%{$1}/g;
+	}
 
 	$regex =~ s/%T/%H:%M:%S/g;
 	$field_list =~ s/%T/%H%M%S/g;

Modified: branches/upstream/libdatetime-format-strptime-perl/current/t/004_locale_defaults.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-strptime-perl/current/t/004_locale_defaults.t?rev=39912&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-strptime-perl/current/t/004_locale_defaults.t (original)
+++ branches/upstream/libdatetime-format-strptime-perl/current/t/004_locale_defaults.t Tue Jul 14 22:24:24 2009
@@ -20,18 +20,18 @@
 	['en_AU',	'%X',	'12:34:56 PM'],
 	['en_AU',	'%c',	'31/12/1998 12:34:56 PM'],
 	# US English
-	['en_US',	'%x',	'Dec 31, 1998'],
+	['en_US',	'%x',	'Dec 31, 98'],
 	['en_US',	'%X',	'12:34:56 PM'],
-	['en_US',	'%c',	'Dec 31, 1998 12:34:56 PM'],
+	['en_US',	'%c',	'Dec 31, 98 12:34:56 PM'],
 	# UK English
-	['en_GB',	'%x',	'31 Dec 1998'],
+	['en_GB',	'%x',	'31 Dec 98'],
 	['en_GB',	'%X',	'12:34:56 PM'],
-	['en_GB',	'%c',	'31 Dec 1998 12:34:56'],
+	['en_GB',	'%c',	'31 Dec 98 12:34:56'],
 	# French
 #);my @tests = (
-	['fr',	'%x',	'31 déc 1998'],
+	['fr',	'%x',	'31 déc 98'],
 	['fr',	'%X',	'12:34:56'],
-	['fr',	'%c',	'31 déc 1998 12:34:56'],
+	['fr',	'%c',	'31 déc 98 12:34:56'],
 );
 
 foreach (@tests) {

Added: branches/upstream/libdatetime-format-strptime-perl/current/t/009_regexp.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-strptime-perl/current/t/009_regexp.t?rev=39912&op=file
==============================================================================
--- branches/upstream/libdatetime-format-strptime-perl/current/t/009_regexp.t (added)
+++ branches/upstream/libdatetime-format-strptime-perl/current/t/009_regexp.t Tue Jul 14 22:24:24 2009
@@ -1,0 +1,63 @@
+#!perl -w
+
+# t/009_regexp.t - Patterns as regular expressions
+
+use Test::More tests => 21;
+use DateTime;
+use DateTime::Format::Strptime;
+
+
+test(
+	pattern => qr/%Y-%m-%d/,
+	input   => '2009-07-13',
+	output  => { year => 2009, month => 7, day => 13 }
+);
+
+test(
+	pattern => qr/%Y-%m-%d Static Text/,
+	input   => '2009-07-13 Static Text',
+	output  => { year => 2009, month => 7, day => 13 }
+);
+
+test(
+	pattern => qr/%Y-%m-%d \w+\s\w+/,
+	input   => '2009-07-13 Static Text',
+	output  => { year => 2009, month => 7, day => 13 }
+);
+
+test(
+	pattern => qr/^%Y-%m-%d \w+\s\w+$/,
+	input   => '2009-07-13 Static Text',
+	output  => { year => 2009, month => 7, day => 13 }
+);
+
+
+eval { 
+	my $strptime = DateTime::Format::Strptime->new(
+		pattern => qr/^%Y-%m-%d \s+$/,
+		on_error => 'croak',
+	);
+	my $parsed = $strptime->parse_datetime('2009-07-13 Static Text');
+};
+is(substr($@,0,42), "Your datetime does not match your pattern.", "The strp pattern is OK, but the regex doesn't match the input.");
+
+
+sub test {
+	my %arg = @_;
+
+	my $strptime = DateTime::Format::Strptime->new(
+		pattern   => $arg{pattern}   || '%F %T',
+		locale    => $arg{locale}    || 'en',
+		time_zone => $arg{time_zone} || 'UTC',
+		diagnostic=> $arg{diagnostic}|| 0,
+		on_error  => $arg{on_error}  || 'undef',
+	);
+	isa_ok($strptime, 'DateTime::Format::Strptime');
+
+	my $parsed = $strptime->parse_datetime($arg{input});
+	isa_ok($parsed, 'DateTime');
+
+	foreach my $k ( keys %{ $arg{output} } ){
+		is( $parsed->$k, $arg{output}{$k} );
+	}
+}




More information about the Pkg-perl-cvs-commits mailing list