X-Git-Url: http://erislabs.net/gitweb/?p=liburi-template-perl.git;a=blobdiff_plain;f=lib%2FURI%2FTemplate.pm;h=b3c123180a9cafc7726d7ede2fa797cf9d93ec0e;hp=47cfb2b5b49c6833d9e11e21cf21d9fdd2b78503;hb=917525490f5d8e583f4b53dcd2d792b9e6f42c88;hpb=53a1b94e04453d9c7eea079af549f2179320b952 diff --git a/lib/URI/Template.pm b/lib/URI/Template.pm index 47cfb2b..b3c1231 100644 --- a/lib/URI/Template.pm +++ b/lib/URI/Template.pm @@ -3,12 +3,14 @@ package URI::Template; use strict; use warnings; -our $VERSION = '0.07'; +our $VERSION = '0.13'; use URI; use URI::Escape (); use overload '""' => \&as_string; +my $unsafe = q(^A-Za-z0-9\-_.~!\$\&'()*+,;=:/?\[\]#@); + =head1 NAME URI::Template - Object for handling URI templates @@ -26,23 +28,14 @@ URI::Template - Object for handling URI templates =head1 DESCRIPTION This is an initial attempt to provide a wrapper around URI templates -as described at http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-00.txt +as described at http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-01.txt =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 @@ -74,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 @@ -121,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 { @@ -137,8 +130,9 @@ sub _process_by_key { # fix undef vals for my $var ( @vars ) { - $params{ $var } = defined $params{ $var } - ? URI::Escape::uri_escape( $params{ $var } ) + $params{ $var } + = defined $params{ $var } + ? URI::Escape::uri_escape( $params{ $var }, $unsafe ) : ''; } @@ -156,7 +150,7 @@ sub _process_by_position { $uri =~ s/{(.+?)}/@params ? defined $params[ 0 ] - ? URI::Escape::uri_escape( shift @params ) + ? URI::Escape::uri_escape( shift @params, $unsafe ) : '' : ''/eg; @@ -174,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 }; @@ -190,15 +184,11 @@ sub deparse { =head1 AUTHOR -=over 4 - -=item * Brian Cassidy Ebricas@cpan.orgE - -=back +Brian Cassidy Ebricas@cpan.orgE =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Brian Cassidy +Copyright 2008 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.