URI::SmartURI - Subclassable and hostless URIs
Version 0.031
my $uri = URI::SmartURI->new( 'http://host/foo/', { reference => 'http://host/bar/' } ); my $hostless = $uri->hostless; # '/foo/' $hostless->absolute; # 'http://host/foo/' $uri->relative; # '../foo/'
This is a sort of "subclass" of URI using delegation with some extra methods, all the methods that work for URIs will work on these objects as well.
It's similar in spirit to URI::WithBase.
It's also completely safe to subclass for your own use.
Takes a uri $str and an optional scheme or hashref with a reference uri (for computing relative/absolute URIs) and an optional scheme.
my $uri = URI::SmartURI->new('http://dev.catalyst.perl.org/'); my $uri = URI::SmartURI->new('/dev.catalyst.perl.org/new-wiki/', 'http'); my $uri = URI::SmartURI->new( 'http://search.cpan.org/~jrockway/Catalyst-Manual-5.701003/', { reference => 'http://search.cpan.org/' } );
The object returned will be blessed into a scheme-specific subclass, based on the class of the underlying $uri->obj (URI object.) For example, URI::SmartURI::http, which derives from URI::SmartURI (or $uri->factory_class if you're subclassing.)
Proxy for URI->new_abs
Proxy for URI::URL->newlocal
Returns the URI with the scheme and host parts stripped.
Accessor for the reference URI (for relative/absolute below.)
Returns the URI relative to the reference URI.
Returns the absolute URI using the reference URI as base.
stringification works, just like with URIs
and == does as well
Explicit equality check to another URI, can be used as URI::SmartURI::eq($uri1, $uri2) as well.
Accessor for the URI object methods are delegated to.
The class whose constructor was called to create the $uri object, usually URI::SmartURI or your own subclass. This is used to call class (rather than object) methods.
These are used internally by SmartURI, and are not interesting for general use, but may be useful for writing subclasses.
Returns a hashref of options for the $uri (reference and scheme.)
Converts, eg., "URI::http" to "URI::SmartURI::http".
Creates a new proxy class class for a URI class, with all exports and constructor intact, and returns its name, which is made using _resolve_uri_class (above).
Inflate any URI objects in @rray into URI::SmartURI objects, all other members pass through unharmed. $opts is a hashref of options to include in the objects created.
Deflate any URI::SmartURI objects in @rray into the URI objects they are proxies for, all other members pass through unharmed.
On import with the -import_uri_mods flag it loads all the URI .pms into your class namespace.
-import_uri_mods
This works:
use URI::SmartURI '-import_uri_mods'; use URI::SmartURI::WithBase; use URI::SmartURI::URL; my $url = URI::SmartURI::URL->new(...); # URI::URL proxy
Even this works:
use URI::SmartURI '-import_uri_mods'; use URI::SmartURI::Escape qw(%escapes);
It even works with a subclass of URI::SmartURI.
I only wrote this functionality so that I could run the URI test suite without much modification, it has no real practical value.
Please report any bugs or feature requests to bug-uri-smarturi at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=URI-SmartURI. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-uri-smarturi at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc URI::SmartURI
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=URI-SmartURI
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/URI-SmartURI
CPAN Ratings
http://cpanratings.perl.org/d/URI-SmartURI
Search CPAN
http://search.cpan.org/dist/URI-SmartURI
Catalyst::Plugin::SmartURI, URI, URI::WithBase
Thanks to folks on freenode #perl for helping me out when I was getting stuck, Somni, revdiablo, PerlJam and others whose nicks I forget.
Rafael Kitover, <rkitover at cpan.org>
<rkitover at cpan.org>
Copyright (c) 2008 Rafael Kitover
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install URI::SmartURI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm URI::SmartURI
CPAN shell
perl -MCPAN -e shell install URI::SmartURI
For more information on module installation, please visit the detailed CPAN module installation guide.