Bot-Cobalt-Plugin-URLTitle
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Plugin/URLTitle.pm view on Meta::CPAN
my $msg = ${ shift() };
my $context = $msg->context;
my $channel = $msg->target;
foreach my $uri ( list_uris($msg->message) ) {
next if not $uri;
my $text = $self->ua->get($uri)->result->dom->at('title')->text or next;
my @split = split /\n/, unidecode($text); # Remove unicode characters and split on newlines
my $title = first { /\S/ } @split; # Grab first element with non-space characters
# Remove leading and trailing whitespace
$title =~ s/^\s+(.+)/$1/;
$title =~ s/(.+)\s+$/$1/;
my $resp = sprintf('[ %s ]', $title);
broadcast( 'message', $context, $channel, $resp );
}
( run in 0.309 second using v1.01-cache-2.11-cpan-88abd93f124 )