NAME

URI::Fast - A fast(er) URI parser

VERSION

version 0.01

SYNOPSIS

use URI::Fast qw(uri);

my $uri = uri 'http://www.example.com/some/path?a=b&c=d';

if ($uri->scheme =~ /http(s)?/) {
  my @path = $uri->path;
  my $a = $uri->param('a');
  my $b = $uri->param('b');
}

if ($uri->path =~ /\/login/ && $uri->scheme ne 'https') {
  $uri->scheme('https');
  $uri->param('upgraded', 1);
}

DESCRIPTION

URI is an excellent module. It is battle-tested, robust, and at this point handles nearly every edge case imaginable. It is often the case, however, that one just needs to grab the path string out of a URL. Or validate some query parameters. Et cetera. In those cases, URI may seem like overkill and may, in fact, be much slower than a simpler solution, like URI::Split. Unfortunately, URI::Split is so bare bones that it does not even parse the authorization section or access or update query parameters.

URI::Fast aims to bridge the gap between the two extremes. It provides fast parsing without many of the frills of URI while at the same time providing slightly more than URI::Split by returning an object with methods to access and update portions of the URI.

EXPORTED SUBROUTINES

uri

Accepts a string, minimally parses it (using URI::Split), and returns a URI::Fast object.

When initially created, only the scheme, authorization section, path, query string, and fragment are split out. Thesea are broken down in a lazy fashion as needed when a related attribute accessor is called.

ATTRIBUTES

Unless otherwise specified, all attributes serve as full accessors, allowing the URI segment to be both retrieved and modified.

scheme

Defaults to file if not present in the uri string.

auth

The authorization section is composed of the username, password, host name, and port number:

hostname.com
someone@hostname.com
someone:secret@hostname.com:1234

Accessing the following attributes may incur a small amount of extra overhead the first time they are called and the auth string is parsed.

usr

The username segment of the authorization string.

pwd

The password segment of the authorization string.

host

The host name segment of the authorization string. May be a domain string or an IP address.

port

The port number segment of the authorization string.

path

In scalar context, returns the entire path string. In list context, returns a list of path segments, split by /.

The path may also be updated using either a string or an array ref of segments:

$uri->path('/foo/bar');
$uri->path(['foo', 'bar']);

query

The complete query string. Does not include the leading ?.

param

Gets or sets a parameter value. The first time this is called, it incurs the overhead of parsing and decoding the query string.

If the key appears more than once in the query string, the value returned will be an array ref of each of its values.

Setting the parameter will update the query string.

frag

The fragment section of the URI, excluding the leading #.

AUTHOR

Jeff Ober <sysread@fastmail.fm>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Jeff Ober.

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