line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LiBot::Handler::URLFetcher; |
2
|
1
|
|
|
1
|
|
2282
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
66
|
|
3
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
52
|
|
4
|
1
|
|
|
1
|
|
8
|
use utf8; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
10
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3291
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
28941
|
|
|
1
|
|
|
|
|
40
|
|
7
|
1
|
|
|
1
|
|
938
|
use HTTP::Response::Encoding; |
|
1
|
|
|
|
|
417
|
|
|
1
|
|
|
|
|
26
|
|
8
|
1
|
|
|
1
|
|
821
|
use HTML::Entities; |
|
1
|
|
|
|
|
6381
|
|
|
1
|
|
|
|
|
103
|
|
9
|
1
|
|
|
1
|
|
8
|
use Encode; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
10
|
1
|
|
|
1
|
|
6548
|
use Furl; |
|
1
|
|
|
|
|
20462
|
|
|
1
|
|
|
|
|
32
|
|
11
|
1
|
|
|
1
|
|
10
|
use Text::Shorten qw(shorten_scalar); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
58
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use Mouse; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# TODO: max_size? |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has prefix => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
default => sub { 'Title: ' }, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has ua => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
lazy => 1, |
25
|
|
|
|
|
|
|
default => sub { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Furl->new( |
29
|
|
|
|
|
|
|
agent => "LiBot/$LiBot::VERSION", |
30
|
|
|
|
|
|
|
timeout => 3, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
526
|
no Mouse; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub init { |
38
|
0
|
|
|
0
|
0
|
|
my ($self, $bot) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$bot->register( |
41
|
|
|
|
|
|
|
qr/(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/ => sub { |
42
|
0
|
|
|
0
|
|
|
my ( $cb, $event, $url ) = @_; |
43
|
0
|
|
|
|
|
|
my $res = $self->ua->get($url); |
44
|
0
|
|
|
|
|
|
$res = $res->as_http_response; |
45
|
0
|
0
|
|
|
|
|
if ($res->content =~ m{\s*(.*?)\s*}smi) { |
46
|
0
|
|
|
|
|
|
my $title = decode_entities($res->encoder->decode($1)); |
47
|
0
|
|
|
|
|
|
$cb->($self->prefix() . shorten_scalar($title, 120)); |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
$cb->(''); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |