Imported upstream version 0.06 upstream/0.06
authorIan Beckwith <ianb@erislabs.net>
Sat, 1 Mar 2008 00:29:35 +0000 (00:29 +0000)
committerIan Beckwith <ianb@erislabs.net>
Sat, 1 Mar 2008 00:29:35 +0000 (00:29 +0000)
Changes
META.yml
README
lib/URI/Template.pm
t/10-basic.t
t/20-deparse.t

diff --git a/Changes b/Changes
index 5bc9507..cb2217e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,13 @@
 Revision history for Perl extension URI::Template
 
+0.06  Mon Apr 23 2007
+    - added some caching for better deparse() performance [Paul "LeoNerd" Evans]
+
+0.05  Thu Apr 19 2007
+    - fix test for variables()
+    - added a note that the results from variables() are in
+      random order
+
 0.04  Mon Jan 22 2007
     - fix undef values when processing
 
index 512e107..ac515c7 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
 ---
 name: URI-Template
-version: 0.04
+version: 0.06
 author:
   - 'Brian Cassidy <brian.cassidy@nald.ca>'
 abstract: Object for handling URI templates
@@ -12,8 +12,8 @@ requires:
 provides:
   URI::Template:
     file: lib/URI/Template.pm
-    version: 0.04
-generated_by: Module::Build version 0.2805
+    version: 0.06
+generated_by: Module::Build version 0.2807
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.2.html
   version: 1.2
diff --git a/README b/README
index 75f354a..eb4da93 100644 (file)
--- a/README
+++ b/README
@@ -40,7 +40,8 @@ METHODS
     stringified.
 
   variables( )
-    Returns an array of variable names found in the template.
+    Returns an array of variable names found in the template. NB: they are
+    returned in random order.
 
   process( %vars )
     Given a list of key-value pairs, it will URI escape the values and
index 54ea7d2..233ce61 100644 (file)
@@ -3,7 +3,7 @@ package URI::Template;
 use strict;
 use warnings;
 
-our $VERSION = '0.04';
+our $VERSION = '0.06';
 
 use URI;
 use URI::Escape ();
@@ -74,7 +74,8 @@ sub as_string {
 
 =head2 variables( )
 
-Returns an array of variable names found in the template.
+Returns an array of variable names found in the template. NB: they
+are returned in random order.
 
 =cut
 
@@ -131,13 +132,17 @@ sub deparse {
     my $self = shift;
     my $uri  = shift;
 
-    my $templ = $self->as_string;
-    my @vars  = $templ =~ /{(.+?)}/g;
-    $templ =~ s/{.+?}/(.+?)/g;
-    my @matches = $uri =~ /$templ/;
+    if( !$self->{ deparse_re } ) {
+       my $templ = $self->as_string;
+       $self->{ vars_list } = [ $templ =~ /{(.+?)}/g ];
+       $templ =~ s/{.+?}/(.+?)/g;
+       $self->{ deparse_re } = qr/$templ/;
+    }
+
+    my @matches = $uri =~ $self->{ deparse_re };
 
     my %results;
-    @results{ @vars } = @matches;
+    @results{ @{ $self->{ vars_list } } } = @matches;
     return %results;
 }
 
index 29c19aa..162063c 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 13;
+use Test::More tests => 14;
 
 use_ok( 'URI::Template' );
 
@@ -9,7 +9,7 @@ use_ok( 'URI::Template' );
     my $text     = 'http://foo.com/{bar}/{baz}?q=%7B';
     my $template = URI::Template->new( $text );
     isa_ok( $template, 'URI::Template' );
-    is_deeply( [ $template->variables ], [ qw( bar baz ) ], 'variables()' );
+    is_deeply( [ sort $template->variables ], [ qw( bar baz ) ], 'variables()' );
     is( "$template", $text, 'as_string()' );
 
     {
@@ -40,6 +40,10 @@ use_ok( 'URI::Template' );
         my $result = $template->process( );
         is( $result, 'http://foo.com//', 'no value sent' );
     }
+    {
+        my $result = $template->process( 'y' => '1' );
+        is( $result, 'http://foo.com//', 'no valid keys used' );
+    }
 }
 
 {
index fd112e0..d6bd543 100644 (file)
@@ -23,8 +23,8 @@ use_ok( 'URI::Template' );
     my $template = URI::Template->new( 'http://ex.com/{x}' );
     isa_ok( $template, 'URI::Template' );
     my %input = ( x => 'y' );
-    my $uri      = $template->process( x => 'y' );
+    my $uri = $template->process( x => 'y' );
     is( $uri, 'http://ex.com/y' );
-    my %result   = $template->deparse( $uri );
+    my %result = $template->deparse( $uri );
     is_deeply( \%result, \%input, 'process => deparse' );
 }