| 1 | package Text::AutoLink; | ||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use 5.006; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use vars qw($VERSION); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use HTML::TreeBuilder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | use Module::Pluggable | ||||||||||||
| 8 | 3 | ▶ | require => 0, | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | search_path => 'Text::AutoLink::Plugin', | ||||||||||||
| 10 | sub_name => 'available_plugins', | ||||||||||||
| 11 | 3 | ; | |||||||||||
| 12 | |||||||||||||
| 13 | 3 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 3 | $VERSION = '0.04000' | |||||||||||
| 15 | } | ||||||||||||
| 16 | |||||||||||||
| 17 | sub new | ||||||||||||
| 18 | 5 | ▶ | { | ||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 19 | 5 | my $class = shift; | |||||||||||
| 20 | 5 | my %args = @_; | |||||||||||
| 21 | 5 | my $self = bless { | |||||||||||
| 22 | plugins => [], | ||||||||||||
| 23 | }, $class; | ||||||||||||
| 24 | |||||||||||||
| 25 | 5 | ▶ | $args{plugins} ||= [$class->available_plugins]; | ||||||||||
|
Condition100%2/2
$args{"plugins"} ||= [$class->available_plugins]
MC/DC100%1/1
$args{"plugins"} ||= [$class->available_plugins]
$args{"plugins"}
Truth table100%2/2
A
A= $args{"plugins"}
| |||||||||||||
| 26 | 5 | foreach my $p (@{$args{plugins}}) { | |||||||||||
| 27 | 18 | ▶ | if (! ref $p) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 17 | eval "require $p"; | |||||||||||
| 29 | 17 | ▶ | die if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 17 | $p = $p->new; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 18 | push @{$self->{plugins}}, $p; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 5 | return $self; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | sub plugins | ||||||||||||
| 40 | 16 | ▶ | { | ||||||||||
|
Subroutine
plugins: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 41 | 16 | my $self = shift; | |||||||||||
| 42 | 16 | ▶ | wantarray ? @{$self->{plugins}} : $self->{plugins}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | sub _parse | ||||||||||||
| 46 | 64 | ▶ | { | ||||||||||
|
Subroutine
_parse: called CC=7 SCAR=19.5
| |||||||||||||
| 47 | 64 | my $self = shift; | |||||||||||
| 48 | 64 | my $x = shift; | |||||||||||
| 49 | |||||||||||||
| 50 | 64 | ▶ | if ($x->attr('_tag') eq 'a') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 16 | return; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 48 | my @list = $x->content_list; | |||||||||||
| 55 | 48 | ▶ | for(my $i = 0; $i < @list; $i++) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 62 | my $c = $list[$i]; | |||||||||||
| 57 | 62 | ▶ | if (ref $c) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 48 | $self->_parse($c); | |||||||||||
| 59 | } else { | ||||||||||||
| 60 | 14 | foreach my $p ($self->plugins) { | |||||||||||
| 61 | 46 | ▶ | next unless $c; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 46 | ▶ | next unless $p->process(\$c); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | 11 | my $subtree = HTML::TreeBuilder->new_from_content($c); | |||||||||||
| 64 | 11 | $self->_parse($subtree); | |||||||||||
| 65 | 11 | $x->splice_content($i, 1, $subtree); | |||||||||||
| 66 | } | ||||||||||||
| 67 | } | ||||||||||||
| 68 | } | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | sub parse_file | ||||||||||||
| 72 | 0 | ▶ | { | ||||||||||
|
Subroutine
parse_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 73 | 0 | my $self = shift; | |||||||||||
| 74 | 0 | my $file = shift; | |||||||||||
| 75 | 0 | ▶ | open my $fh, "<", $file or die "Failed to open file $file: $!"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 0 | $self->parse_fh($fh); | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | sub parse_fh | ||||||||||||
| 80 | 0 | ▶ | { | ||||||||||
|
Subroutine
parse_fh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 81 | 0 | my $self = shift; | |||||||||||
| 82 | 0 | my $fh = shift; | |||||||||||
| 83 | 0 | my $text = join '', <$fh>; | |||||||||||
| 84 | 0 | return $self->parse_string($text); | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | sub parse_string | ||||||||||||
| 88 | 5 | ▶ | { | ||||||||||
|
Subroutine
parse_string: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 89 | 5 | my $self = shift; | |||||||||||
| 90 | 5 | my $string = shift; | |||||||||||
| 91 | |||||||||||||
| 92 | 5 | my $ret; | |||||||||||
| 93 | 5 | my $tree = HTML::TreeBuilder->new_from_content($string); | |||||||||||
| 94 | 5 | $self->_parse($tree); | |||||||||||
| 95 | 5 | foreach my $i ($tree->look_down(_implicit => 1)) { | |||||||||||
| 96 | 23 | ▶ | $i->replace_with_content if $i->parent; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | } | ||||||||||||
| 98 | 5 | ▶ | if ($tree->implicit) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | $ret = join('', | ||||||||||||
| 100 | 3 | ▶ | map { ref $_ ? $_->as_HTML : $_ } $tree->content_list ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | } else { | ||||||||||||
| 102 | 2 | $ret = $tree->as_HTML; | |||||||||||
| 103 | } | ||||||||||||
| 104 | 5 | $tree->delete; | |||||||||||
| 105 | 5 | return $ret; | |||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | 3 | 1; | |||||||||||
| 109 | |||||||||||||
| 110 | __END__ | ||||||||||||