[Chapter 17] 17.5 The URI Module
Author: Ellen Siever, Stephen Spainhour & Nathan Patwardhan
Date: 1999-07-02T01:58:29Z

#

| Chapter 17 The LWP Library |

## 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:

- uri_escape
- uri_unescape

### 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:

- abs
- as_string
- base
- crack
- default_port
- eparams
- epath
- eq
- equery
- frag
- full_path
- host
- netloc
- params
- password
- path
- port
- query
- rel
- scheme
- strict
- user

17.4 The HTML Module |  | VII. Perl/Tk