line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wallflower::Util; |
2
|
|
|
|
|
|
|
$Wallflower::Util::VERSION = '1.014'; |
3
|
2
|
|
|
2
|
|
92547
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
52
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use Exporter; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
98
|
|
7
|
2
|
|
|
2
|
|
1078
|
use HTTP::Headers; |
|
2
|
|
|
|
|
16004
|
|
|
2
|
|
|
|
|
74
|
|
8
|
2
|
|
|
2
|
|
959
|
use HTML::LinkExtor; |
|
2
|
|
|
|
|
17230
|
|
|
2
|
|
|
|
|
1000
|
|
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
|
3454
|
my ( $response, $url ) = @_; |
24
|
4
|
|
|
|
|
9
|
my $le = $linkextor{ HTTP::Headers->new( @{ $response->[1] } ) |
|
4
|
|
|
|
|
25
|
|
25
|
|
|
|
|
|
|
->content_type }; |
26
|
4
|
100
|
|
|
|
436
|
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
|
|
6
|
my ( $file, $url ) = @_; |
34
|
2
|
|
|
|
|
3
|
my @links; |
35
|
|
|
|
|
|
|
my $parser = HTML::LinkExtor->new( |
36
|
|
|
|
|
|
|
sub { |
37
|
11
|
|
|
11
|
|
8069
|
my ( $tag, @pairs ) = @_; |
38
|
11
|
|
|
|
|
22
|
my $i = 0; |
39
|
11
|
|
|
|
|
130
|
push @links, grep $i++ % 2, @pairs; |
40
|
|
|
|
|
|
|
}, |
41
|
2
|
|
|
|
|
28
|
$url |
42
|
|
|
|
|
|
|
); |
43
|
2
|
|
|
|
|
5545
|
$parser->parse_file("$file"); |
44
|
2
|
|
|
|
|
215
|
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
|
|
|
|
|
2
|
my $content = do { local ( *ARGV, $/ ); @ARGV = ("$file"); <> }; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
77
|
|
58
|
1
|
|
|
|
|
36
|
return map URI->new_abs( $_, $url ), grep defined, |
59
|
|
|
|
|
|
|
$content =~ /$css_regexp/gc; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |