| 1 | package DBIx::dbMan::Extension::ShowTables; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'DBIx::dbMan::Extension'; | ||
| 5 | use Text::FormatTable; | ||
| 6 | |||
| 7 | our $VERSION = '0.05'; | ||
| 8 | |||
| 9 | 1; | ||
| 10 | |||
| 11 | sub IDENTIFICATION { return "000001-000020-000005"; } | ||
| 12 | |||
| 13 | sub preference { return 0; } | ||
| 14 | |||
| 15 | sub known_actions { return [ qw/SHOW_TABLES/ ]; } | ||
| 16 | |||
| 17 | sub handle_action { | ||
| 18 | my ($obj,%action) = @_; | ||
| 19 | |||
| 20 | if ($action{action} eq 'SHOW_TABLES') { | ||
| 21 | $action{action} = 'NONE'; | ||
| 22 | unless ($obj->{-dbi}->current) { | ||
| 23 | $obj->{-interface}->error("No current connection selected."); | ||
| 24 | return %action; | ||
| 25 | } | ||
| 26 | |||
| 27 | my $table = new Text::FormatTable '| l | l | l |'; | ||
| 28 | $table->rule; | ||
| 29 | $table->head('SCHEMA','NAME','TYPE'); | ||
| 30 | $table->rule; | ||
| 31 | |||
| 32 | my $sth = $obj->{-dbi}->table_info(); | ||
| 33 | my $ret = $sth->fetchall_arrayref(); | ||
| 34 | study $action{mask}; | ||
| 35 | if (defined $ret) { | ||
| 36 | for (sort { | ||
| 37 | ($a->[1] eq $b->[1]) | ||
| 38 | ? ($a->[2] cmp $b->[2]) | ||
| 39 | : ($a->[1] cmp $b->[1]) } @$ret) { | ||
| 40 | if (($action{type} eq 'object' or | ||
| 41 | $action{type} eq lc $_->[3]) and | ||
| 42 | $action{mask} and | ||
| 43 | $_->[1] =~ /$action{mask}/i) { | ||
| 44 | $table->row($_->[1],$_->[2],$_->[3]); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | $sth->finish; | ||
| 49 | $table->rule; | ||
| 50 | $action{action} = 'OUTPUT'; | ||
| 51 | $action{output} = $table->render($obj->{-interface}->render_size); | ||
| 52 | } | ||
| 53 | |||
| 54 | $action{processed} = 1; | ||
| 55 | return %action; | ||
| 56 | } |