TOC/HTML.pm

filter: Statementstmt 50.6% 40 / 79 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 45.0% 9 / 20 Podpod 75.0% 3 / 4 totaltotal 39.6% 52 / 131 CC 9 SCAR 27.5
CC
9
Cov
40%
BUILD
56.0
html_for_document
6.0
html_for_document_body
6.0
CRAP 15.7
« TOC/OutputHandler/HTML.pm ↑ Summary TOC/InputHandler/HTML.pm »
1 package Text::TOC::HTML;
2 {
3 2 $Text::TOC::HTML::VERSION = '0.10';
4 }
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use namespace::autoclean 0.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Text::TOC::InputHandler::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Text::TOC::OutputHandler::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Text::TOC::Types qw( Filter HashRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 has _input_handler => (
19 is => 'ro',
20 isa => 'Text::TOC::InputHandler::HTML',
21 init_arg => undef,
22 lazy => 1,
23 builder => '_build_input_handler',
24 handles => [ 'add_file' ],
25 );
26  
27 2 has _input_handler_args => (
28 is => 'rw',
29 isa => HashRef,
30 init_arg => undef,
31 );
32  
33 2 has _output_handler => (
34 is => 'ro',
35 isa => 'Text::TOC::OutputHandler::HTML',
36 init_arg => undef,
37 lazy => 1,
38 builder => '_build_output_handler',
39 );
40  
41 2 has _output_handler_args => (
42 is => 'rw',
43 isa => HashRef,
44 init_arg => undef,
45 );
46  
47 2 has _toc_document => (
48 is => 'ro',
49 isa => 'HTML::DOM',
50 init_arg => undef,
51 lazy => 1,
52 builder => '_build_toc_document',
53 );
54  
55 0 ▶my $single_filter = sub { $_[0]->tagName() =~ /^h[2-4]$/i };
Subroutine __ANON__: not called CC=1 SCAR=1.2
56 0 ▶my $multi_filter = sub { $_[0]->tagName() =~ /^h[1-4]$/i };
Subroutine __ANON__: not called CC=1 SCAR=1.2
57  
58 0 ▶my $single_link_generator = sub { return q{#} . $_[0]->anchor_name() };
Subroutine __ANON__: not called CC=1 SCAR=1.2
59 0 ▶my $multi_link_generator = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 return 'file://' . $_[0]->source_file() . q{#} . $_[0]->anchor_name();
61 2 };
62  
63 0 ▶sub BUILD {
Subroutine BUILD: not called CC=7 SCAR=40.3
Pod undocumented
64 0 my $self = shift;
65 0 my $p = shift;
66  
67 0 my %ih;
68 my %oh;
69  
70 0 ▶ if ( delete $p->{multi} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $p->{'multi'}) { } 0 0 0
71 0 ▶ $ih{filter} = delete $p->{filter} || $multi_filter;
Condition0%0/3
delete $p->{'filter'} || $multi_filter
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $p->{'filter'} || $multi_filter
delete $p->{'filter'} $multi_filter
Truth table0%0/3
A || B
A= delete $p->{'filter'}B= $multi_filter
ABresult
1X1
011
000
72 0 ▶ $oh{link_generator} = delete $p->{link_generator} || $multi_link_generator;
Condition0%0/3
delete $p->{'link_generator'} || $multi_link_generator
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $p->{'link_generator'} || $multi_link_generator
delete $p->{'link_generator'} $multi_link_generator
Truth table0%0/3
A || B
A= delete $p->{'link_generator'}B= $multi_link_generator
ABresult
1X1
011
000
73 }
74 else {
75 0 ▶ $ih{filter} = delete $p->{filter} || $single_filter;
Condition0%0/3
delete $p->{'filter'} || $single_filter
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $p->{'filter'} || $single_filter
delete $p->{'filter'} $single_filter
Truth table0%0/3
A || B
A= delete $p->{'filter'}B= $single_filter
ABresult
1X1
011
000
76 0 ▶ $oh{link_generator} = delete $p->{link_generator} || $single_link_generator;
Condition0%0/3
delete $p->{'link_generator'} || $single_link_generator
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $p->{'link_generator'} || $single_link_generator
delete $p->{'link_generator'} $single_link_generator
Truth table0%0/3
A || B
A= delete $p->{'link_generator'}B= $single_link_generator
ABresult
1X1
011
000
77 }
78  
79 $oh{style} = delete $p->{style}
80 0 ▶ if exists $p->{style};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"style"} 0 0 0
81  
82 0 $self->_set_input_handler_args(\%ih);
83 0 $self->_set_output_handler_args(\%oh);
84  
85 0 return;
86 }
87  
88 0 ▶sub _build_input_handler {
Subroutine _build_input_handler: not called CC=1 SCAR=6.9
89 0 my $self = shift;
90  
91 0 return Text::TOC::InputHandler::HTML->new( $self->_input_handler_args() );
92 }
93  
94 0 ▶sub _build_output_handler {
Subroutine _build_output_handler: not called CC=1 SCAR=6.9
95 0 my $self = shift;
96  
97 0 return Text::TOC::OutputHandler::HTML->new(
98 $self->_output_handler_args() );
99 }
100  
101 0 ▶sub html_for_toc {
Subroutine html_for_toc: not called CC=1 SCAR=6.9
Pod documented
102 0 my $self = shift;
103  
104 0 return $self->_toc_document()->innerHTML();
105 }
106  
107 0 ▶sub _build_toc_document {
Subroutine _build_toc_document: not called CC=1 SCAR=6.9
108 0 my $self = shift;
109  
110 0 return $self->_output_handler()
111 ->process_node_list( $self->_input_handler()->nodes() );
112 }
113  
114 0 ▶sub html_for_document {
Subroutine html_for_document: not called CC=2 SCAR=17.9
Pod documented
115 0 my $self = shift;
116 0 my $path = shift;
117  
118 # Building this also updates the original document with the target nodes.
119 0 $self->_toc_document();
120  
121 0 my $doc = $self->_input_handler()->document($path);
122  
123 0 ▶ return unless $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc 0 0 0
124  
125 0 return $doc->innerHTML();
126 }
127  
128 0 ▶sub html_for_document_body {
Subroutine html_for_document_body: not called CC=2 SCAR=17.9
Pod documented
129 0 my $self = shift;
130 0 my $path = shift;
131  
132 # Building this also updates the original document with the target nodes.
133 0 $self->_toc_document();
134  
135 0 my $doc = $self->_input_handler()->document($path);
136  
137 0 ▶ return unless $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc 0 0 0
138  
139 0 my $html = $doc->innerHTML();
140  
141 0 $html =~ s{.+<body>}{}s;
142 0 $html =~ s{</body>.+}{}s;
143  
144 0 return $html;
145 }
146  
147 2 __PACKAGE__->meta()->make_immutable();
148  
149 2 1;
150  
151 # ABSTRACT: Build a table contents for one or more HTML documents
152  
153  
154 __END__
« TOC/OutputHandler/HTML.pm ↑ Summary TOC/InputHandler/HTML.pm »