Treex/Block/Write/Treex.pm

filter: Statementstmt 53.6% 22 / 41 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod n/a totaltotal 47.2% 26 / 55 CC 4 SCAR 16.3
CC
4
Cov
47%
__ANON__
12.0
__ANON__
6.0
__ANON__
2.0
CRAP 5.1
« Treex/Core/TredView/LineStyles.pm ↑ Summary Treex/Core/Phrase/NTerm.pm »
1 package Treex::Block::Write::Treex;
2 1 $Treex::Block::Write::Treex::VERSION = '2.20151210';
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 File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 extends 'Treex::Block::Write::BaseWriter';
9  
10 1 has '+extension' => ( default => '.treex' );
11 1 has '+compress' => ( default => 1 );
12  
13 1 has storable => (
14 is => 'rw',
15 isa => 'Bool',
16 documentation => 'Use the Storable module (instead of Treex::PML) for storing into .streex files. Defaults to document->storable.'
17 );
18  
19 # HACKS: Treex::PML::Document->save() cannot take filehandle
20  
21 # Allow writing to STDOUT
22 override '_get_filename' => sub {
23  
24 0 ▶ my $filename = super();
Subroutine __ANON__: not called CC=2 SCAR=17.9
25  
26 0 ▶ if ( $filename eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename eq "-") 0 0 0
27 0 $filename = '/dev/stdout';
28 }
29 0 return $filename;
30 1 };
31  
32 # If a gzipped file is opened first, the header won't be correct
33 override '_open_file_handle' => sub {
34 0 ▶ my ( $self, $filename ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
35
36 # This line is the only one needed from super() implementation
37 0 mkpath( dirname($filename) );
38 0 return;
39 1 };
40  
41 override '_document_extension' => sub {
42 0 ▶ my ( $self, $document ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
43  
44 0 my $storable = $self->storable;
45 0 ▶ if ( not defined $storable ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $storable) 0 0 0
46 0 $storable = $document->storable;
47 }
48  
49 0 ▶ if ($storable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($storable) { } 0 0 0
50 0 return '.streex';
51 }
52 else {
53 0 return super;
54 }
55 1 };
56  
57 override '_do_process_document' => sub {
58  
59 0 ▶ my ( $self, $document ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
60  
61 0 my $filename = $self->_last_filename;
62 0 $document->set_filename($filename);
63 0 $document->save($filename);
64 0 return 1;
65 1 };
66  
67 1 1;
68  
69 __END__
70  
71 =pod
72  
73 =encoding utf-8
74  
75 =head1 NAME
76  
77 Treex::Block::Write::Treex
78  
79 =head1 VERSION
80  
81 version 2.20151210
82  
83 =head1 DESCRIPTION
84  
85 Document writer for the Treex file format (C<*.treex>),
86 which is actually a PML instance which is an XML-based format.
87  
88 For a list of possible attributes, see
89 L<BaseWriter|Treex::Block::Write::BaseWriter>.
90  
91 =head1 METHODS
92  
93 =over
94  
95 =item process_document
96  
97 Saves the document.
98  
99 =back
100  
101 =head1 AUTHORS
102  
103 Martin Popel <popel@ufal.mff.cuni.cz>
104  
105 Ondřej Dušek <odusek@ufal.mff.cuni.cz>
106  
107 =head1 COPYRIGHT AND LICENSE
108  
109 Copyright © 2011-2012 by Institute of Formal and Applied Linguistics, Charles University in Prague
110  
111 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Core/TredView/LineStyles.pm ↑ Summary Treex/Core/Phrase/NTerm.pm »