NAME

URI::Info - Extract various information from a URI (URL)

VERSION

This document describes version 0.002 of URI::Info (from Perl distribution URI-Info), released on 2021-10-17.

SYNOPSIS

 use URI::Info;

 my $info = URI::Info->new(
     # include_plugins => ['Search::*'],  # only use these plugins. by default, all plugins will be loaded
     # exclude_plugins => [...],          # don't use certain plugins
 );

 my $res = $info->info("https://www.google.com/search?safe=off&oq=kathy+griffin");
 # => {
 #        host => "www.google.com",
 #        is_search=>1,
 #        search_engine=>"Google",
 #        search_string=>"kathy griffin",
 # }

DESCRIPTION

This module (and its plugins) will let you extract various information from a piece of URI (URL) string.

Keywords: URI parser, URL parser, search string extractor

FUNCTIONS

uri_info

Usage:

 my $hashref = uri_info($uri);

Return a hash of extracted pieces of information from a $uri string. Will consult the plugins to do the hard work. All the installed plugins will be used. To customize the set of plugins to use, use the OO interface.

METHODS

new

Usage:

 my $uinfo = URI::Info->new(%args);

Constructor. Known arguments (* marks required arguments):

  • include_plugins

    Array of plugins (names or wildcard patterns or names+arguments) to include. Plugin name is module name under URI::Info::Plugin:: without the prefix, e.g.:

     SearchQuery::tokopedia

    Wildcard pattern is a pattern containing wildcard characters, e.g:

     SearchQuery::toko*
     SearchQuery::**

    See Module::List::Wildcard for more details on the wildcard behavior, particularly the difference between * and **.

    Name+argument is either: 1) a string containing plugin name followed by = followed by a comma-separated list of arguments, or; 2) a 2-element arrayref where the first element is plugin name or wildcard pattern, and the second element is an arrayref or hashref of arguments to instantiate the plugin with. Examples:

     SearchQuery::tokopedia=foo,1,bar,2
     ['SearchQuery::tokopedia', {foo=>1, bar=>2, ...}]

    If include_plugins is unspecified, will list all installed modules under URI::Info::Plugin:: and include them all.

  • exclude_plugins

    Array of plugins (names or wildcard patterns) to exclude.

    Takes precedence over include_plugins argument.

    Default is empty array.

info

Usage:

 my $hashref = $uinfo->info($url);

Example:

 my $hashref = $uinfo->info("https://www.google.com/search?q=foo+bar");
 # => {url=>"https://www.google.com/search?q=foo+bar", is_search=>1, search_type=>'search', search_query=>'foo bar'}

ENVIRONMENT

URI_INFO_PLUGINS

This can be used to include/exclude plugins when include_plugins *and* exclude_plugins attributes are not set. The syntax is:

 -Plugin1ToExclude,+Plugin2ToInclude,arg1,val1,...,+Plugin3ToInclude

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/URI-Info.

SOURCE

Source repository is at https://github.com/perlancar/perl-URI-Info.

SEE ALSO

URI::ParseSearchString. For extracting search query terms, this module is much more concise albeit not plugin-based. Last update is 2013.

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTOR

Steven Haryanto <stevenharyanto@gmail.com>

CONTRIBUTING

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by perlancar <perlancar@cpan.org>.

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

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=URI-Info

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.