App-GSD
view release on metacpan or search on metacpan
NAME
App::GSD - boost productivity by blocking distracting websites
VERSION
version 0.4
SYNOPSIS
use App::GSD;
my $app = App:GSD->new({ block => [qw(foo.com bar.com baz.com)] });
$app->work; # sites are now blocked
$app->play; # unblocked
METHODS
new ( \%args )
The following arguments are accepted:
block
An arrayref of hostnames to block, without a 'www.' prefix (if
present) as these will be blocked automatically.
hosts_file
Path to the hosts file (e.g. '/etc/hosts'), overriding the module's
guess based on current operating system.
network_command
A reference to an array passable to "system()" that will restart the
network, e.g.
['/etc/init.d/network', 'restart']
bin/get-shit-done view on Meta::CPAN
=head1 CONFIGURATION
The script will look for either C</etc/get-shit-done.yaml> or C</etc/gsd.yaml>
for configuration. The file is in YAML format, with the following fields:
=head2 block
List of hostnames to block, without 'www.' prefix (if any). For example,
if 'reddit.com' is provided, both 'reddit.com' and 'www.reddit.com' will
be blocked.
=head2 hosts_file
Path to the system hosts file, e.g. /etc/hosts. If not supplied, a default
is guessed based on operating system.
=head2 network_command
A command to flush DNS and/or restart the network. If not supplied, a
default is guessed based on OS.
lib/App/GSD.pm view on Meta::CPAN
return $self->{hosts_file};
}
# Return network_command as 'undef' (if not specified)
# or arrayref
sub network_command {
my $self = shift;
return $self->{network_command};
}
# List of sites to be blocked
sub blocklist {
my $self = shift;
my $block = $self->{block};
return map { ($_, "www.$_") } @$block;
}
# Determine the best method of flushing DNS, and execute it
sub _flush_dns {
my $self = shift;
my $netcmd = $self->network_command;
lib/App/GSD.pm view on Meta::CPAN
App::GSD - boost productivity by blocking distracting websites
=head1 VERSION
version 0.4
=head1 SYNOPSIS
use App::GSD;
my $app = App:GSD->new({ block => [qw(foo.com bar.com baz.com)] });
$app->work; # sites are now blocked
$app->play; # unblocked
=head1 METHODS
=head2 new ( \%args )
The following arguments are accepted:
=over
=item block
An arrayref of hostnames to block, without a 'www.' prefix (if
present) as these will be blocked automatically.
=item hosts_file
Path to the hosts file (e.g. '/etc/hosts'), overriding the
module's guess based on current operating system.
=item network_command
A reference to an array passable to C<system()> that will restart
the network, e.g.
t/author-basic.t view on Meta::CPAN
my @hosts = qw(reddit.com facebook.com);
my $app = App::GSD->new({ block => \@hosts });
isa_ok( $app, 'App::GSD', 'ctor ok' );
my $hosts_file = $app->hosts_file;
my $previous_hosts = read_file($hosts_file);
$app->work;
for my $host (@hosts, map { "www.$_" } @hosts) {
is( resolve($host), '127.0.0.1', "$host blocked" );
}
$app->play;
sleep 20; # Give network time to restart
for my $host (@hosts, map { "www.$_" } @hosts) {
isnt( resolve($host), '127.0.0.1', "$host no longer blocked" );
}
is( scalar read_file($hosts_file), $previous_hosts, 'host file matches original' ) or do {
diag("Restoring old hostfile...");
write_file($hosts_file, $previous_hosts);
};
done_testing;
# Resolve a hostname to an IP address
};
my $app = App::GSD->new($config);
isa_ok( $app, 'App::GSD', 'ctor ok' );
is( $app->hosts_file, $hosts_file, 'hosts_file accessor' );
$app->work;
my $new_hosts = read_file($hosts_file);
for my $host (@hosts, map {"www.$_" } @hosts) {
like($new_hosts, qr/^127\.0\.0\.1\s+\Q$host\E\s*$/m, "$host blocked");
}
$app->play;
is( read_file($hosts_file), $hosts, 'host file matches original' );
done_testing;
( run in 0.677 second using v1.01-cache-2.11-cpan-49f99fa48dc )