line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::AutoLink; |
2
|
3
|
|
|
3
|
|
93771
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
324
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
79
|
use 5.006; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
167
|
|
5
|
3
|
|
|
3
|
|
16
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
201
|
|
6
|
3
|
|
|
3
|
|
4525
|
use HTML::TreeBuilder; |
|
3
|
|
|
|
|
163795
|
|
|
3
|
|
|
|
|
41
|
|
7
|
|
|
|
|
|
|
use Module::Pluggable |
8
|
3
|
|
|
|
|
26
|
require => 0, |
9
|
|
|
|
|
|
|
search_path => 'Text::AutoLink::Plugin', |
10
|
|
|
|
|
|
|
sub_name => 'available_plugins', |
11
|
3
|
|
|
3
|
|
3686
|
; |
|
3
|
|
|
|
|
38504
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN { |
14
|
3
|
|
|
3
|
|
2431
|
$VERSION = '0.04000' |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new |
18
|
|
|
|
|
|
|
{ |
19
|
5
|
|
|
5
|
1
|
5898
|
my $class = shift; |
20
|
5
|
|
|
|
|
18
|
my %args = @_; |
21
|
5
|
|
|
|
|
26
|
my $self = bless { |
22
|
|
|
|
|
|
|
plugins => [], |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
100
|
|
|
52
|
$args{plugins} ||= [$class->available_plugins]; |
26
|
5
|
|
|
|
|
17409
|
foreach my $p (@{$args{plugins}}) { |
|
5
|
|
|
|
|
22
|
|
27
|
18
|
100
|
|
|
|
51
|
if (! ref $p) { |
28
|
17
|
|
|
|
|
1361
|
eval "require $p"; |
29
|
17
|
50
|
|
|
|
84
|
die if $@; |
30
|
17
|
|
|
|
|
144
|
$p = $p->new; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
18
|
|
|
|
|
26
|
push @{$self->{plugins}}, $p; |
|
18
|
|
|
|
|
74
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
|
|
27
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub plugins |
40
|
|
|
|
|
|
|
{ |
41
|
16
|
|
|
16
|
1
|
1954
|
my $self = shift; |
42
|
16
|
100
|
|
|
|
41
|
wantarray ? @{$self->{plugins}} : $self->{plugins}; |
|
14
|
|
|
|
|
57
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _parse |
46
|
|
|
|
|
|
|
{ |
47
|
64
|
|
|
64
|
|
85
|
my $self = shift; |
48
|
64
|
|
|
|
|
73
|
my $x = shift; |
49
|
|
|
|
|
|
|
|
50
|
64
|
100
|
|
|
|
184
|
if ($x->attr('_tag') eq 'a') { |
51
|
16
|
|
|
|
|
226
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
48
|
|
|
|
|
813
|
my @list = $x->content_list; |
55
|
48
|
|
|
|
|
385
|
for(my $i = 0; $i < @list; $i++) { |
56
|
62
|
|
|
|
|
86
|
my $c = $list[$i]; |
57
|
62
|
100
|
|
|
|
115
|
if (ref $c) { |
58
|
48
|
|
|
|
|
122
|
$self->_parse($c); |
59
|
|
|
|
|
|
|
} else { |
60
|
14
|
|
|
|
|
246
|
foreach my $p ($self->plugins) { |
61
|
46
|
50
|
|
|
|
359
|
next unless $c; |
62
|
46
|
100
|
|
|
|
149
|
next unless $p->process(\$c); |
63
|
11
|
|
|
|
|
43
|
my $subtree = HTML::TreeBuilder->new_from_content($c); |
64
|
11
|
|
|
|
|
9233
|
$self->_parse($subtree); |
65
|
11
|
|
|
|
|
143
|
$x->splice_content($i, 1, $subtree); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub parse_file |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
74
|
0
|
|
|
|
|
0
|
my $file = shift; |
75
|
0
|
0
|
|
|
|
0
|
open my $fh, "<", $file or die "Failed to open file $file: $!"; |
76
|
0
|
|
|
|
|
0
|
$self->parse_fh($fh); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub parse_fh |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
82
|
0
|
|
|
|
|
0
|
my $fh = shift; |
83
|
0
|
|
|
|
|
0
|
my $text = join '', <$fh>; |
84
|
0
|
|
|
|
|
0
|
return $self->parse_string($text); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub parse_string |
88
|
|
|
|
|
|
|
{ |
89
|
5
|
|
|
5
|
1
|
23
|
my $self = shift; |
90
|
5
|
|
|
|
|
11
|
my $string = shift; |
91
|
|
|
|
|
|
|
|
92
|
5
|
|
|
|
|
6
|
my $ret; |
93
|
5
|
|
|
|
|
52
|
my $tree = HTML::TreeBuilder->new_from_content($string); |
94
|
5
|
|
|
|
|
3510
|
$self->_parse($tree); |
95
|
5
|
|
|
|
|
171
|
foreach my $i ($tree->look_down(_implicit => 1)) { |
96
|
23
|
100
|
|
|
|
1252
|
$i->replace_with_content if $i->parent; |
97
|
|
|
|
|
|
|
} |
98
|
5
|
100
|
|
|
|
246
|
if ($tree->implicit) { |
99
|
10
|
100
|
|
|
|
617
|
$ret = join('', |
100
|
3
|
|
|
|
|
50
|
map { ref $_ ? $_->as_HTML : $_ } $tree->content_list ); |
101
|
|
|
|
|
|
|
} else { |
102
|
2
|
|
|
|
|
38
|
$ret = $tree->as_HTML; |
103
|
|
|
|
|
|
|
} |
104
|
5
|
|
|
|
|
1529
|
$tree->delete; |
105
|
5
|
|
|
|
|
367
|
return $ret; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |