dbMan/Extension/Clipboard.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 82 CC 6 SCAR 30.9
CC
6
Cov
0%
handle_action
42.0
IDENTIFICATION
2.0
preference
2.0
CRAP 22.0
1 package DBIx::dbMan::Extension::Clipboard;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5  
6 our $VERSION = '0.06';
7  
8 1;
9  
10 sub IDENTIFICATION { return "000001-000065-000006"; }
11  
12 sub preference { return 80; }
13  
14 sub known_actions { return [ qw/SQL_RESULT/ ]; }
15  
16 sub init {
17 my $obj = shift;
18  
19 $obj->{prompt_title} = $obj->{-config}->prompt_clipboard || '[clip]';
20 }
21  
22 sub handle_action {
23 my ($obj,%action) = @_;
24  
25 $action{processed} = 1;
26 if ($action{action} eq 'SQL_RESULT' and $action{copy_to_clipboard} and ref $action{result} eq 'ARRAY') {
27 delete $action{copy_to_clipboard};
28 if ($action{union_clipboard}) {
29 my $clip = $obj->{-mempool}->get('clipboard');
30 if (exists $clip->{-result}) {
31 if (scalar @{$action{result}->[0]} != scalar @{$clip->{-result}->[0]}) {
32 $action{output_info} = "Cannot union copy results with different number of columns.\n";
33 } else {
34 my @res = map { [ @$_ ] } @{$action{result}};
35 $clip->{-result} = [ @{$clip->{-result}}, @res ];
36 $obj->{-mempool}->set('clipboard',$clip);
37 $action{output_info} = "Union copy to clipboard done.\n";
38 }
39 } else {
40 delete $action{union_clipboard};
41 }
42 }
43 unless ($action{union_clipboard}) {
44 my $res; $res = [ map { [ @$_ ] } @{$action{result}} ];
45 $obj->{-mempool}->set('clipboard',{ -result => $res, -fieldnames => $action{fieldnames}, -fieldtypes => $action{fieldtypes}});
46 $action{output_info} = "Copy to clipboard done.\n";
47 }
48 delete $action{processed};
49 $obj->{-interface}->prompt($action{clipboard_prompt_num},$obj->{prompt_title});
50 $obj->{-interface}->rebuild_menu();
51 }
52  
53 return %action;
54 }