Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: 17.4 The HTML ModuleChapter 17
The LWP Library
Next: VII. Perl/Tk
 

17.5 The URI Module

The URI module contains functions and modules to specify and convert URIs. (URLs are a type of URI.) There are three URI modules: URL, Escape, and Heuristic. Of primary importance to many LWP applications is the URI::URL class, which creates the objects used by LWP::UserAgent to determine protocols, server locations, and resource names.

The URI::Escape module replaces unsafe characters in URL strings with their appropriate escape sequences. URI::Heuristic provides convenience methods for creating proper URLs out of short strings and incomplete addresses.

17.5.1 URI::Escape

This module escapes or unescapes "unsafe" characters within a URL string. Unsafe characters in URLs are described by RFC 1738. Before you form URI::URL objects and use that class's methods, you should make sure your strings are properly escaped. This module does not create its own objects; it exports the following functions:

17.5.2 URI::URL

This module creates URL objects that store all the elements of a URL. These objects are used by the request method of LWP::UserAgent for server addresses, port numbers, file names, protocol, and many of the other elements that can be loaded into a URL.

The new constructor is used to make a URI::URL object:

$url = new URI::URL($url_string [, $base_url])
This method creates a new URI::URL object with the URL given as the first parameter. An optional base URL can be specified as the second parameter and is useful for generating an absolute URL from a relative URL.

The following list describes the methods for the URI::URL class:


Previous: 17.4 The HTML ModulePerl in a NutshellNext: VII. Perl/Tk
17.4 The HTML ModuleBook IndexVII. Perl/Tk