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.20
[liburi-template-perl.git]
/
lib
/
URI
/
Template.pm
diff --git
a/lib/URI/Template.pm
b/lib/URI/Template.pm
index
79c944f
..
edb1ce2
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.
16
';
+our $VERSION = '0.
20
';
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 || die 'No template provided';
+ 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;
@@
-123,7
+124,7
@@
sub _tostring_query {
$join = '&' if $exp->{ op } =~ /[?&]/;
if ( ref $value eq 'ARRAY' ) {
$join = '&' if $exp->{ op } =~ /[?&]/;
if ( ref $value eq 'ARRAY' ) {
- return
unless
@$value;
+ return
if !
@$value;
if ( $var->{ explode } ) {
return join( $join,
map { $var->{ name } . '=' . _quote( $_, $safe ) } @$value );
if ( $var->{ explode } ) {
return join( $join,
map { $var->{ name } . '=' . _quote( $_, $safe ) } @$value );
@@
-134,7
+135,7
@@
sub _tostring_query {
}
}
elsif ( ref $value eq 'HASH' ) {
}
}
elsif ( ref $value eq 'HASH' ) {
- return
unless
keys %$value;
+ return
if !
keys %$value;
if ( $var->{ explode } ) {
return join(
$join,
if ( $var->{ explode } ) {
return join(
$join,
@@
-286,7
+287,18
@@
sub _compile_expansion {
}
sub template {
}
sub template {
- return $_[ 0 ]->{ template };
+ my $self = shift;
+ my $templ = shift;
+
+ # Update template
+ if ( defined $templ && $templ ne $self->{ template } ) {
+ $self->{ template } = $templ;
+ $self->{ _vars } = {};
+ $self->_study;
+ return $self;
+ }
+
+ return $self->{ template };
}
sub variables {
}
sub variables {
@@
-328,14
+340,22
@@
URI::Template - Object for handling URI templates (RFC 6570)
=head1 SYNOPSIS
use URI::Template;
=head1 SYNOPSIS
use URI::Template;
+
my $template = URI::Template->new( 'http://example.com/{x}' );
my $uri = $template->process( x => 'y' );
my $template = URI::Template->new( 'http://example.com/{x}' );
my $uri = $template->process( x => 'y' );
+
+ # or
+
+ my $template = URI::Template->new();
+ $template->template( 'http://example.com/{x}' );
+ my $uri = $template->process( x => 'y' );
+
# uri is a URI object with value 'http://example.com/y'
=head1 DESCRIPTION
This module provides a wrapper around URI templates as described in RFC 6570:
# uri is a URI object with value 'http://example.com/y'
=head1 DESCRIPTION
This module provides a wrapper around URI templates as described in RFC 6570:
-http://tools.ietf.org/html/rfc6570
+L<< http://tools.ietf.org/html/rfc6570 >>.
=head1 INSTALLATION
=head1 INSTALLATION
@@
-349,11
+369,12
@@
http://tools.ietf.org/html/rfc6570
=head2 new( $template )
Creates a new L<URI::Template> instance with the template passed in
=head2 new( $template )
Creates a new L<URI::Template> instance with the template passed in
-as the first parameter.
+as the first parameter
(optional)
.
-=head2 template
+=head2 template
( $template )
-This method returns the original template string.
+This method returns the original template string. If provided, it will also set and parse a
+new template string.
=head2 variables
=head2 variables
@@
-387,7
+408,7
@@
URI object.
=head1 COPYRIGHT AND LICENSE
=head1 COPYRIGHT AND LICENSE
-Copyright 2007-201
2
by Brian Cassidy
+Copyright 2007-201
5
by Brian Cassidy
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.