line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wallflower::Util; |
2
|
|
|
|
|
|
|
$Wallflower::Util::VERSION = '1.013'; |
3
|
2
|
|
|
2
|
|
88126
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
24
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use Exporter; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
72
|
|
7
|
2
|
|
|
2
|
|
1174
|
use HTTP::Headers; |
|
2
|
|
|
|
|
16555
|
|
|
2
|
|
|
|
|
70
|
|
8
|
2
|
|
|
2
|
|
1007
|
use HTML::LinkExtor; |
|
2
|
|
|
|
|
17592
|
|
|
2
|
|
|
|
|
996
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( links_from ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# some code to obtain links to resources |
14
|
|
|
|
|
|
|
my %linkextor = ( |
15
|
|
|
|
|
|
|
'text/html' => \&_links_from_html, |
16
|
|
|
|
|
|
|
'text/x-server-parsed-html' => \&_links_from_html, |
17
|
|
|
|
|
|
|
'application/xhtml+xml' => \&_links_from_html, |
18
|
|
|
|
|
|
|
'application/vnd.wap.xhtml+xml' => \&_links_from_html, |
19
|
|
|
|
|
|
|
'text/css' => \&_links_from_css, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub links_from { |
23
|
4
|
|
|
4
|
1
|
3610
|
my ( $response, $url ) = @_; |
24
|
4
|
|
|
|
|
11
|
my $le = $linkextor{ HTTP::Headers->new( @{ $response->[1] } ) |
|
4
|
|
|
|
|
30
|
|
25
|
|
|
|
|
|
|
->content_type }; |
26
|
4
|
100
|
|
|
|
471
|
return if !$le; |
27
|
3
|
|
100
|
|
|
14
|
return grep !$_->scheme || $_->scheme =~ /^http/, |
28
|
|
|
|
|
|
|
$le->( $response->[2], $url ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# HTML |
32
|
|
|
|
|
|
|
sub _links_from_html { |
33
|
2
|
|
|
2
|
|
7
|
my ( $file, $url ) = @_; |
34
|
2
|
|
|
|
|
4
|
my @links; |
35
|
|
|
|
|
|
|
my $parser = HTML::LinkExtor->new( |
36
|
|
|
|
|
|
|
sub { |
37
|
11
|
|
|
11
|
|
7917
|
my ( $tag, @pairs ) = @_; |
38
|
11
|
|
|
|
|
22
|
my $i = 0; |
39
|
11
|
|
|
|
|
131
|
push @links, grep $i++ % 2, @pairs; |
40
|
|
|
|
|
|
|
}, |
41
|
2
|
|
|
|
|
32
|
$url |
42
|
|
|
|
|
|
|
); |
43
|
2
|
|
|
|
|
5494
|
$parser->parse_file("$file"); |
44
|
2
|
|
|
|
|
232
|
return @links; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# CSS |
48
|
|
|
|
|
|
|
my $css_regexp = qr{ |
49
|
|
|
|
|
|
|
(?: |
50
|
|
|
|
|
|
|
\@import\s+(?:"([^"]+)"|'([^']+)') |
51
|
|
|
|
|
|
|
| url\((?:"([^"]+)"|'([^']+)'|([^)]+))\) |
52
|
|
|
|
|
|
|
) |
53
|
|
|
|
|
|
|
}x; |
54
|
|
|
|
|
|
|
sub _links_from_css { |
55
|
1
|
|
|
1
|
|
4
|
my ( $file, $url ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
3
|
my $content = do { local ( *ARGV, $/ ); @ARGV = ("$file"); <> }; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
78
|
|
58
|
1
|
|
|
|
|
40
|
return map URI->new_abs( $_, $url ), grep defined, |
59
|
|
|
|
|
|
|
$content =~ /$css_regexp/gc; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |