The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

URI::Attr - associate attributes with the URI name space

SYNOPSIS

 use URI::Attr;
 $attr = URI::Attr->new;
 $attr->attr_update(SERVER => "http://www.perl.com")->{visit} = "yes";
 if ($attr->attr_plain($url, "visit")) {
     #...
 }

DESCRIPTION

Instances of the URI::Attr class is able to associate attributes with "places" in the URI name space. The main idea is to be able to look up all attributes that are relevant to a specific absolute URI efficiently and to be able to override attributes at different hierarchal levels of the URI namespace.

The levels of the URI namespace is given the following names:

   GLOBAL  - affect all URIs
   SCHEME  - affect all URIs of the given scheme
   DOMAIN  - affect all URIs within the given domain (domains nest)
   HOST    - a given host
   SERVER  - a specific server (port) on the host
   DIR     - a directory component (nestable)
   PATH    - the final path component

GLOBAL and SCHEME are the only levels available for all URIs. The other levels only make sense for URIs that follow the generic URL pattern (like http: and ftp: schemes). Other level names can be used for specific schemes.

Lets take a look at an example. Consider the following URL:

   http://www.perl.com/cgi-bin/cpan_mod?module=LWP

This URL can be broken up into the following hierarchal levels:

   SCHEME  http
   DOMAIN  .com
   DOMAIN  .perl
   HOST    www
   SERVER  80        (implicit port)
   DIR     cgi-bin
   PATH    cpan-mod

METHODS

The following methods are provided by this class:

$db = URI::Attr->new

The constructor takes now arguments. It returns a newly allocated URI::Attr object.

$db->attr($uri, [$attr_name])

Look up all attributes that are relevant to the given $uri. In scalar context only the most specific attribute is returned. In list context all attributes are returned, with the most specific first. Each attribute is represented by a reference to a 2 element array. The first element is the name of the level. The second element is the attribute(s).

If the optional $attr_name is given, only the attribute with the given name is considered. If no $attr_name is given, then the attributes are returned as a hash reference.

$db->attr_plain($uri, [$attr_name])

Same as attr() but only return the attribute(s), not the associated level names.

$db->attr_update($level, $uri)

Returns a hash reference associated with $uri at the given $level. If the given $level name does not make sense for the given $uri return <undef>. If the $level is nestable, then the most specific instance related to the $uri is used.

The hash returned can then be updated in order to assign attributes to the given place in the URI name space.

$db->as_string

Dump the content of the URI::Attr object. Mainly useful for debugging.

BUGS

There ought to be a way to associate attributes with domains/hosts without regard to scheme (and for several schemes and several domain/hosts). Think, think,...

Perhaps there should be defined relationships between schemes, so that for instace everything that is valid for http is also valid for https, but not the other way around. Same goes for nntp and news which should be treated as the same thing and their relation to snews.

A similar concept is present in w3c-libwww under the name URL Tree. The scheme is simply ignored here and the root of the tree is the hostname part of the URL.

A totally different approach would be associate attributes with regular expressions that are matched against URLs. Perhaps this would have been a better way?

SEE ALSO

URI

COPYRIGHT

Copyright 1998, Gisle Aas

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