App-DuckPAN
view release on metacpan or search on metacpan
lib/App/DuckPAN/Query.pm view on Meta::CPAN
package App::DuckPAN::Query;
our $AUTHORITY = 'cpan:DDG';
# ABSTRACT: Main application/loop for duckpan query
$App::DuckPAN::Query::VERSION = '1021';
use Moo;
use Data::Printer return_value => 'dump';
use POE qw( Wheel::ReadLine );
use Try::Tiny;
use Path::Tiny;
use App::DuckPAN::Fathead;
use open qw/:std :utf8/;
# Entry into the module.
sub run {
my ( $self, $app, $blocks ) = @_;
# Here so that travis builds will pass on github
require DDG::Request;
DDG::Request->import;
require DDG::Test::Location;
DDG::Test::Location->import;
require DDG::Test::Language;
DDG::Test::Language->import;
# Main session. All events declared have equivalent subs.
POE::Session->create(
package_states => [
$self => [qw(_start _stop _get_user_input _got_user_input _run_query)]
],
args => [$app, $blocks] # passed to _start
);
POE::Kernel->run();
return 0;
}
# Initialize the main session. Called once by default.
sub _start {
my ($k, $h, $app, $blocks) = @_[KERNEL, HEAP, ARG0, ARG1];
my $history_path = $app->cfg->cache_path->child('query_history');
# Session that handles user input
my $powh_readline = POE::Wheel::ReadLine->new(
InputEvent => '_got_user_input'
);
$powh_readline->bind_key("C-\\", "interrupt");
$powh_readline->read_history($history_path);
$powh_readline->put('(Empty query for ending test)');
# Store in the heap for use in other events
@$h{qw(app blocks console history_path)} = ($app, $blocks, $powh_readline, $history_path);
$k->sig(TERM => '_stop');
# Queue user input event
$k->yield('_get_user_input');
}
sub _default { warn "Unhandled event - $_[ARG0]" }
# The session is about to stop. Ensure that the ReadLine object is
# deleted, so it can place your terminal back into a sane mode. This
# function is triggered by POE's "_stop" event.
sub _stop {
undef $_[HEAP]->{console}; #powh_readline;
exit;
}
( run in 2.046 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )