| 1 | package Treex::Block::Read::BaseTextReader; | ||||||||||||||||||||||||||||
| 2 | 5 | $Treex::Block::Read::BaseTextReader::VERSION = '2.20210102'; | |||||||||||||||||||||||||||
| 3 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | extends 'Treex::Block::Read::BaseReader'; | |||||||||||||||||||||||||||
| 6 | #use File::Slurp 9999; | ||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use PerlIO::via::gzip; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # By default read from STDIN | ||||||||||||||||||||||||||||
| 10 | 5 | has '+from' => ( | |||||||||||||||||||||||||||
| 11 | default => '-', | ||||||||||||||||||||||||||||
| 12 | handles => [qw(current_filename current_filehandle file_number _set_file_number next_filehandle)], | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | has lines_per_doc => ( isa => 'Int', is => 'ro', default => 0 ); | |||||||||||||||||||||||||||
| 16 | 5 | has merge_files => ( isa => 'Bool', is => 'ro', default => 0 ); | |||||||||||||||||||||||||||
| 17 | 5 | has encoding => ( isa => 'Str', is => 'ro', default => 'utf8' ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||
| 21 | 8 | ▶ | if ( $self->lines_per_doc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | $self->set_is_one_doc_per_file(0); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 8 | ▶ | if ($self->encoding ne 'utf8'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | $self->from->set_encoding($self->encoding); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 8 | return; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | sub next_document_text { | ||||||||||||||||||||||||||
|
Subroutine
next_document_text: called CC=6 SCAR=32.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 32 | 2 | ▶ | if ( $self->is_one_doc_per_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 2 | return $self->from->next_file_text(); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $text = ''; | |||||||||||||||||||||||||||
| 37 | LINE: | ||||||||||||||||||||||||||||
| 38 | 0 | for my $line ( 1 .. $self->lines_per_doc ) { | |||||||||||||||||||||||||||
| 39 | 0 | $line = $self->from->next_line(); | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (!defined $line){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return if $text eq '' && !$self->from->has_next_file(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$text eq "" and not $self->from->has_next_file
MC/DC0%0/2
$text eq "" and not $self->from->has_next_file
$text eq ""
not $self->from->has_next_file
Truth table0%0/3
A and not(B)
A= $text eq ""B= not $self->from->has_next_file
| |||||||||||||||||||||||||||||
| 42 | 0 | last LINE; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $text .= $line; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 0 | return $text; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 5 | 1; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||