App-MPDSync
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/MPDSync.pm view on Meta::CPAN
package App::MPDSync;
use strict;
use warnings;
use 5.010;
our $VERSION = '0.02';
use Getopt::Long;
use Net::MPD;
use Proc::Daemon;
sub new {
my ($class, @options) = @_;
my $self = bless {
from => '',
to => 'localhost',
daemon => 1,
verbose => 0,
source => undef,
@options,
}, $class;
}
sub parse_options {
my ($self, @args) = @_;
local @ARGV = @args;
Getopt::Long::Configure('bundling');
Getopt::Long::GetOptions(
'D|daemon!' => \$self->{daemon},
'V|version' => \&show_version,
'f|from=s' => \$self->{from},
't|to=s' => \$self->{to},
'h|help' => \&show_help,
'v|verbose' => \$self->{verbose},
);
}
sub vprint {
my ($self, @message) = @_;
say @message if $self->{verbose};
}
sub show_help {
print <<'HELP';
Usage: mpd-sync [options] --from source [--to dest]
Options:
-f,--from Source MPD instance (required)
-t,--to Destination MPD instance (default localhost)
-v,--verbose Be noisy
--no-daemon Do not fork to background
-V,--version Show version and exit
-h,--help Show this help and exit
HELP
exit;
}
sub show_version {
say "mpd-sync (App::MPDSync) version $VERSION";
exit;
}
sub execute {
my ($self) = @_;
local @SIG{qw{ INT TERM HUP }} = sub {
exit 0;
};
unless ($self->{from}) {
say STDERR 'Source MPD not provided';
show_help;
}
my $source = Net::MPD->connect($self->{from});
if ($self->{daemon}) {
$self->vprint('Forking to background');
Proc::Daemon::Init;
}
{
$self->vprint('Syncrhonizing initial playlist');
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.470 second using v1.00-cache-2.02-grep-82fe00e-cpan-d29e8ade9f55 )