X-Git-Url: http://erislabs.net/gitweb/?p=liburi-template-perl.git;a=blobdiff_plain;f=lib%2FURI%2FTemplate.pm;h=233ce618a42ccfdfdfe3d3f597263326e8d400bc;hp=54ea7d28f6cead4a4cb4cb0cbb4e87ef7151830b;hb=7c69490596e221b9d4be4d94de939429258ff7b3;hpb=3f3d56e5fb9a55ee113ccf2bc03f3a453f80baa0 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; }