App-BCVI-NotifyClient
view release on metacpan or search on metacpan
lib/App/BCVI/NotifyClient.pm view on Meta::CPAN
14151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
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}) {
"Starting background process to monitor $opt{tty} for $opt{idle} second idle period\n"
;
"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}) {
"Starting background process to monitor $opt{tty} for output\n"
;
"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 0.317 second using v1.01-cache-2.11-cpan-26ccb49234f )