line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ########################################################################## #
|
4
|
|
|
|
|
|
|
# Title: Write stream to tabular file
|
5
|
|
|
|
|
|
|
# Creation date: 2007-03-05
|
6
|
|
|
|
|
|
|
# Author: Michael Zedeler
|
7
|
|
|
|
|
|
|
# Description: Writes data stream to file
|
8
|
|
|
|
|
|
|
# Data Stream class
|
9
|
|
|
|
|
|
|
# Transformer
|
10
|
|
|
|
|
|
|
# File: $Source: /data/cvs/lib/DSlib/lib/DS/Transformer/TabFileWriter.pm,v $
|
11
|
|
|
|
|
|
|
# Repository: kronhjorten
|
12
|
|
|
|
|
|
|
# State: $State: Exp $
|
13
|
|
|
|
|
|
|
# Documentation: inline
|
14
|
|
|
|
|
|
|
# Recepient: -
|
15
|
|
|
|
|
|
|
# ########################################################################## #
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package DS::Transformer::TabFileWriter;
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
1677
|
use base qw{ DS::Transformer::TabStreamWriter };
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
93
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
7
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
22
|
1
|
|
|
1
|
|
4
|
use Carp;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
23
|
1
|
|
|
1
|
|
5
|
use Carp::Assert;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
24
|
1
|
|
|
1
|
|
137
|
use IO::File;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
717
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our ($VERSION) = $DS::VERSION;
|
27
|
|
|
|
|
|
|
our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/;
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new {
|
31
|
1
|
|
|
1
|
1
|
17
|
my( $class, $filename, $field_order, $source, $target ) = @_;
|
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
my $self = undef;
|
34
|
1
|
|
|
|
|
5
|
assert(ref($filename) eq '', "Must be scalar but is " . ref( $filename ));
|
35
|
1
|
|
|
|
|
4
|
my $fh;
|
36
|
1
|
50
|
|
|
|
35
|
if( not defined( $filename ) ) {
|
|
|
50
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
$fh = new_tmpfile IO::File;
|
38
|
|
|
|
|
|
|
} elsif( not -f $filename ) {
|
39
|
1
|
|
|
|
|
9
|
$fh = new IO::File;
|
40
|
1
|
|
|
|
|
46
|
$fh->open( $filename, ">" );
|
41
|
|
|
|
|
|
|
} else {
|
42
|
0
|
|
|
|
|
0
|
croak("The file $filename already exists.");
|
43
|
|
|
|
|
|
|
}
|
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
127
|
if( $fh ) {
|
46
|
1
|
|
|
|
|
12
|
$self = $class->SUPER::new( $fh, $field_order, $source, $target );
|
47
|
1
|
|
|
|
|
4
|
$self->{filename} = $filename;
|
48
|
|
|
|
|
|
|
} else {
|
49
|
0
|
|
|
|
|
0
|
$self = undef;
|
50
|
|
|
|
|
|
|
}
|
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
4
|
return $self;
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub process {
|
56
|
12
|
|
|
12
|
1
|
14
|
my( $self, $row ) = @_;
|
57
|
|
|
|
|
|
|
|
58
|
12
|
|
|
|
|
13
|
my $result;
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# TODO (V3) Writing header this late is not a good thing. Move to post-attach, pre-process stage.
|
61
|
12
|
100
|
|
|
|
29
|
unless( $self->{header_written} ) {
|
62
|
1
|
|
|
|
|
3
|
$self->{header_written} = 1;
|
63
|
1
|
|
|
|
|
7
|
$self->write_header;
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
|
66
|
12
|
|
|
|
|
54
|
$result = $self->SUPER::process( $row );
|
67
|
12
|
100
|
|
|
|
39
|
$self->{fh}->close() unless $row;
|
68
|
|
|
|
|
|
|
|
69
|
12
|
|
|
|
|
107
|
return $result;
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1;
|