App-BCVI-NotifyClient
view release on metacpan or search on metacpan
lib/App/BCVI/NotifyClient.pm view on Meta::CPAN
my($self, @args) = @_;
my $command = $self->opt('command') || $self->default_command();
if($command eq 'notify') {
# Check for TTY monitoring options; handle them and exit
$self->_notify_handle_tty_monitoring(@args);
# Otherwise drop through for default handling
}
return $self->SUPER::send_command(@args);
}
sub _notify_handle_tty_monitoring {
my($self, @args) = @_;
my %opt = $self->_notify_get_options(@args) or return;
$opt{tty} ||= $self->_notify_current_tty;
if($opt{idle}) {
print "Starting background process to monitor $opt{tty} for $opt{idle} second idle period\n";
print "Kill monitor with: bnotify --kill\n";
$opt{output} = $default_poll_interval;
$self->_notify_fork_bg_tty_monitor(sub {
while(1) {
$self->_notify_wait_for_idle(\%opt);
$self->SUPER::send_command("terminal is idle");
$self->_notify_exit if $opt{once};
$self->_notify_wait_for_output(\%opt);
}
});
}
elsif($opt{output}) {
print "Starting background process to monitor $opt{tty} for output\n";
print "Kill monitor with: bnotify --kill\n";
$opt{idle} = $default_idle_time;
$self->_notify_fork_bg_tty_monitor(sub {
$self->_notify_wait_for_idle(\%opt);
while(1) {
$self->_notify_wait_for_output(\%opt);
$self->SUPER::send_command("output received");
$self->_notify_exit if $opt{once};
$self->_notify_wait_for_idle(\%opt);
}
});
}
elsif($opt{kill}) {
$self->App::BCVI::Server::kill_current_listener();
exit;
}
}
( run in 1.940 second using v1.01-cache-2.11-cpan-49f99fa48dc )