David E. Wheeler


URI::Nested - Nested URIs


  package URI::jdbc;
  use parent 'URI::Nested';
  sub prefix       { 'jdbc' }
  sub nested_class { undef  }
  sub subprotocol  { shift->nested_uri->scheme(@_) }

  package main;
  my $jdbc_uri = URI->new('jdbc:oracle:scott/tiger@//myhost:1521/myservicename');
  my $nested_uri = $jdbc_uri->nested_uri;


This class provides support for nested URIs, where the scheme is a prefix, and the remainder of the URI is another URI. Examples include JDBC URIs and database URIs.


The following differences exist compared to the URI class interface:

Class Method


Returns the prefix to be used, which corresponds to the URI's scheme. Defaults to the last part of class name.


Returns the URI subclass to use for the nested URI. If defined, the nested URI will always be coerced into this class if it is not naturally an instance of this class or one of its subclasses.



  my $uri = URI::Nested->new($string);
  my $uri = URI::Nested->new($string, $base);

Always returns a URI::Nested object. $base may be another URI object or string. Unlike in URI's new(), schemes will always be applied to the URI and the nested URI if they does not already schemes. And if nested_class is defined, the nested URI will be coerced into that class.



  my $scheme = $uri->scheme;
  $uri->scheme( $new_scheme );

Gets or sets the scheme part of the URI. When setting the scheme, it must always be the same as the value returned by prefix or an exception will be thrown -- although the letter casing may vary. The returned value is always lowercase.


  my $nested_uri = $uri->nested_uri;

Returns the nested URI.

Instance Methods


  my $abs = $uri->abs( $base_uri );

Returns the URI::Nested object itself. Unlike URI's abs(), $URI::ABS_ALLOW_RELATIVE_SCHEME is ignored.


  my $rel = $uri->rel( $base_uri );

Returns the URI::Nested object itself.


This module is stored in an open GitHub repository. Feel free to fork and contribute!

Please file bug reports via GitHub Issues or by sending mail to bug-URI-db@rt.cpan.org.


David E. Wheeler <david@justatheory.com>

Copyright and License

Copyright (c) 2013 David E. Wheeler. Some Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.