Revision history for Perl extension URI::Template
+0.10 Wed Jan 16 2007
+ - fix test suite for JSON 2.x
+
0.09 Tue Aug 28 2007
- minor doc update
Makefile.PL
MANIFEST This list of files
META.yml
-README
t/01-use.t
t/10-basic.t
t/11-ordered.t
---
abstract: Object for handling URI templates
-author: Brian Cassidy <bricas@cpan.org>
+author:
+ - Brian Cassidy <bricas@cpan.org>
+build_requires:
+ Test::More: 0
distribution_type: module
-generated_by: Module::Install version 0.67
+generated_by: Module::Install version 0.68
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.3.html
- inc
- t
requires:
- Test::More: 0
URI: 0
-version: 0.09
+version: 0.10
-use inc::Module::Install 0.65;
+use inc::Module::Install 0.68;
name 'URI-Template';
all_from 'lib/URI/Template.pm';
requires 'URI';
-requires 'Test::More';
+
+test_requires 'Test::More';
auto_install;
WriteAll;
+++ /dev/null
-NAME
- URI::Template - Object for handling URI templates
-
-SYNOPSIS
- use URI::Template;
- my $template = URI::Template->new( 'http://example.com/{x}' );
- my $uri = $template->process( x => 'y' );
- # uri is a URI object with value 'http://example.com/y'
-
- my %result = $template->deparse( $uri );
- # %result is ( x => 'y' )
-
-DESCRIPTION
- This is an initial attempt to provide a wrapper around URI templates as
- described at
- http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-01.txt
-
-INSTALLATION
- perl Makefile.PL
- make
- make test
- make install
-
-METHODS
- new( $template )
- Creates a new URI::Template instance with the template passed in as the
- first parameter.
-
- as_string( )
- Returns the original template string. Also used when the object is
- stringified.
-
- variables( )
- Returns an array of unique variable names found in the template. NB:
- they are returned in random order.
-
- all_variables( )
- Returns an array of variable names found as they appear in template --
- in order, duplicates included.
-
- process( %vars|\@values )
- Given a list of key-value pairs or an array ref of values (for
- positional substitution), it will URI escape the values and substitute
- them in to the template. Returns a URI object.
-
- process_to_string( %vars|\@values )
- Processes input like the "process" method, but doesn't inflate the
- result to a URI object.
-
- deparse( $uri )
- Does some rudimentary deparsing of a uri based on the current template.
- Returns a hash with the extracted values.
-
-AUTHOR
- Brian Cassidy <bricas@cpan.org>
-
-COPYRIGHT AND LICENSE
- Copyright 2007 by Brian Cassidy
-
- This library is free software; you can redistribute it and/or modify it
- under the same terms as Perl itself.
-
# This is not enforced yet, but will be some time in the next few
# releases once we can make sure it won't clash with custom
# Module::Install extensions.
- $VERSION = '0.67';
+ $VERSION = '0.68';
}
# Whether or not inc::Module::Install is actually loaded, the
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
#line 1
package Module::Install::Base;
-$VERSION = '0.67';
+$VERSION = '0.68';
# Suspend handler for "redefined" warnings
BEGIN {
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use strict;
use warnings;
-our $VERSION = '0.09';
+our $VERSION = '0.10';
use URI;
use URI::Escape ();
sub process_to_string {
my $self = shift;
- if( ref $_[ 0 ] ) {
+ if ( ref $_[ 0 ] ) {
return $self->_process_by_position( @_ );
}
else {
# fix undef vals
for my $var ( @vars ) {
- $params{ $var } = defined $params{ $var }
+ $params{ $var }
+ = defined $params{ $var }
? URI::Escape::uri_escape( $params{ $var }, $unsafe )
: '';
}
my $self = shift;
my $uri = shift;
- if( !$self->{ deparse_re } ) {
- my $templ = $self->as_string;
- $self->{ vars_list } = [ $templ =~ /{(.+?)}/g ];
- $templ =~ s/{.+?}/(.+?)/g;
- $self->{ deparse_re } = qr/$templ/;
+ if ( !$self->{ deparse_re } ) {
+ my $templ = $self->as_string;
+ $self->{ vars_list } = [ $templ =~ /{(.+?)}/g ];
+ $templ =~ s/{.+?}/(.+?)/g;
+ $self->{ deparse_re } = qr/$templ/;
}
my @matches = $uri =~ $self->{ deparse_re };
# fatal - no template provided
{
- eval { URI::Template->new; };
- ok( $@ );
+ eval { URI::Template->new; };
+ ok( $@ );
}
{
my $text = 'http://foo.com/{bar}/{baz}?q=%7B';
my $template = URI::Template->new( $text );
isa_ok( $template, 'URI::Template' );
- is_deeply( [ sort $template->variables ], [ qw( bar baz ) ], 'variables()' );
+ is_deeply(
+ [ sort $template->variables ],
+ [ qw( bar baz ) ],
+ 'variables()'
+ );
is( "$template", $text, 'as_string()' );
{
is( $result, 'http://foo.com/%7Bx%7D/', 'values are uri escaped' );
}
{
- my $result = $template->process( );
+ my $result = $template->process();
is( $result, 'http://foo.com//', 'no value sent' );
}
{
my $text = 'http://foo.com/{arg2}/{arg1}';
my $template = URI::Template->new( $text );
isa_ok( $template, 'URI::Template' );
- is_deeply( [ $template->all_variables ], [ qw( arg2 arg1 ) ], 'all_variables()' );
+ is_deeply(
+ [ $template->all_variables ],
+ [ qw( arg2 arg1 ) ],
+ 'all_variables()'
+ );
{
my $result = $template->process( [ qw( x y ) ] );
# test with no values
{
- my $result = $template->process_to_string( [ ] );
+ my $result = $template->process_to_string( [] );
is( $result, 'http://foo.com//', 'process w/ no values' );
}
}
for my $file ( @files ) {
open( my $json, $file );
- my $suite = JSON::jsonToObj( do { local $/; <$json> } );
+ my $data = do { local $/; <$json> };
close( $json );
+ eval { JSON->VERSION( 2 ) };
+ my $suite = $@ ? JSON::jsonToObj( $data ) : JSON::from_json( $data );
my %variables = %{ $suite->{ variables } };
my $count = 0;
for my $test ( @{ $suite->{ tests } } ) {
my $template = URI::Template->new( $test->{ template } );
- my $result = $template->process( %variables );
+ my $result = $template->process( %variables );
$count++;
is( $result, $test->{ expected }, "${file}#${count}" );
}
}
-
use_ok( 'URI::Template' );
{
- my $template = URI::Template->new( 'http://{domain}.com/{dir}/{file}.html' );
+ my $template
+ = URI::Template->new( 'http://{domain}.com/{dir}/{file}.html' );
isa_ok( $template, 'URI::Template' );
my %result = $template->deparse( 'http://example.com/test/1.html' );
- is_deeply( \%result, { domain => 'example', dir => 'test', file => '1' }, 'deparse()' );
+ is_deeply( \%result, { domain => 'example', dir => 'test', file => '1' },
+ 'deparse()' );
}
{
my $template = URI::Template->new( 'http://test.com/{x}/{y}/{x}/{y}' );
isa_ok( $template, 'URI::Template' );
my %result = $template->deparse( 'http://test.com/1/2/1/2' );
- is_deeply( \%result, { x => 1, y => 2 }, 'deparse() with multiple values' );
+ is_deeply(
+ \%result,
+ { x => 1, y => 2 },
+ 'deparse() with multiple values'
+ );
}
{
eval "use Test::Pod 1.14";
plan skip_all => 'Test::Pod 1.14 required' if $@;
-plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{ TEST_POD };
all_pod_files_ok();
eval "use Test::Pod::Coverage 1.04";
plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
-plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{ TEST_POD };
all_pod_coverage_ok();