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;
}