package Dancer::Plugin::MPD; use warnings; use strict; use
Dancer::Plugin; use Audio::MPD; our $VERSION = '0.03'; my $mpd;
register mpd => sub { if ($mpd && $mpd->ping) { return $mpd; }
else { return $mpd = _connect(); } }; sub _connect { my $conf =
plugin_setting; # Only pass settings to Audio::MPD if they're
specified in the config; # Audio::MPD does sensible things by
default, so in the majority of cases # (MPD listening on
localhost, on port 6600, with no password set), no #
configuration will be needed at all. my %mpd_conf; for my
$setting (qw(host port password conntype)) { $mpd_conf{$setting}
= $conf->{$setting} if exists $conf->{$setting}; } #
Audio::MPD's default conntype is 'once', which re-establishes a
connection # for every request. For performance, we probably
want to re-use a # connection. $mpd_conf{conntype} ||= 'reuse';
my $mpd = Audio::MPD->new(\%mpd_conf);
Dancer::Factory::Hook->instance->execute_hooks('mpd_connected',
$mpd); return $mpd; }
Dancer::Factory::Hook->instance->install_hooks(qw(