Permalink
Browse files

Request's timeouts in WebTitle

  • Loading branch information...
1 parent dc6d9c2 commit cc8989c711fcbc294b948d288a45ea378d6b3da4 @lessmian lessmian committed May 22, 2010
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
@@ -1,18 +1,25 @@
package WebTitle;
use LWP::Simple qw /get $ua/;
+use Sys::SigAction qw /timeout_call/;
+use vars qw /$site/;
sub init {
return { publicmsg => \&pubmsg };
}
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;
}

0 comments on commit cc8989c

Please sign in to comment.