line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
package HTML::RewriteAttributes::Links; |
3
|
4
|
|
|
4
|
|
52341
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
214
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
131
|
|
5
|
4
|
|
|
4
|
|
26
|
use base 'HTML::RewriteAttributes'; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
2157
|
|
6
|
4
|
|
|
4
|
|
4314
|
use HTML::Tagset (); |
|
4
|
|
|
|
|
8851
|
|
|
4
|
|
|
|
|
270
|
|
7
|
4
|
|
|
4
|
|
3205
|
use URI; |
|
4
|
|
|
|
|
30564
|
|
|
4
|
|
|
|
|
1704
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %rewritable_attrs; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
for my $tag (keys %HTML::Tagset::linkElements) { |
14
|
|
|
|
|
|
|
for my $attr (@{ $HTML::Tagset::linkElements{$tag} }) { |
15
|
|
|
|
|
|
|
$rewritable_attrs{$tag}{$attr} = 1; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _should_rewrite { |
20
|
36
|
|
|
36
|
|
73
|
my ($self, $tag, $attr) = @_; |
21
|
|
|
|
|
|
|
|
22
|
36
|
|
100
|
|
|
257
|
return ( $rewritable_attrs{$tag} || {} )->{$attr}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _rewrite { |
26
|
7
|
|
|
7
|
|
22
|
my ($self, $html, $arg) = @_; |
27
|
|
|
|
|
|
|
|
28
|
7
|
100
|
|
|
|
30
|
if (!ref($arg)) { |
29
|
5
|
|
|
|
|
27
|
$self->{rewrite_link_base} = $arg; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$arg = sub { |
32
|
18
|
|
|
18
|
|
31
|
my ($tag, $attr, $value) = @_; |
33
|
18
|
|
|
|
|
80
|
my $uri = URI->new($value); |
34
|
|
|
|
|
|
|
|
35
|
18
|
100
|
|
|
|
23167
|
$uri = $uri->abs($self->{rewrite_link_base}) |
36
|
|
|
|
|
|
|
unless defined $uri->scheme; |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
15737
|
return $uri->as_string; |
39
|
5
|
|
|
|
|
33
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
7
|
|
|
|
|
44
|
$self->SUPER::_rewrite($html, $arg); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# if we see a base tag, steal its href for future link resolution |
46
|
|
|
|
|
|
|
sub _start_tag { |
47
|
39
|
|
|
39
|
|
89
|
my $self = shift; |
48
|
39
|
|
|
|
|
66
|
my ($tag, $attr, $attrseq, $text) = @_; |
49
|
|
|
|
|
|
|
|
50
|
39
|
100
|
66
|
|
|
122
|
if ($tag eq 'base' && defined $attr->{href}) { |
51
|
2
|
|
|
|
|
5
|
$self->{rewrite_link_base} = $attr->{href}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
39
|
|
|
|
|
145
|
$self->SUPER::_start_tag(@_); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |