dbMan/Extension/CmdOutputToFile.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 68 CC 9 SCAR 26.2
CC
9
Cov
0%
cmdcomplete
30.0
handle_action
12.0
restart_complete
12.0
CRAP 13.8
1 package DBIx::dbMan::Extension::CmdOutputToFile;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5  
6 our $VERSION = '0.04';
7  
8 1;
9  
10 sub IDENTIFICATION { return "000001-000017-000004"; }
11  
12 sub preference { return 2000; }
13  
14 sub known_actions { return [ qw/COMMAND/ ]; }
15  
16 sub handle_action {
17 my ($obj,%action) = @_;
18  
19 $action{processed} = 1;
20 if ($action{action} eq 'COMMAND') {
21 if ($action{cmd} =~ s/^\\s(c)?\s*\((.*?)\)\s+//i) {
22 $action{output_save_copy} = $1;
23 $action{output_device} = $2;
24 delete $action{processed};
25 }
26 }
27  
28 return %action;
29 }
30  
31 sub cmdhelp {
32 return [
33 '\s(<file>) <command>' => 'Save output of <command> to <file>',
34 '\sc(<file>) <command>' => 'Save copy of output of <command> to <file>'
35 ];
36 }
37  
38  
39 sub restart_complete {
40 my ($obj,$text,$line,$start) = @_;
41 my %action = (action => 'LINE_COMPLETE', text => $text, line => $line,
42 start => $start);
43 do {
44 %action = $obj->{-core}->handle_action(%action);
45 } until ($action{processed});
46 return @{$action{list}} if ref $action{list} eq 'ARRAY';
47 return $action{list} if $action{list};
48 return ();
49 }
50  
51 sub cmdcomplete {
52 my ($obj,$text,$line,$start) = @_;
53 return $obj->restart_complete($text,$1,$start-(length($line)-length($1))) if $line =~ /^\s*\\sc?\s*\(.+?\)\s+(.*)$/i;
54 return $obj->{-interface}->filenames_complete($text,$line,$start) if $line =~ /^\s*\\sc?\s*\(\S*$/i;
55 return ('\s','\sc') if $line =~ /^\s*$/i;
56 return ('s(','sc(') if $line =~ /^\s*\\[A-Z]*$/i;
57 return ();
58 }