GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  ROSE::URI (3)

.ds Aq ’

NAME

Rose::URI - A URI class that allows easy and efficient manipulation of URI components.

CONTENTS

SYNOPSIS



    use Rose::URI;

    $uri = Rose::URI->new(pw@foo.com/bar/baz">http://un:pw@foo.com/bar/baz?a=1&b=two+3);

    $scheme = $uri->scheme;
    $user   = $uri->username;
    $pass   = $uri->password;
    $host   = $uri->host;
    $path   = $uri->path;
    ...

    $b = $uri->query_param(b);  # $b = "two 3"
    $a = $uri->query_param(a);  # $a = 1

    $uri->query_param_delete(b);
    $uri->query_param(c => blah blah);
    ...

    print $uri;



DESCRIPTION

Rose::URI is an alternative to URI. The important differences are as follows.

Rose::URI provides a rich set of query string manipulation methods. Query parameters can be added, removed, and checked for their existence. URI allows the entire query to be set or returned as a whole via the query_form or query methods, and the URI::QueryParam module provides a few more methods for query string manipulation.

Rose::URI supports query parameters with multiple values (e.g. a=1&a=2). URI has limited support for this through query_form’s list return value. Better methods are available in URI::QueryParam.

Rose::URI uses Apache’s C-based URI parsing and HTML escaping functions when running in a mod_perl 1.x web server environment.

Rose::URI stores each URI in pieces (scheme, host, path, etc.) and then assembles those pieces when the entire URI is needed as a string. This technique is based on the assumption that the URI will be manipulated many more times than it is stringified. If this is not the case in your usage scenario, then URI may be a better alternative.

Now some similarities: both classes use the overload module to allow magic stringification. Both URI and Rose::URI objects can be printed and compared as if they were strings.

Rose::URI actually uses the URI class to do the heavy lifting of parsing URIs when not running in a mod_perl 1.x environment.

Finally, a caveat: Rose::URI supports only http-like URIs. This includes ftp, http, https, and other similar looking URIs. URI supports many more esoteric URI types (gopher, mailto, etc.) If you need to support these formats, use URI instead.

CONSTRUCTOR

<B>new [ URI | PARAMS ]B> Constructs a URI object based on URI or PARAMS, where URI is a string and PARAMS are described below. Returns a new Rose::URI object.

The query string portion of the URI argument may use either & or ; as the parameter separator. Examples:



    $uri = Rose::URI->new(/foo?a=1&b=2);
    $uri = Rose::URI->new(/foo?a=1;b=2); # same thing



The query_param_separator parameter determines what is used when the query string (or the whole URI) is output as a string later.

Rose::URI uses URI or Apache::URI (when running under mod_perl 1.x) to do its URI string parsing.

Valid PARAMS are:



    fragment
    host
    password
    path
    port
    query
    scheme
    username

    query_param_separator



Which correspond to the following URI pieces:



    <scheme>://<username:password>@<path>?<query>#<fragment>



All the above parameters accept strings. See below for more information about the query parameter. The query_param_separator parameter determines the separator used when constructing the query string. It is & by default (e.g. a=1&b=2)

CLASS METHODS

<B>default_omit_empty_query_params [BOOL]B> Get or set a boolean value that determines whether or not query parameters with empty (that is, undef or zero-length) values will be omitted from the query string by default. The default value is false.
<B>default_query_param_separator [CHARACTER]B> Get or set the character used to separate query parameters in the stringified version of Rose::URI objects. Defaults to &.

OBJECT METHODS

<B>abs [BASE]B> This method exists solely for compatibility with URI.

Returns an absolute Rose::URI object. If the current URI is already absolute, then a reference to it is simply returned. If the current URI is relative, then a new absolute URI is constructed by combining the URI and the BASE, and returned.

<B>as_stringB> Returns the URI as a string. The string is URI escaped (reserved URI characters are replaced with %xx sequences), but not HTML escaped (ampersands are not escaped, for example).
<B>cloneB> Returns a copy of the Rose::URI object.
<B>fragment [FRAGMENT]B> Get or set the fragment portion of the URI.
<B>omit_empty_query_params [BOOL]B> Get or set a boolean value that determines whether or not query parameters with empty (that is, undef or zero-length) values will be omitted from the query string. The default value is determined by the default_query_param_separator class method.
<B>password [PASSWORD]B> Get or set the password portion of the URI.
<B>path [PATH]B> Get or set the path portion of the URI.
<B>port [PORT]B> Get or set the port number portion of the URI.
<B>query [QUERY]B> Get or sets the URI’s query. QUERY may be an appropriately escaped query string (e.g. a=1&b=2&c=a+long+string), a reference to a hash, or a list of name/value pairs.

Query strings may use either & or ; as their query separator. If a & character exists anywhere in the query string, it is assumed to be the separator.

If none of the characters &, ;, or = appears in the query string, then the entire query string is taken as a single parameter name with an undefined value.

Hashes and lists should specify multiple parameter values using array references.

Here are some examples representing the query string a=1&a=2&b=3



    $uri->query("a=1&a=2&b=3");             # string
    $uri->query("a=1;a=2;b=3");             # same thing
    $uri->query({ a => [ 1, 2 ], b => 3 }); # hash ref
    $uri->query(a => [ 1, 2 ], b => 3);     # list



Returns the current (or new) query as a URI-escaped (but not HTML-escaped) query string.

<B>query_form QUERYB> Implementation of URI’s method of the same name. This exists for backwards compatibility purposes only and should not be used (or necessary). See the URI documentation for more details.
<B>query_hashB> Returns the current query as a hash (in list context) or reference to a hash (in scalar context), with multiple parameter values represented by array references (see the query method for details).

The return value is a shallow copy of the actual query hash. It should be treated as read-only unless you really know what you are doing.

Example:



    $uri = Rose::URI->new(/foo?a=1&b=2&a=2);

    $h = $uri->query_hash; # $h = { a => [ 1, 2 ], b => 2 }



<B>query_param NAME [, VALUE]B> Get or set a query parameter. If only NAME is passed, it returns the value of the query parameter named NAME. Parameters with multiple values are returned as array references. If both NAME and VALUE are passed, it sets the parameter named NAME to VALUE, where VALUE can be a simple scalar value or a reference to an array of simple scalar values.

Examples:



    $uri = Rose::URI->new(/foo?a=1);

    $a = $uri->query_param(a); # $a = 1

    $uri->query_param(a => 3); # query string is now "a=3"

    $uri->query_param(b => [ 4, 5 ]); # now "a=3&b=4&b=5"

    $b = $uri->query_param(b); # $b = [ 4, 5 ];



<B>query_params NAME [, VALUE]B> Same as the query_param method, except the return value is always either an array (in list context) or reference to an array (in scalar context), even if there is only one value.

Examples:



    $uri = Rose::URI->new(/foo?a=1&b=1&b=2);

    $a = $uri->query_params(a); # $a = [ 1 ]
    @a = $uri->query_params(a); # @a = ( 1 )

    $b = $uri->query_params(a); # $b = [ 1, 2 ]
    @b = $uri->query_params(a); # @b = ( 1, 2 )



<B>query_param_add NAME, VALUEB> Adds a new value to a query parameter. Example:



    $uri = Rose::URI->new(/foo?a=1&b=1);

    $a = $uri->query_param_add(b => 2); # now "a=2&b=1&b=2"



Returns an array (in list context) or reference to an array (in scalar context) of the new parameter value(s).

<B>query_param_delete NAMEB> Deletes all instances of the parameter named NAME from the query.
<B>query_param_exists NAMEB> Returns a boolean value indicating whether or not a parameter named NAME exists in the query string.
<B>query_param_separator [CHARACTER]B> Get or set the character used to separate query parameters in the stringified version of the URI. Defaults to the return value of the default_query_param_separator class method (& by default).
<B>rel BASEB> This method exists solely for compatibility with URI.

Returns a relative URI reference if it is possible to make one that denotes the same resource relative to BASE. If not, then the current URI is simply returned.

<B>scheme [SCHEME]B> Get or set the scheme portion of the URI.
<B>userinfoB> Returns the username and password attributes joined by a : (colon). The username and password are not escaped in any way. If there is no password, only the username is returned (without the colon). If neither exist, an empty string is returned.
<B>userinfo_escapedB> Returns the username and password attributes joined by a : (colon). The username and password are URI-escaped, but not HTML-escaped. If there is no password, only the username is returned (without the colon). If neither exist, an empty string is returned.
<B>username [USERNAME]B> Get or set the username portion of the URI.

AUTHOR

John C. Siracusa (siracusa@gmail.com)

LICENSE

Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 ROSE::URI (3) 2015-03-18

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.