App-RoboBot

 view release on metacpan or  search on metacpan

lib/App/RoboBot/Plugin/Net/URLs.pm  view on Meta::CPAN

package App::RoboBot::Plugin::Net::URLs;
$App::RoboBot::Plugin::Net::URLs::VERSION = '4.004';
use v5.20;

use namespace::autoclean;

use Moose;
use MooseX::SetOnce;

use HTML::TreeBuilder::LibXML;
use LWP::UserAgent;
use Text::Levenshtein qw( distance );
use URI::Find;

extends 'App::RoboBot::Plugin';

=head1 net.urls

Provides functions related to URLs.

In addition to exported functions, this module inserts a pre-hook into the
message processing pipeline which looks for any URLs in messages others have
sent. Any URLs that are detected are retrieved automatically and an attempt is
made to locate a page title. Redirects are also logged.

If either a page title or any redirects are found, they are displayed back in
the channel.

A timeout on all URL retrievals is set to prevent poorly behaving websites from
delaying subsequent message processing. If the timeout is reached, all further
URL detection and page title lookup is skipped for the current message.

=cut

has '+name' => (
    default => 'Net::URLs',
);

has '+description' => (
    default => 'Provides functions related to URLs.',
);

has '+before_hook' => (
    default => 'check_urls',
);

=head2 shorten-url

=head3 Description

Returns a short version of a URL for easier sharing.

=head3 Usage

<url>

=head3 Examples

    :emphasize-lines: 2

    (shorten-url "http://images.google.com/really-long-image-url.jpg?with=plenty&of=tracking&arguments=foo123")
    "http://tinyurl.com/foObar42"
=cut

has '+commands' => (
    default => sub {{
        'shorten-url' => { method      => 'shorten_url',
                           description => 'Returns a short version of a URL for easier sharing.',
                           usage       => '"<url>"',
                           example     => '"http://images.google.com/really-long-image-url.jpg?with=plenty&of=tracking&arguments=foo123"',
                           result      => 'http://tinyurl.com/foObar42' },
    }},
);

has 'ua' => (
    is      => 'ro',
    isa     => 'LWP::UserAgent',
    default => sub {
        LWP::UserAgent->new(
            agent        => "App::RoboBot",
            timeout      => 3,
            max_redirect => 5,



( run in 0.991 second using v1.01-cache-2.11-cpan-39bf76dae61 )