X-Git-Url: http://erislabs.net/gitweb/?p=liburi-template-perl.git;a=blobdiff_plain;f=lib%2FURI%2FTemplate.pm;h=79bffdf143c710c7688a504a8be6c4bc2e89ddd1;hp=a903cad5b80a56bbb2b39ff077cb86d3a2a9a963;hb=83c3737484d89a57cfd230d6a4039a269e212035;hpb=e0de6ab08282e52476e36abb99a35be9eff9ca8e diff --git a/lib/URI/Template.pm b/lib/URI/Template.pm index a903cad..79bffdf 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.08_02'; +our $VERSION = '0.10'; use URI; use URI::Escape (); @@ -32,19 +32,10 @@ as described at http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-0 =head1 INSTALLATION -To install this module via Module::Build: - - perl Build.PL - ./Build # or `perl Build` - ./Build test # or `perl Build test` - ./Build install # or `perl Build install` - -To install this module via ExtUtils::MakeMaker: - - perl Makefile.PL - make - make test - make install + perl Makefile.PL + make + make test + make install =head1 METHODS @@ -76,8 +67,8 @@ sub as_string { =head2 variables( ) -Returns an array of variable names found in the template. NB: they -are returned in random order. +Returns an array of unique variable names found in the template. +NB: they are returned in random order. =cut @@ -123,7 +114,7 @@ inflate the result to a URI object. sub process_to_string { my $self = shift; - if( ref $_[ 0 ] ) { + if ( ref $_[ 0 ] ) { return $self->_process_by_position( @_ ); } else { @@ -139,7 +130,8 @@ sub _process_by_key { # fix undef vals for my $var ( @vars ) { - $params{ $var } = defined $params{ $var } + $params{ $var } + = defined $params{ $var } ? URI::Escape::uri_escape( $params{ $var }, $unsafe ) : ''; } @@ -176,11 +168,11 @@ sub deparse { my $self = shift; my $uri = shift; - if( !$self->{ deparse_re } ) { - my $templ = $self->as_string; - $self->{ vars_list } = [ $templ =~ /{(.+?)}/g ]; - $templ =~ s/{.+?}/(.+?)/g; - $self->{ deparse_re } = qr/$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 };