Dump.pm

filter: Statementstmt 24.6% 20 / 81 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 2 totaltotal 20.5% 23 / 112 CC 11 SCAR 33.7
CC
11
Cov
21%
__ANON__
56.0
__ANON__
30.0
new
2.0
CRAP 29.1
↑ Summary sample.pl »
1 package DBIx::Dump;
2
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 require Exporter;
8 #use AutoLoader qw(AUTOLOAD);
9
10 1 our @ISA = qw(Exporter);
11
12 # Items to export into callers namespace by default. Note: do not export
13 # names by default without a very good reason. Use EXPORT_OK instead.
14 # Do not simply export all your public functions/methods/constants.
15
16 # This allows declaration use DBIx::Dump ':all';
17 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 # will save memory.
19 1 our %EXPORT_TAGS = ( 'all' => [ qw(
20
21 ) ] );
22
23 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24
25 1 our @EXPORT = qw(
26
27 );
28 1 our $VERSION = '0.04';
29
30 sub new
31 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my $self = shift;
33 0 my $attr = {@_};
34
35 0 bless $attr, $self;
36 }
37
38 ### Must put all anonymous subs before the %formats hash and dump sub.
39
40 0 ▶my $excel = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
41
42 0 my $self = shift;
43
44 0 $self->{excelFormat} = undef;
45
46 0 require Spreadsheet::WriteExcel;
47
48 0 ▶ my $workbook = $self->{Generator} || Spreadsheet::WriteExcel->new($self->{output});
Condition0%0/3
$self->{'Generator'} || 'Spreadsheet::WriteExcel'->new($self->{'output'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'Generator'} || 'Spreadsheet::WriteExcel'->new($self->{'output'})
$self->{'Generator'} 'Spreadsheet::WriteExcel'->new($self->{'output'})
Truth table0%0/3
A || B
A= $self->{'Generator'}B= 'Spreadsheet::WriteExcel'->new($self->{'output'})
ABresult
1X1
011
000
49 0 $self->{Generator} = $workbook;
50
51 0 my $worksheet = $workbook->addworksheet();
52
53 0 my $col = 0; my $row = 0;
54
55 0 my $cols = $self->{sth}->{NAME_uc};
56
57 0 foreach my $data (@$cols)
58 {
59 0 ▶ $self->{eventHandler}->($self, \$data, $cols->[$col], 1) if $self->{eventHandler};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eventHandler"} 0 0 0
60 0 $worksheet->write(0, $col, $data, $self->{excelFormat});
61 0 $col++;
62 }
63 0 $row++;
64 0 $col = 0;
65
66 0 ▶ while (my @data = $self->{sth}->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (my(@data) = $self->{"sth"}->fetchrow_array) 0 0 0
67 {
68 0 foreach my $data (@data)
69 {
70 0 ▶ $self->{eventHandler}->($self, \$data, $cols->[$col], $row+1) if $self->{eventHandler};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eventHandler"} 0 0 0
71 0 $worksheet->write($row, $col, $data, $self->{excelFormat});
72 0 $col++;
73 }
74 0 $col = 0;
75 0 $row++;
76 }
77 0 $row = 0;
78 0 _clean_up($self);
79 1 };
80
81 0 ▶my $csv = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
82
83 0 my $self = shift;
84
85 0 require Text::CSV_XS;
86 0 require IO::File;
87
88 0 my $fh = IO::File->new("$self->{output}", "w");
89
90 0 ▶ my $csvobj = $self->{Generator} || Text::CSV_XS->new({
Condition0%0/3
$self->{'Generator'} || 'Text::CSV_XS'->new({'quote_char', '"', 'escape_char', '"', 'sep_char', ',', 'binary', 0})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'Generator'} || 'Text::CSV_XS'->new({'quote_char', '"', 'escape_char', '"', 'sep_char', ',', 'binary', 0})
$self->{'Generator'} 'Text::CSV_XS'->new({'quote_char', '"', 'escape_char', '"', 'sep_char', ',', 'binary', 0})
Truth table0%0/3
A || B
A= $self->{'Generator'}B= 'Text::CSV_XS'->new({'quote_char', '"', 'escape_char', '"', 'sep_char', ',', 'binary', 0})
ABresult
1X1
011
000
91 'quote_char' => '"',
92 'escape_char' => '"',
93 'sep_char' => ',',
94 'binary' => 0
95 });
96
97 0 $self->{Generator} = $csvobj;
98
99 0 my $cols = $self->{sth}->{NAME_uc};
100 0 $csvobj->combine(@$cols);
101 0 print $fh $csvobj->string(), "\n";
102
103 0 my $row = 0;
104 0 ▶ while (my @data = $self->{sth}->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (my(@data) = $self->{"sth"}->fetchrow_array) 0 0 0
105 {
106 0 my $col = 0;
107 0 foreach my $data (@data)
108 {
109 0 ▶ $self->{eventHandler}->($self, \$data, $cols->[$col], $row+1) if $self->{eventHandler};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eventHandler"} 0 0 0
110 0 $col++;
111 }
112 0 $csvobj->combine(@data);
113 0 print $fh $csvobj->string(), "\n";
114 0 $row++;
115 }
116 0 $row = 0;
117 0 $fh->close();
118 0 _clean_up($self);
119 1 };
120
121
122 #### This is experimental, don't use!!!!! ####
123 0 ▶my $iQuery = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
124
125 0 my $self = shift;
126
127 0 require IO::File;
128
129 0 my $fh = IO::File->new("$self->{output}", "w");
130
131 0 my $stmt = $self->{sth}->{Statement};
132 0 $stmt =~ /from\s+(.*)\s+(where|order by|group by)*/i;
133 0 my @tables;
134 1 };
135 ###############################################
136
137 1 my %formats = (
138 'excel' => $excel,
139 'csv' => $csv,
140 'iQuery' => $iQuery
141 );
142
143 sub dump
144 0 ▶{
Subroutine dump: not called CC=1 SCAR=6.9
Pod undocumented
145 0 my $self = shift;
146 0 my $attr = {@_};
147 0 $self = {%$self, %$attr};
148
149 0 $formats{$self->{'format'}}->($self);
150 }
151
152 sub _clean_up
153 0 ▶{
Subroutine _clean_up: not called CC=1 SCAR=6.9
154 0 my $self = shift;
155
156 0 $self->{Generator} = undef;
157 0 $self->{excelFormat} = undef;
158 }
159
160 # Preloaded methods go here.
161
162 # Autoload methods go after =cut, and are processed by the autosplit program.
163
164 1 1;
165 __END__
↑ Summary sample.pl »