TOC/Role/InputHandler.pm

filter: Statementstmt 74.4% 35 / 47 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 1 totaltotal 67.6% 44 / 65 CC 3 SCAR 12.2
CC
3
Cov
69%
add_file
12.0
__ANON__
2.0
__ANON__
2.0
CRAP 3.4
« TOC/InputHandler/HTML.pm ↑ Summary TOC/Filter/Anon.pm »
1 package Text::TOC::Role::InputHandler;
2 {
3 2 $Text::TOC::Role::InputHandler::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;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use File::Slurp qw( read_file );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Path::Class qw( file );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Text::TOC::Types qw( ArrayRef File Filter HashRef Node Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use MooseX::Params::Validate qw( validated_list );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 requires '_process_file';
19  
20 has _files => (
21 traits => ['Array'],
22 is => 'bare',
23 isa => ArrayRef [File],
24 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 2 handles => {
26 _add_file => 'push',
27 files => 'elements',
28 },
29 );
30  
31 has _documents => (
32 is => 'bare',
33 isa => 'Tie::IxHash',
34 0 ▶ default => sub { Tie::IxHash->new() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 2 handles => {
36 _add_document => 'STORE',
37 documents => 'Values',
38 document => 'FETCH',
39 },
40 );
41  
42 2 has _filter => (
43 is => 'ro',
44 isa => Filter,
45 coerce => 1,
46 init_arg => 'filter',
47 );
48  
49 has nodes => (
50 traits => ['Array'],
51 is => 'ro',
52 isa => ArrayRef [Node],
53 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 2 handles => {
55 _add_node => 'push',
56 },
57 );
58  
59 0 ▶sub add_file {
Subroutine add_file: not called CC=3 SCAR=24.8
Pod undocumented
60 0 my $self = shift;
61 0 my ( $file, $content ) = validated_list(
62 \@_,
63 file => { isa => File, coerce => 1 },
64 content => { isa => Str, optional => 1 },
65 );
66  
67 0 $self->_add_file($file);
68  
69 0 ▶ unless ( defined $content ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content) 0 0 0
70 0 ▶ die "No such file: $file" unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
71 0 $content = read_file( $file->stringify() );
72 }
73  
74 0 my $document = $self->_process_file( $file, $content );
75  
76 0 $self->_add_document( $file->stringify() => $document );
77  
78 0 return;
79 }
80  
81 2 1;
82  
83 # ABSTRACT: A role for input handlers
84  
85  
86 __END__
« TOC/InputHandler/HTML.pm ↑ Summary TOC/Filter/Anon.pm »