| 1 | package DBIx::dbMan::Extension::History; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'DBIx::dbMan::Extension'; | ||
| 5 | use Text::FormatTable; | ||
| 6 | use DBIx::dbMan::History; | ||
| 7 | |||
| 8 | our $VERSION = '0.05'; | ||
| 9 | |||
| 10 | 1; | ||
| 11 | |||
| 12 | sub IDENTIFICATION { return "000001-000035-000005"; } | ||
| 13 | |||
| 14 | sub preference { return 0; } | ||
| 15 | |||
| 16 | sub known_actions { return [ qw/HISTORY/ ]; } | ||
| 17 | |||
| 18 | sub menu { | ||
| 19 | my $obj = shift; | ||
| 20 | |||
| 21 | return ( { label => 'Input', submenu => [ | ||
| 22 | { label => 'History', submenu => [ | ||
| 23 | { label => 'Show', action => { action => 'HISTORY', | ||
| 24 | operation => 'show' } }, | ||
| 25 | { label => 'Clear', action => { action => 'HISTORY', | ||
| 26 | operation => 'clear' } } | ||
| 27 | ] } ] } ); | ||
| 28 | } | ||
| 29 | |||
| 30 | sub handle_action { | ||
| 31 | my ($obj,%action) = @_; | ||
| 32 | |||
| 33 | if ($action{action} eq 'HISTORY') { | ||
| 34 | if ($action{operation} eq 'show') { | ||
| 35 | my $table = new Text::FormatTable '| r l |'; | ||
| 36 | $table->rule; | ||
| 37 | my $i = 1; | ||
| 38 | my $history = new DBIx::dbMan::History -config => $obj->{-config}; | ||
| 39 | for ($history->load()) { | ||
| 40 | $table->row("$i.",$_); | ||
| 41 | ++$i; | ||
| 42 | } | ||
| 43 | $table->rule; | ||
| 44 | $action{action} = 'OUTPUT'; | ||
| 45 | $action{output} = $table->render($obj->{-interface}->render_size); | ||
| 46 | } elsif ($action{operation} eq 'clear') { | ||
| 47 | $obj->{-interface}->history_clear(); | ||
| 48 | $action{action} = 'OUTPUT'; | ||
| 49 | $action{output} = "Commands history cleared.\n"; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | $action{processed} = 1; | ||
| 54 | return %action; | ||
| 55 | } |