dbMan/Extension/SQLOutputPlain.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 77 CC 6 SCAR 22.9
CC
6
Cov
0%
handle_action
20.0
done
12.0
IDENTIFICATION
2.0
CRAP 9.8
1 package DBIx::dbMan::Extension::SQLOutputPlain;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5  
6 our $VERSION = '0.09';
7  
8 1;
9  
10 sub IDENTIFICATION { return "000001-000027-000009"; }
11  
12 sub preference { return 0; }
13  
14 sub known_actions { return [ qw/SQL_OUTPUT/ ]; }
15  
16 sub init {
17 my $obj = shift;
18 $obj->{-mempool}->register('output_format','plain');
19 }
20
21 sub done {
22 my $obj = shift;
23 $obj->{-mempool}->deregister('output_format','plain');
24 if ($obj->{-mempool}->get('output_format') eq 'plain') {
25 my @all_formats = $obj->{-mempool}->get_register('output_format');
26 $obj->{-mempool}->set('output_format', @all_formats ? $all_formats[0] : '');
27 }
28 }
29
30 sub handle_action {
31 my ($obj,%action) = @_;
32  
33 $action{processed} = 1;
34 if ($action{action} eq 'SQL_OUTPUT') {
35 if ($obj->{-mempool}->get('output_format') eq 'plain') {
36 my $output = join ',',@{$action{fieldnames}};
37 $output .= "\n";
38 my @litp = (); my @lits = ();
39 for (@{$action{fieldtypes}}) {
40 my %th = %{$obj->{-dbi}->type_info($_)};
41 push @litp,$th{LITERAL_PREFIX}||'';
42 push @lits,$th{LITERAL_SUFFIX}||'';
43 }
44 for (@{$action{result}}) {
45 my @lp = @litp; my @ls = @lits;
46 $output .= join ',',map { my $lm = shift @lp; my $rm = shift @ls; defined($_)?"$lm$_$rm":"NULL" } @$_;
47 $output .= "\n";
48 }
49 $action{action} = 'OUTPUT';
50 $action{output} = $output;
51 delete $action{processed};
52 }
53 }
54  
55 return %action;
56 }