dbMan/Extension/CmdCount.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 78 CC 9 SCAR 24.3
CC
9
Cov
0%
handle_action
20.0
cmdcomplete
20.0
objectlist
6.0
CRAP 11.4
1 package DBIx::dbMan::Extension::CmdCount;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5  
6 our $VERSION = '0.02';
7  
8 1;
9  
10 sub IDENTIFICATION { return "000001-000078-000002"; }
11  
12 sub preference { return 1000; }
13  
14 sub known_actions { return [ qw/COMMAND/ ]; }
15  
16 sub handle_action {
17 my ($obj,%action) = @_;
18  
19 if ($action{action} eq 'COMMAND' and $obj->{-dbi}->current) {
20 if ($action{cmd} =~ /^(?:\/\*.*?\*\/\s*)?count\s+(.*)(?:\s*\/\*.*?\*\/)?$/i) {
21 $action{action} = 'COUNT';
22 $action{count_tables} = [ split /,/,$1 ];
23 } elsif ($action{cmd} =~ /^(?:\/\*.*?\*\/\s*)?countre\s+(.*)(?:\s*\/\*.*?\*\/)?$/i) {
24 $action{action} = 'COUNT';
25 $action{count_re} = $1 || '^';
26 }
27 }
28  
29 $action{processed} = 1;
30 return %action;
31 }
32  
33 sub objectlist {
34 my ($obj,$type,$text) = @_;
35  
36 my %action = (action => 'SQL', oper => 'complete', what => 'list', type => $type, context => $text);
37 do {
38 %action = $obj->{-core}->handle_action(%action);
39 } until ($action{processed});
40 return @{$action{list}} if ref $action{list} eq 'ARRAY';
41 return ();
42 }
43  
44 sub cmdcomplete {
45 my ($obj,$text,$line,$start) = @_;
46 return () unless $obj->{-dbi}->current;
47 return map { $1.$_ } $obj->objectlist('TABLE',$2) if $line =~ /^\s*(?:\/\*.*?\*\/\s*)?COUNT\s+(?:.*,\s+|.*?(\S*,))?(\S*)$/i;
48 return qw/COUNT COUNTRE/ if $line =~ /^\s*(?:\/\*.*?\*\/\s*)?[A-Z]*$/i;
49 }
50  
51 sub cmdhelp {
52 my $obj = shift;
53  
54 return [ 'COUNT <table>,...' => 'Select base statistics of tables',
55 'COUNTRE <re>' => 'COUNT on table name fit to RE' ] if $obj->{-dbi}->current;
56 return [];
57 }