| 1 | package Treex::Block::Write::BaseTextWriter; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | $Treex::Block::Write::BaseTextWriter::VERSION = '2.20210102'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Encode 'decode'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | extends 'Treex::Block::Write::BaseWriter'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | has encoding => ( | |||||||||||||||||||||||||||||||||||||||||
| 11 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | default => 'utf8', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | documentation => 'Output encoding. \'utf8\' by default.', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | has '+to' => ( | |||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | builder => '_build_to', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | lazy_build => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | has '+compress' => ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Set the right text encoding when opening a handle. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | around '_open_file_handle' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my ( $orig, $self, $filename ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # actually open the file handle | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $handle = $self->$orig($filename); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # set the right encoding | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | binmode( $handle, ':' . $self->encoding ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | return $handle; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # Default to standard output if no output file is set. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub _build_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_to: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ( !defined( $self->path ) && !defined( $self->file_stem ) && !defined( $self->substitute ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $self->path or defined $self->file_stem or defined $self->substitute
defined $self->path or defined $self->file_stem
MC/DC0%0/3
defined $self->path or defined $self->file_stem or defined $self->substitute
defined $self->path
defined $self->file_stem
defined $self->substitute
Truth table25%1/4
A or B or C
A= defined $self->pathB= defined $self->file_stemC= defined $self->substitute
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | return '-'; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # Append everything to one file if the 'to' parameter is set just to one file. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | override '_get_next_filename' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | return $self->to if ( $self->to !~ m/[ ,]/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return super(); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub _do_before_process { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do_before_process: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my ($self, $document) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | # allow header printing (in overrides) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $self->print_header($document); | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | sub _do_after_process { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do_after_process: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | my ($self, $document) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # allow footer printing (in overrides) | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $self->print_footer($document); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub print_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_header: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my ( $self, $document ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub print_footer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_footer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my ( $self, $document ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||||||||