GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  URI::MATCH (3)

.ds Aq ’

NAME

URI::Match - Match URLs By Parts

CONTENTS

SYNOPSIS



  use URI;
  use URI::Match;

  my $uri = URI->new("http://www.example.com");

  # Match just a single part of the URL
  if ( $uri->match_parts( host => qr/^(?!www).+\.cpan\.org$/ )) {
    # matched
  }

  # Match using a subroutine
  my $code = sub {
    my ($host, $url) = @_;
    return $host eq www.perl.org;
  };
  if ( $uri->match_parts( host => $code ) ) {
    # matched
  }

  # Match using an object
  my $object = My::Matcher->new(); # must implement "match"
  if ( $uri->match_parts( host => $object ) ) {
    # matched
  }

  # Match several parts
  my $code = sub {
    my ($path, $url) = @_;
    return $path ne /;
  };
  if ( $uri->match_parts(
        host => qr/^(?!www).+\.cpan\.org$/,
        path => $code
  )) {
    # matched
  }

  # Match the whole URL (just for completeness)
  if ($uri->match_parts( qr{^http://search\.cpan\.org} )) {
    # matched
  }



DESCRIPTION

This is a simple utility that adds ability to match URL parts against regular expressions, subroutines, or objects that implement a match() method.

Since this module uses loops and method calls, writing up a clever regular expression and using it directly against the whole URL is probably faster. This module aims to solve the problem where readability matters, or when you need to assemble the match conditions at run time.

URI::Match adds the following methods to the URI namespace.

METHODS

    match_parts(%cond)

Matches the URI object against the given conditions. The conditions can be given as a single scalar or a hash. If given a single scalar, it will match against the whole URI. Otherwise, the key value will be taken as the part to match the condition against.

For example,



  $uri->match_parts( qr{^ftp://ftp.cpan.org$} )



Will only match if the entire URL matches the regular expression above. But If you want to match against several different schemes (say, http and ftp) and aother set of hosts, you could say:



  $uri->match_parts(
    scheme => qr{^(?:ftp|http)$},
    host   => qr{^.+\.example\.com$}
  )



Conditions can be either a scalar, a regular expression, a subroutine, or an object which implements a match() method. Simple scalars are treated as regular expressions.

AUTHOR

Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>

LICENSE

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

See http://www.perl.com/perl/misc/Artistic.html

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 URI::MATCH (3) 2007-11-08

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.