dbMan/Extension/EditObjectsOracle.pm untested

filter: Statementstmt 0.0% 0 / 78 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 158 CC 23 SCAR 51.4
CC
23
Cov
0%
handle_action
306.0
cmdcomplete
42.0
objectlist
6.0
CRAP 171.2
1 package DBIx::dbMan::Extension::EditObjectsOracle;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5 use Text::FormatTable;
6 use Term::ANSIColor;
7  
8 our $VERSION = '0.06';
9  
10 1;
11  
12 sub IDENTIFICATION { return "000001-000045-000006"; }
13  
14 sub preference { return 50; }
15  
16 sub known_actions { return [ qw/EDIT_OBJECT/ ]; }
17  
18 sub handle_action {
19 my ($obj,%action) = @_;
20  
21 $action{processed} = 1;
22 if ($action{action} eq 'EDIT_OBJECT' and $obj->{-dbi}->driver eq 'Oracle') {
23 unless ($obj->{-dbi}->current) {
24 $action{action} = 'NONE';
25 $obj->{-interface}->error("No current connection selected.");
26 return %action;
27 }
28 my $lastwhat = $action{what};
29 my $schema = '';
30 $schema = uc $1 if $action{what} =~ s/^([^.]+)\.//;
31 my $schema_add = '';
32 my @schema = ();
33 if ($schema) {
34 $schema_add = ' AND owner = ?';
35 push @schema,$schema;
36 }
37 my $basetable = $schema?'all':'user';
38  
39 my $d = $obj->{-dbi}->selectall_arrayref(q!
40 SELECT object_name, object_type
41 FROM !.$basetable.q!_objects
42 WHERE UPPER(object_name) LIKE ? AND object_type !.($action{type}?(q! = '!.uc($action{type}).q!'!):q!IN ('PROCEDURE','FUNCTION','TRIGGER','VIEW','PACKAGE','PACKAGE BODY')!).$schema_add,
43 {},uc($action{what}),@schema);
44 $action{what} = $lastwhat;
45 if (defined $d) {
46 $action{action} = 'NONE';
47 if (@$d) {
48 if (@$d == 1) {
49 $action{action} = 'EDIT';
50 $action{what} = $d->[0][0];
51 $action{what} = "$schema.".$action{what} if $schema;
52 $action{type} = $d->[0][1];
53 delete $action{processed};
54 return %action;
55 } else {
56 my $colorized = $obj->{-mempool}->get('output_format') eq 'colortable';
57 $action{action} = 'OUTPUT';
58 $action{output} = "You must explicit say which object you want edit:\n";
59 my $tab = new Text::FormatTable '| l | l |';
60 $tab->rule;
61 my @schema = ();
62 push @schema,'SCHEMA' if $schema;
63 $tab->head(map { $colorized ? color( $obj->{-config}->tablecolor_head || 'bright_yellow' ) . $_ . color( $obj->{-config}->tablecolor_lines || 'reset' ) : $_; } @schema,'NAME','TYPE');
64 $tab->rule;
65 for (@$d) {
66 my @item = ();
67 push @item,$schema if $schema;
68 $tab->row(map { $colorized ? color( $obj->{-config}->tablecolor_content || 'bright_white' ) . $_ . color( $obj->{-config}->tablecolor_lines || 'reset' ) : $_; } @item,@$_);
69 }
70 $tab->rule;
71 $action{output} .= ( $colorized ? color( $obj->{-config}->tablecolor_lines || 'reset' ) : '' )
72 . $tab->render($obj->{-interface}->render_size) . ( $colorized ? color( 'reset' ) : '' );
73 }
74 } else {
75 $obj->{-interface}->error("Object ".$action{what}." not found.");
76 return %action;
77 }
78 } else {
79 $obj->{-interface}->error( DBI::errstr() );
80 }
81 }
82  
83 return %action;
84 }
85  
86 sub objectlist {
87 my ($obj,$type) = @_;
88 my $d = $obj->{-dbi}->selectall_arrayref(q!
89 SELECT object_name
90 FROM user_objects
91 WHERE object_type !.
92 ($type?(q! = '!.$type.q!'!):q!IN ('PROCEDURE','FUNCTION','TRIGGER','VIEW','PACKAGE','PACKAGE BODY')!));
93 return map { $_->[0] } @$d;
94 }
95  
96 sub cmdcomplete {
97 my ($obj,$text,$line,$start) = @_;
98 return () unless $obj->{-dbi}->current;
99 return $obj->objectlist('PACKAGE BODY') if $line =~ /^\s*EDIT\s+PACKAGE\s+BODY\s+\S*$/i;
100 return ('BODY',$obj->objectlist('PACKAGE')) if $line =~ /^\s*EDIT\s+PACKAGE\s+\S*$/i;
101 return $obj->objectlist($1) if $line =~ /^\s*EDIT\s+(PROCEDURE|FUNCTION|TRIGGER|VIEW|PACKAGE)\s+\S*$/i;
102 return qw/PROCEDURE FUNCTION TRIGGER VIEW PACKAGE/ if $line =~ /^\s*EDIT\s+\S*$/i;
103 return ();
104 }