App-AltSQL
view release on metacpan or search on metacpan
lib/App/AltSQL.pm view on Meta::CPAN
}
=head2 handle_term_input $input
The user has just typed something and submitted the buffer. Do something with it. Most notably, parse it for directives and act upon them.
=cut
sub handle_term_input {
my ($self, $input) = @_;
# Next if Ctrl-C or if user typed nothing
if (! length $input) {
return;
}
$input =~ s/\s*$//; # no trailing spaces
$input =~ s/;*$//; # no trailing semicolon
# Support mysql '\c' clear command
if ($input =~ m/\\c$/) {
return;
}
# Extract out \G
my %render_opts;
if ($input =~ s/\\G$//) {
$render_opts{one_row_per_column} = 1;
}
# Allow the user to pass non-SQL control verbs
if ($input =~ m/^\s*(quit|exit)\s*$/) {
$self->shutdown();
}
# Allow the user to execute perl code via '% print Dumper(...);'
if (my ($perl_code) = $input =~ m/^% (.+)$/) {
eval $perl_code;
if ($@) {
$self->log_error($@);
}
return;
}
if (my ($command) = $input =~ m/^\.([a-z]+)\b/i) {
my $handled = $self->call_command(lc($command), $input);
return if $handled;
}
$self->model->handle_sql_input($input, \%render_opts);
}
=head2 call_command $command, $input
Currently, the application treats any text that starts with a period as a command to the program rather then as SQL to be sent to the server. This method will be called with that command and the full line types. So, if someone typed '.reset screen'...
=cut
sub call_command {
my ($self, $command, $input) = @_;
# Do nothing here; placeholder for plugin's to attach to
return;
}
=head2 create_view %args
Call L<App::AltSQL::View> C<new()>, mixing in the app and command line view arguments and loading any requested plugins.
=cut
sub create_view {
my ($self, %args) = @_;
my $view = $self->args->{view_class}->new(
app => $self,
%args,
%{ $self->args->{view_args} },
);
if (my $plugins = $self->config->{view_plugins}) {
$view->load_plugins(@$plugins);
}
return $view;
}
=head2 log_info, log_debug, log_error
Your basic logging methods, they all currently do the same thing.
=cut
sub log_info {
my ($self, $message) = @_;
print $message . "\n";
}
sub log_debug {
return log_info(@_);
}
sub log_error {
return log_info(@_);
}
no Moose;
__PACKAGE__->meta->make_immutable;
=head1 DEVELOPMENT
This module is being developed via a git repository publicly available at http://github.com/ewaters/altsql-shell. I encourage anyone who is interested to fork my code and contribute bug fixes or new features, or just have fun and be creative.
=head1 COPYRIGHT
Copyright (c) 2012 Eric Waters and Shutterstock Images (http://shutterstock.com). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
=head1 AUTHOR
Eric Waters <ewaters@gmail.com>
( run in 0.582 second using v1.01-cache-2.11-cpan-e1769b4cff6 )