06 Feb 2005 12:06:04 UTC
- Distribution: URI-Find-Rule
- Module version: 0.8
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (645 / 2 / 0)
- KwaliteeBus factor: 0
- 90.00% Coverage
- License: perl_5
- Activity24 month
- Download (5.43KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionRJP Rob Partingtonand 1 contributors
- Copyright (C) 2004, Rob Partington
URI::Find::Rule - Simpler interface to URI::Find
use URI::Find::Rule; # find all the http URIs in some text my @uris = URI::Find::Rule->scheme('http')->in($text); # or you can use anything that URI->can() for HTTP URIs my @uris = URI::Find::Rule->http->in($text); # find all the URIs referencing a host my @uris = URI::Find::Rule->host(qr/myhost/)->in($text);
URI::Find::Rule is a simpler interface to URI::Find (closely modelled on File::Find::Rule by Richard Clamp).
Because it operates on URI objects instead of the stringified versions of the found URIs, it's nicer than, say, grepping the stringified values from URI::Find::Simple's
It returns (default) a list containing
[$original, $uri]for each URI or, optionally, a list containing a URI object for each URI.
in, all the methods can take multiple strings or regexps to match against, e.g.
->scheme('http') # match against the single string 'http' ->scheme('http','ftp') # match either string 'http' or 'ftp' ->scheme(qr/tp$/, 'ldap') # match /tp$/ or the string 'ldap'
They can also be combined to provide more selective filtering, e.g.
->scheme('ftp')->host('pi.st') # match FTP URIs with a host of pi.st
The filtering is done by checking against the corresponding methods called on the URI object so almost anything (see BUGS) you can do with a URI object, you can filter on.
Only a few methods are listed, for more examples check the tests.
With a single argument, returns a list of anonymous arrays containing
($original_text, $uri)for each URI found in
With a true-valued second argument, it returns a list of URI objects, one for each URI found in
Negates the immediately following rule.
Filters the URIs found based on their scheme.
Filters the URIs found based on their parsed hostname.
A convenient alias for
->ldap('pi.st') # converts to ->scheme('ldap')->host('pi.st')
Any unrecognised method will be converted to
URI->can()needs a URI before it'll respond -- at the moment, this is
http://x:y@a/b#c?dwhich means that any of the scheme-specific methods (like
$uri->dnfor LDAP URIs can't be used.)
The anonymous arrays contain the original text and the stringified URI in reverse order when compared with URI::Find's callback. This may confuse.
Richard Clamp (patches, code to cargo cult from) John Levon (pointing out broken comments and complexity)
This module is free software, and may be distributed under the same terms as Perl itself.
Copyright (C) 2004, Rob Partington <firstname.lastname@example.org>
Module Install Instructions
To install URI::Find::Rule, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install URI::Find::Rule
For more information on module installation, please visit the detailed CPAN module installation guide.