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
---
name: URI-Template
-version: 0.04
+version: 0.06
author:
- 'Brian Cassidy <brian.cassidy@nald.ca>'
abstract: Object for handling URI templates
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
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
use strict;
use warnings;
-our $VERSION = '0.04';
+our $VERSION = '0.06';
use URI;
use URI::Escape ();
=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
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;
}
use strict;
use warnings;
-use Test::More tests => 13;
+use Test::More tests => 14;
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()' );
{
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' );
+ }
}
{
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' );
}