lib/Treex/Block/Write/Treex.pm

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