Imported upstream version 0.06
[liburi-template-perl.git] / lib / URI / Template.pm
index 54ea7d2..233ce61 100644 (file)
@@ -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;
 }