Igor Zinovyev > Eve > Eve::Uri

Download:
Eve-0.06.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Eve::Uri - a URI automation class.

SYNOPSIS ^

    use Eve::Uri;

    my $uri  = Eve::Uri->new(
        string => 'http://domain.com/path/script?foo=bar&baz=1&baz=2');

    my $string = $uri->string;
    my $host = $uri->host;
    my $fragment = $uri->fragment;
    my $query_string = $uri->query;

    my $query_parameter = $uri->get_query_parameter(name => 'foo');
    my @query_parameter_list = $uri->get_query_parameter(name => 'baz');

    $uri->set_query_parameter(name => 'foo', value => 'some');
    $uri->set_query_parameter(name => 'baz', value => [3, 4]);

    $uri->set_query_hash(hash => {'name' => 'foo', 'value' => 'some'});
    $uri->set_query_hash(
        hash => {'name' => 'foo', 'value' => 'some'}, delimiter => '&');
    my $query_hash = $uri->get_query_hash();

    my $another_uri = $uri->clone();

    my $matches_hash = $uri->match($another_uri) # empty hash - no placeholders

    $another_uri->query = 'another=query';
    $matches_hash = $uri->match($another_uri); # undef

    $another_uri->path_concat('/some/deeper/path');

    my $placeholder_uri = Eve::Uri->new(
        string => 'http://domain.com/:placeholder/:another');

    my $substituted_uri = $placeholder_uri->substitute(
        hash => {
            'placeholder' => 'first_value',
            'another' => 'another_value'});

    print $substituted_uri->string;
    # http://domain.com/first_value/another_value

    my $uri_is_relative = $uri->is_relative();

DESCRIPTION ^

The class provides automation for different common operations with URIs. A URI is automaticaly brought to the canonical form after creation or after using any setter method.

Attributes

fragment

a fragment part of the URI.

query

a query string part of the URI

string

an URI as a string

Constructor arguments

string

a string that can contain placeholders that are preceded with a semicolon character (':').

METHODS ^

init()

clone()

Clones and returns the object.

Returns

The object identical to self.

match()

Matches self against other URI.

Arguments

uri

a URI instance to match with.

Returns

If it matches then a substitutions hash is returned, otherwise - undef. If no placeholders in the URI empty hash is returned. Note that the method ignores query and fragment parts of URI.

path_concat()

Concatenates the url path with another path.

Arguments

string

substitute()

Substitutes values to the URI placeholders.

Arguments

hash

a hash of substitutions.

Throws

Eve::Error::Value

when not enough or redundant substitutions are specified.

get_query_parameter()

Returns a query parameter value for a certain parameter name.

Arguments

name

set_query_parameter()

Sets a query parameter value or a list of values for a certain parameter name.

Arguments

name
value

If a scalar value is passed, it is assigned as a single value for the parameter name. If a list reference is passed, the parameter is assigned as a list.

get_query_hash()

Gets query string parameters as a hash.

set_query_hash()

Sets query string parameters as a hash.

Arguments

hash
delimiter

is_relative()

Returns 0 or 1 depending on the URI.

Returns

1

the URI is relative, e.g. /some/path

0

the URI is absolute, e.g. http://example.com

SEE ALSO ^

URI

LICENSE AND COPYRIGHT ^

Copyright 2012 Igor Zinovyev.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

AUTHOR ^

Sergey Konoplev
Igor Zinovyev
syntax highlighting: