projects
/
liburi-template-perl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Imported Upstream version 0.21
[liburi-template-perl.git]
/
lib
/
URI
/
Template.pm
diff --git
a/lib/URI/Template.pm
b/lib/URI/Template.pm
index
d96c895
..
0069457
100644
(file)
--- a/
lib/URI/Template.pm
+++ b/
lib/URI/Template.pm
@@
-3,7
+3,7
@@
package URI::Template;
use strict;
use warnings;
use strict;
use warnings;
-our $VERSION = '0.
19
';
+our $VERSION = '0.
21
';
use URI;
use URI::Escape ();
use URI;
use URI::Escape ();
@@
-24,7
+24,8
@@
my %TOSTRING = (
sub new {
my $class = shift;
sub new {
my $class = shift;
- my $templ = shift || '';
+ my $templ = shift;
+ $templ = '' unless defined $templ;
my $self = bless { template => $templ, _vars => {} } => $class;
$self->_study;
my $self = bless { template => $templ, _vars => {} } => $class;
$self->_study;
@@
-198,15
+199,16
@@
sub _tostring_path {
sub _study {
my ( $self ) = @_;
my @hunks = grep { defined && length } split /(\{.+?\})/, $self->template;
sub _study {
my ( $self ) = @_;
my @hunks = grep { defined && length } split /(\{.+?\})/, $self->template;
+ my $pos = 1;
for ( @hunks ) {
next unless /^\{(.+?)\}$/;
for ( @hunks ) {
next unless /^\{(.+?)\}$/;
- $_ = $self->_compile_expansion( $1 );
+ $_ = $self->_compile_expansion( $1
, $pos++
);
}
$self->{ studied } = \@hunks;
}
sub _compile_expansion {
}
$self->{ studied } = \@hunks;
}
sub _compile_expansion {
- my ( $self, $str ) = @_;
+ my ( $self, $str
, $pos
) = @_;
my %exp = ( op => '', vars => [], str => $str );
if ( $str =~ /^([+#.\/;?&|!\@])(.+)/ ) {
my %exp = ( op => '', vars => [], str => $str );
if ( $str =~ /^([+#.\/;?&|!\@])(.+)/ ) {
@@
-233,7
+235,7
@@
sub _compile_expansion {
# remove "optional" flag (for opensearch compatibility)
$var{ name } =~ s{\?$}{};
# remove "optional" flag (for opensearch compatibility)
$var{ name } =~ s{\?$}{};
- $self->{ _vars }->{ $var{ name } }
++
;
+ $self->{ _vars }->{ $var{ name } }
= $pos
;
push @{ $exp{ vars } }, \%var;
}
push @{ $exp{ vars } }, \%var;
}
@@
-287,11
+289,11
@@
sub _compile_expansion {
sub template {
my $self = shift;
sub template {
my $self = shift;
- my $
new_template
= shift;
+ my $
templ
= shift;
# Update template
# Update template
- if (
$new_template && $new_template
ne $self->{ template } ) {
- $self->{ template } = $
new_template
;
+ if (
defined $templ && $templ
ne $self->{ template } ) {
+ $self->{ template } = $
templ
;
$self->{ _vars } = {};
$self->_study;
return $self;
$self->{ _vars } = {};
$self->_study;
return $self;
@@
-301,7
+303,7
@@
sub template {
}
sub variables {
}
sub variables {
- return keys %{ $_[ 0 ]->{ _vars } };
+ return
sort {$_[ 0 ]->{ _vars }->{ $a } <=> $_[ 0 ]->{ _vars }->{ $b } }
keys %{ $_[ 0 ]->{ _vars } };
}
sub expansions {
}
sub expansions {
@@
-377,7
+379,7
@@
new template string.
=head2 variables
=head2 variables
-Returns an array of unique variable names found in the template
. NB: they are returned in random order
.
+Returns an array of unique variable names found in the template
(in the order of appearance)
.
=head2 expansions
=head2 expansions