From 8ae3345c296c24329f5889474dd633174d57b13b Mon Sep 17 00:00:00 2001 From: Ian Beckwith Date: Sat, 28 Nov 2015 02:26:26 +0000 Subject: [PATCH] Imported Upstream version 0.20 --- Changes | 3 +++ META.yml | 2 +- lib/URI/Template.pm | 11 ++++++----- t/10-basic.t | 25 ++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Changes b/Changes index 3e3cf90..ec97a3e 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension URI::Template +0.20 2015-01-05 + - Handle "0" as a template properly (RT 101109) + 0.19 2015-01-05 - Allow empty template as per spec (RT 101109) - template() now accepts a new string as an argument (Artem Krivopolenov) diff --git a/META.yml b/META.yml index 21d777f..93f22cc 100644 --- a/META.yml +++ b/META.yml @@ -27,4 +27,4 @@ requires: resources: license: http://dev.perl.org/licenses/ repository: http://github.com/bricas/uri-template -version: 0.19 +version: 0.20 diff --git a/lib/URI/Template.pm b/lib/URI/Template.pm index d96c895..edb1ce2 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.19'; +our $VERSION = '0.20'; use URI; use URI::Escape (); @@ -24,7 +24,8 @@ my %TOSTRING = ( sub new { my $class = shift; - my $templ = shift || ''; + my $templ = shift; + $templ = '' unless defined $templ; my $self = bless { template => $templ, _vars => {} } => $class; $self->_study; @@ -287,11 +288,11 @@ sub _compile_expansion { sub template { my $self = shift; - my $new_template = shift; + my $templ = shift; # 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; diff --git a/t/10-basic.t b/t/10-basic.t index 4d6f404..c7b57c3 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 28; use_ok( 'URI::Template' ); @@ -17,6 +17,29 @@ use_ok( 'URI::Template' ); } } +# "0" as a template +{ + my $template = URI::Template->new( '0' ); + isa_ok( $template, 'URI::Template' ); + is( $template->template, '0', 'template() is "0"' ); + + { + my $result = $template->process(); + is( $result, '0', 'process() for "0" template' ); + isa_ok( $result, 'URI', 'return value from process() isa URI' ); + } + + # set template back to empty + $template->template( '' ); + is( $template->template, '', 'template() is empty' ); + + { + my $result = $template->process(); + is( $result, '', 'process() for new empty template' ); + isa_ok( $result, 'URI', 'return value from process() isa URI' ); + } +} + # Update template { my $template = URI::Template->new; -- 2.11.0