line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
package DBIx::DataModel::Schema::ResultAs::Tsv; |
3
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
4
|
1
|
|
|
1
|
|
588
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp::Clan qw[^(DBIx::DataModel::|SQL::Abstract)]; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
110
|
use Scalar::Util 1.07 qw/openhandle/; |
|
1
|
|
|
|
|
40
|
|
|
1
|
|
|
|
|
71
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
13
|
use parent 'DBIx::DataModel::Schema::ResultAs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
65
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
0
|
3
|
my ($class, $file) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
50
|
|
|
|
3
|
croak "-result_as => [Tsv => ...] ... target file is missing" if !$file; |
17
|
1
|
|
|
|
|
5
|
return bless {file => $file}, $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub get_result { |
22
|
1
|
|
|
1
|
1
|
3
|
my ($self, $statement) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# open file |
25
|
1
|
|
|
|
|
2
|
my $fh; |
26
|
1
|
50
|
|
|
|
10
|
if (openhandle $self->{file}) { |
27
|
1
|
|
|
|
|
3
|
$fh = $self->{file}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
|
|
|
|
|
|
open $fh, ">", $self->{file} |
31
|
0
|
0
|
|
|
|
0
|
or croak "open $self->{file} for writing : $!"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# get data |
35
|
1
|
|
|
|
|
3
|
$statement->execute; |
36
|
1
|
|
|
|
|
36
|
$statement->make_fast; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# activate tsv mode by setting output field and record separators |
39
|
1
|
|
|
|
|
5
|
local $\ = "\n"; |
40
|
1
|
|
|
|
|
2
|
local $, = "\t"; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# print header row |
43
|
1
|
|
|
1
|
|
491
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
233
|
|
44
|
1
|
|
|
|
|
4
|
my @headers = $statement->headers; |
45
|
1
|
|
|
|
|
29
|
print $fh @headers; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# print data rows |
48
|
1
|
|
|
|
|
4
|
while (my $row = $statement->next) { |
49
|
3
|
|
|
|
|
5
|
my @data = @{$row}{@headers}; |
|
3
|
|
|
|
|
9
|
|
50
|
3
|
|
|
|
|
13
|
s/[\t\n]+/ /g foreach @data; |
51
|
3
|
|
|
|
|
15
|
print $fh @data; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# cleanup and return |
55
|
1
|
|
|
|
|
4
|
$statement->finish; |
56
|
1
|
|
|
|
|
34
|
return $self->{file}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |