Imported Upstream version 0.20 upstream/0.20
authorIan Beckwith <ianb@erislabs.net>
Sat, 28 Nov 2015 02:26:26 +0000 (02:26 +0000)
committerIan Beckwith <ianb@erislabs.net>
Sat, 28 Nov 2015 02:26:26 +0000 (02:26 +0000)
Changes
META.yml
lib/URI/Template.pm
t/10-basic.t

diff --git a/Changes b/Changes
index 3e3cf90..ec97a3e 100644 (file)
--- 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)
index 21d777f..93f22cc 100644 (file)
--- 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
index d96c895..edb1ce2 100644 (file)
@@ -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;
index 4d6f404..c7b57c3 100644 (file)
@@ -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;