dbMan/Extension/SQLOutputMarkdown.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 70 CC 5 SCAR 17.9
CC
5
Cov
0%
done
12.0
handle_action
12.0
IDENTIFICATION
2.0
CRAP 6.0
1 package DBIx::dbMan::Extension::SQLOutputMarkdown;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5 use utf8;
6 use Text::FormatTable;
7 use Term::ANSIColor;
8  
9 our $VERSION = '0.01';
10  
11 1;
12  
13 sub IDENTIFICATION { return "000001-000100-000001"; }
14  
15 sub preference { return 0; }
16  
17 sub known_actions { return [ qw/SQL_OUTPUT/ ]; }
18  
19 sub init {
20 my $obj = shift;
21 $obj->{-mempool}->register('output_format','markdown');
22 }
23  
24 sub done {
25 my $obj = shift;
26 $obj->{-mempool}->deregister('output_format','markdown');
27 if ($obj->{-mempool}->get('output_format') eq 'markdown') {
28 my @all_formats = $obj->{-mempool}->get_register('output_format');
29 $obj->{-mempool}->set('output_format', @all_formats ? $all_formats[0] : '');
30 }
31 }
32
33 sub handle_action {
34 my ($obj,%action) = @_;
35  
36 $action{processed} = 1;
37 if ($action{action} eq 'SQL_OUTPUT') { # table is standard fallback
38 if ($obj->{-mempool}->get('output_format') eq 'markdown') {
39 my $output = '';
40 $output .= '| ' . ( join ' | ', @{ $action{ fieldnames } } ) . ' |' . "\n";
41 $output .= '| ' . ( join ' | ', map { '---' } @{ $action{ fieldnames } } ) . ' |' . "\n";
42  
43 for ( @{ $action{ result } } ) {
44 $output .= '| ' . ( join ' | ', @$_ ) . ' |' . "\n";
45 }
46  
47 $action{action} = 'OUTPUT';
48 $action{output} = $output;
49 delete $action{processed};
50 }
51 }
52  
53 return %action;
54 }