From: Ian Beckwith Date: Mon, 23 Apr 2007 18:45:49 +0000 (+0100) Subject: upgraded to upstream 0.06 X-Git-Tag: 0.15-1~11^2~5 X-Git-Url: http://erislabs.net/gitweb/?p=liburi-template-perl.git;a=commitdiff_plain;h=c919af438f16d7b1b19ffe6c38162bb80a9ab3a7 upgraded to upstream 0.06 --- diff --git a/Changes b/Changes index 5bc9507..cb2217e 100644 --- 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 diff --git a/META.yml b/META.yml index 512e107..ac515c7 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- name: URI-Template -version: 0.04 +version: 0.06 author: - 'Brian Cassidy ' 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 --- 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 diff --git a/lib/URI/Template.pm b/lib/URI/Template.pm index 54ea7d2..233ce61 100644 --- a/lib/URI/Template.pm +++ b/lib/URI/Template.pm @@ -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; } diff --git a/t/10-basic.t b/t/10-basic.t index 29c19aa..162063c 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -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' ); + } } { diff --git a/t/20-deparse.t b/t/20-deparse.t index fd112e0..d6bd543 100644 --- a/t/20-deparse.t +++ b/t/20-deparse.t @@ -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' ); }