Pod::Extract::URI - Extract URIs from POD
use Pod::Extract::URI; # Get a list of URIs from a file my @uris = Pod::Extract::URI->uris_from_file( $file ); # Or filehandle my @uris = Pod::Extract::URI->uris_from_filehandle( $filehandle ); # Or the full OO my $parser = Pod::Extract::URI->new(); $parser->parse_from_file( $file ); my @uris = $parser->uris(); my %uri_details = $parser->uri_details();
This module parses POD and uses URI::Find or URI::Find::Schemeless to extract any URIs it can.
URI::Find
URI::Find::Schemeless
Create a new Pod::Extract::URI object.
Pod::Extract::URI
new() takes an optional hash of options, whose names correspond to object methods described in more detail below.
new()
Should the parser try to extract schemeless URIs (using URI::Find::Schemeless)?
Should the parser only look for URIs in L<> sequences?
Should the parser look in POD text paragraph, verbatim blocks, or commands?
Restrict URIs to the schemes in the arrayref.
Exclude URIs with the schemes in the arrayref.
An arrayref of patterns to ignore.
A reference to a subroutine to run for each URI to see if the URI should be ignored.
Convert the URIs found to their canonical form.
Strip extra brackets which may appear around the URL returned by URI::Find. See method below for more details.
Get/set the L_only flag. Takes one optional true/false argument to set the L_only flag. Defaults to false.
If true, Pod::Extract::URI will look for URIs only in L<> sequences, otherwise it will look anywhere in the POD.
L<>
Get/set the want_command flag. Takes one optional true/false argument to set the want_command flag. Defaults to true.
If true, Pod::Extract::URI will look for URIs in command blocks (i.e. =head1, etc.).
=head1
Get/set the want_textblock flag. Takes one optional true/false argument to set the want_textblock flag. Defaults to true.
If true, Pod::Extract::URI will look for URIs in textblocks (i.e. paragraphs).
Get/set the want_verbatim flag. Takes one optional true/false argument to set the want_verbatim flag. Defaults to true.
If true, Pod::Extract::URI will look for URIs in verbatim blocks (i.e. code examples, etc.).
$peu->schemes( [ 'http', 'ftp' ] );
Get/set the list of schemes to search for. Takes an optional arrayref of schemes to set.
If there are no schemes, Pod::Extract::URI will look for all schemes.
$peu->exclude_schemes( [ 'mailto', 'https' ] );
Get/set the list of schemes to ignore. Takes an optional arrayref of schemes to set.
$peu->stop_uris( [ qr/example\.com/, 'foobar.com' ] );
Get/set a list of patterns to apply to each URI to see if it should be ignored. Takes an optional arrayref of patterns to set. Strings in the list will be automatically converted to patterns (using qr//).
The URIs will be checked against the canonical URI form if use_canonical has been specified. Otherwise, they will be checked against the URI as it appears in the POD. If strip_brackets is specified, the brackets (and "URL:" prefix, if present) will be removed before testing.
use_canonical
strip_brackets
Any URI that matches a pattern will be ignored.
sub exclude { my $uri = shift; return ( $uri->host =~ /example\.com/ ) ? 1 : 0; } $peu->stop_sub( \&exclude );
Get/set a subroutine to check each URI found to see if it should be ignored. Takes an optional coderef to set.
The subroutine will be passed a reference to the URI object, the text found by URI::Find, and a reference to the Pod::Extract::URI object. If it returns true, the URI will be ignored.
URI
Get/set the use_canonical flag. Takes one optional true/false argument to set the use_canonical flag. Defaults to false.
If true, Pod::Extract::URI will store the URIs it finds in the canonical form (as returned by URI-canonical()>. The original URI and text will still be available via uri_details().
URI-
uri_details()
Get/set the strip_brackets flag. Takes one optional true/false argument to set the strip_brackets flag. Defaults to true.
RFC 2396 Appendix E suggests the form <http://www.example.com/> or <URL:http://www.example.com/> when embedding URLs in plain text. URI::Find includes these in the URLs it returns. If strip_brackets is true, this extra stuff will be removed and won't appear in the URIs returned by Pod::Extract::URI.
<http://www.example.com/>
<URL:http://www.example.com/>
$peu->parse_from_file( $filename );
Parses the POD from the specified file and stores the URIs it finds for later retrieval.
$peu->parse_from_filehandle( $filehandle );
Parses the POD from the filehandle and stores the URIs it finds for later retrieval.
my @uris = $peu->uris_from_file( $filename );
A shortcut for parse_from_file() then uris().
parse_from_file()
uris()
my @uris = $peu->uris_from_filehandle( $filename );
A shortcut for parse_from_filehandle() then uris().
parse_from_filehandle()
my @uris = $peu->uris();
Returns a list of the URIs found from parsing.
my %details = $peu->uri_details();
Returns a hash of data about the URIs found.
The keys of the hash are the URIs (which match those returned by uris()).
The values of the hash are arrayrefs of hashrefs. Each hashref contains
The URI object returned by URI::Find.
The text returned by URI::Find, which will have the brackets stripped from it if strip_brackets has been specified.
The original text returned by URI::Find.
The initial line number of the paragraph in which the URI was found.
The Pod::Paragraph object corresponding to the paragraph where the URI was found.
Pod::Paragraph
You can specify URIs to ignore in your POD, using a =for stop_uris command, e.g.
=for stop_uris
=for stop_uris www.foobar.com
These will be converted to patterns as if they had been passed in via stop_uris() directly, and will apply from the point of the command onwards.
stop_uris()
Ian Malpass (ian-cpan@indecorous.com)
Copyright 2007, Ian Malpass
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
URI::Find, URI::Find::Schemeless, URI.
To install Pod::Extract::URI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pod::Extract::URI
CPAN shell
perl -MCPAN -e shell install Pod::Extract::URI
For more information on module installation, please visit the detailed CPAN module installation guide.