Treex/Core/DocumentReader/ZoneReader.pm

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