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)
use strict;
use warnings;
-our $VERSION = '0.19';
+our $VERSION = '0.20';
use URI;
use URI::Escape ();
sub new {
my $class = shift;
- my $templ = shift || '';
+ my $templ = shift;
+ $templ = '' unless defined $templ;
my $self = bless { template => $templ, _vars => {} } => $class;
$self->_study;
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;
use strict;
use warnings;
-use Test::More tests => 21;
+use Test::More tests => 28;
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;