lib/Treex/Core/DocumentReader/ZoneReader.pm

filter: Statementstmt 34.7% 24 / 69 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 4 / 12 Podpod 0.0% 0 / 7 totaltotal 23.3% 28 / 120 CC 17 SCAR 37.6
CC
17
Cov
24%
next_document_text
110.0
_open_file
12.0
zone_label
6.0
CRAP 42.9
« lib/Treex/Block/Util/Eval.pm ↑ Summary lib/Treex/Block/Util/DefinedAttr.pm »
1 package Treex::Core::DocumentReader::ZoneReader;
2 {
3 1 $Treex::Core::DocumentReader::ZoneReader::VERSION = '0.08633_1';
4 }
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 has language => (
11 is => 'ro',
12 isa => 'Treex::Type::LangCode',
13 required => 1,
14 );
15  
16 1 has selector => ( isa => 'Treex::Type::Selector', is => 'ro', default => '' );
17  
18 sub zone_label {
19 0 ▶ my ($self) = @_;
Subroutine zone_label: not called CC=2 SCAR=17.9
Pod undocumented
20 0 ▶ return $self->language if $self->selector eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->selector eq "" 0 0 0
21 0 return $self->language . '_' . $self->selector;
22 }
23  
24 1 has encoding => ( isa => 'Str', is => 'ro', default => 'utf8' );
25 1 has lines_per_doc => ( isa => 'Int', is => 'ro', default => 0 );
26 1 has merge_files => ( isa => 'Bool', is => 'ro', default => 0 );
27 1 has is_one_doc_per_file => (
28 is => 'rw',
29 isa => 'Bool',
30 default => 1,
31 );
32  
33 1 has filenames => (
34 isa => 'ArrayRef[Str]',
35 is => 'ro',
36 required => 1,
37 );
38  
39 1 has _file_number => (
40 is => 'rw',
41 isa => 'Int',
42 default => 0,
43 documentation => 'Number of input files loaded so far.',
44 );
45  
46 1 has _current_fh => ( is => 'rw' );
47  
48 sub BUILD {
49 0 ▶ my ($self) = @_;
Subroutine BUILD: not called CC=2 SCAR=17.9
Pod undocumented
50 0 ▶ if ( $self->lines_per_doc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lines_per_doc) 0 0 0
51 0 $self->set_is_one_doc_per_file(0);
52 }
53 0 return;
54 }
55  
56 sub restart {
57 0 ▶ my $self = shift;
Subroutine restart: not called CC=1 SCAR=6.9
Pod undocumented
58 0 $self->_set_file_number(0);
59 0 return;
60 }
61  
62 sub next_filename {
63 0 ▶ my ($self) = @_;
Subroutine next_filename: not called CC=2 SCAR=17.9
Pod undocumented
64 0 my $file_number = $self->_file_number;
65 0 ▶ return if $file_number == @{ $self->filenames };
Branch: 1 branch
BranchTrueFalseTotal
if $file_number == @{$self->filenames;} 0 0 0
66 0 $self->_set_file_number( $file_number + 1 );
67 0 return $self->filenames->[$file_number];
68 }
69  
70 sub current_filename {
71 0 ▶ my ($self) = @_;
Subroutine current_filename: not called CC=2 SCAR=17.9
Pod undocumented
72 0 ▶ log_fatal "next_* method must be called before" if !$self->_file_number;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_file_number 0 0 0
73 0 return $self->filenames->[ $self->file_number - 1 ];
74 }
75  
76 sub _open_file {
77 0 ▶ my ( $self, $filename ) = @_;
Subroutine _open_file: not called CC=3 SCAR=24.8
78 0 ▶ return if !defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 0 0
79 0 my $F;
80 0 ▶ if ( $filename eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename eq '-') { } 0 0 0
81 0 $F = \*STDIN;
82 }
83 else {
84 0 open $F, '<:' . $self->encoding, $filename;
85 }
86 0 return $F;
87 }
88  
89 sub next_filehandle {
90 0 ▶ my ($self) = @_;
Subroutine next_filehandle: not called CC=2 SCAR=17.9
Pod undocumented
91 0 ▶ return $self->_open_file( $self->next_filename or return );
Condition0%0/2
$self->next_filename || (return)
l!l
00
MC/DC0%0/1
$self->next_filename || (return)
$self->next_filename
Truth table0%0/2
A
A= $self->next_filename
Aresult
11
00
92 }
93  
94 sub next_document_text {
95 0 ▶ my ($self) = @_;
Subroutine next_document_text: not called CC=10 SCAR=47.0
Pod undocumented
96 0 ▶ return read_file( $self->next_filehandle() or return ) if $self->is_one_doc_per_file;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_one_doc_per_file 0 0 0
Condition0%0/2
$self->next_filehandle || (return)
l!l
00
MC/DC0%0/1
$self->next_filehandle || (return)
$self->next_filehandle
Truth table0%0/2
A
A= $self->next_filehandle
Aresult
11
00
97  
98 0 my $FH = $self->_current_fh;
99 0 ▶ if ( !$FH ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($FH) 0 0 0
100 0 ▶ $FH = $self->next_filehandle() or return;
Branch: 1 branch
BranchTrueFalseTotal
$FH = $self->next_filehandle or return 0 0 0
101 0 $self->_set_current_fh($FH);
102 }
103  
104 0 my $text = '';
105 LINE:
106 0 for my $line ( 1 .. $self->lines_per_doc ) {
107 0 ▶ while ( eof($FH) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eof $FH) 0 0 0
108 0 $FH = $self->next_filehandle();
109 0 ▶ if ( !$FH ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($FH) 0 0 0
110 0 ▶ return if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 0 0 0
111 0 return $text;
112 }
113 0 $self->_set_current_fh($FH);
114 0 ▶ last LINE if !$self->merge_files;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->merge_files 0 0 0
115 }
116 0 $text .= <$FH>;
117 }
118 0 return $text;
119 }
120  
121 1 1;
« lib/Treex/Block/Util/Eval.pm ↑ Summary lib/Treex/Block/Util/DefinedAttr.pm »