| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 79 | 0 | my $F; | |||||||||||||||||||
| 80 | 0 | ▶ | if ( $filename eq '-' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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)
MC/DC0%0/1
$self->next_filename || (return)
$self->next_filename
Truth table0%0/2
A
A= $self->next_filename
| |||||||||||||||||||||
| 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
Condition0%0/2
$self->next_filehandle || (return)
MC/DC0%0/1
$self->next_filehandle || (return)
$self->next_filehandle
Truth table0%0/2
A
A= $self->next_filehandle
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | my $FH = $self->_current_fh; | |||||||||||||||||||
| 99 | 0 | ▶ | if ( !$FH ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 0 | ▶ | $FH = $self->next_filehandle() or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 108 | 0 | $FH = $self->next_filehandle(); | |||||||||||||||||||
| 109 | 0 | ▶ | if ( !$FH ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 0 | ▶ | return if $text eq ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | return $text; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | 0 | $self->_set_current_fh($FH); | |||||||||||||||||||
| 114 | 0 | ▶ | last LINE if !$self->merge_files; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | 0 | $text .= <$FH>; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | 0 | return $text; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||