App-SlowQuitApps
view release on metacpan or search on metacpan
lib/App/SlowQuitApps.pm view on Meta::CPAN
package App::SlowQuitApps;
use 5.010;
use strict;
use warnings;
use List::Util 'max';
our $VERSION = '0.000003';
# What the application is called...
my $APP_NAME = 'SlowQuitApps';
my $APP_ID = _get_id($APP_NAME) // die "Can't locate $APP_NAME\n";
our ($DELAY, %SLOWQUIT, %FASTQUIT, $CONFIGURED);
# This does the actual work, once all the calls set up what's to be done...
END {
_configure() if !$CONFIGURED;
}
# Export API...
sub import {
for my $subname (qw< delay slowquit fastquit >) {
no strict 'refs';
*{caller().'::'.$subname} = \&{$subname};
}
}
# Set delay...
sub delay {
my ($delay) = @_;
# Convert fractional seconds to integral milliseconds...
$DELAY = max(1, int($delay * 1000));
}
# Add an application to the blacklist (i.e. will be slowquitted)...
sub slowquit {
my ($app) = @_;
my $app_id = _get_id($app);
if (!$app_id || $app_id !~ /\S/) {
my (undef, undef, $line) = caller;
warn "Can't slowquit application '$app' at line $line (application not found)\n";
}
else {
$SLOWQUIT{$app} = $app_id;
}
}
# Add an application to the whitelist (i.e. will NOT be slowquitted)...
sub fastquit {
my ($app) = @_;
my $app_id = _get_id($app);
if (!$app_id || $app_id !~ /\S/) {
my (undef, undef, $line) = caller;
warn "Can't fastquit application '$app' at line $line (application not found)\n";
}
else {
$FASTQUIT{$app} = $app_id;
}
}
# This takes the information gathered, configures the system _defaults, and restarts the app...
sub _configure {
# Does the config make sense???
if (keys(%SLOWQUIT) && keys(%FASTQUIT)) {
warn "Can't configure both slowquit and fastquit on apps.\nConfiguration unchanged.\n";
}
else {
# Clear everything...
_defaults("delete $APP_ID");
# Set up delay...
if ($DELAY) {
_defaults("write $APP_ID delay -int $DELAY");
say "Slowquit after $DELAY msec";
}
# Set up whitelist or blacklist...
if (keys %SLOWQUIT) {
( run in 2.246 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )