Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Request's timeouts in WebTitle

  • Loading branch information...
commit cc8989c711fcbc294b948d288a45ea378d6b3da4 1 parent dc6d9c2
@lessmian lessmian authored
Showing with 12 additions and 4 deletions.
  1. +1 −0  README
  2. +11 −4 plugins/WebTitle.pm
View
1  README
@@ -3,5 +3,6 @@ Required modules:
MooseX::NonMoose
AnyEvent::IRC
LWP::Simple (for WebTitle plugin)
+ Sys::SigAction (for WebtiTle plugin)
Hash::MultiValue (for Powiedz plugin)
Tie::RegexpHash (for Odzywki plugin)
View
15 plugins/WebTitle.pm
@@ -1,5 +1,7 @@
package WebTitle;
use LWP::Simple qw /get $ua/;
+use Sys::SigAction qw /timeout_call/;
+use vars qw /$site/;
sub init {
return { publicmsg => \&pubmsg };
@@ -7,12 +9,17 @@ sub init {
sub pubmsg {
my ($bot, $data) = @_;
+ my $timeout = 10;
if ($data->{msg} =~ /(http:\/\/[^ ]+)/) {
$ua->max_size(1024);
- my $site = get($1);
- my ($title) = $site =~ /<title>([^<]+)<\/title>/i;
- $title =~ s/\n/ /g;
- return "[ $title ]" if $title;
+ if (timeout_call($timeout, sub {$site = get($1)})){
+ return undef;
+ }
+ else {
+ my ($title) = $site =~ /<title>([^<]+)<\/title>/i;
+ $title =~ s/\n/ /g;
+ return "[ $title ]" if $title;
+ }
}
return undef;
}
Please sign in to comment.
Something went wrong with that request. Please try again.