From: Andrew Ruthven Date: Tue, 30 Sep 2008 15:03:20 +0000 (+1300) Subject: Add some protection to failing to connect to MPD. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da8fac282bee7f72d79741367acf5676881f1d2e;p=picture-display.git Add some protection to failing to connect to MPD. --- diff --git a/lib/Display/Plugins/MPD.pm b/lib/Display/Plugins/MPD.pm index 35442f7..11d7444 100644 --- a/lib/Display/Plugins/MPD.pm +++ b/lib/Display/Plugins/MPD.pm @@ -1,6 +1,7 @@ package Display::Plugins::MPD; use Clutter; +use Carp qw(cluck); use Audio::MPD; use POSIX qw/strftime/; use POE::Session; @@ -15,14 +16,21 @@ sub new { my $class = ref($proto) || $proto; my $self = $class->SUPER::new(@_); + bless ($self, $class); + + eval { + $self->{'mpd'} = Audio::MPD->new(); + }; + if ($@) { + carp "Failed to connect to MPD: $@"; + } else { + $self->init_delay($delay, 'mpd_display'); + $self->init(); + } - $self->{'mpd'} = Audio::MPD->new(); $self->{'file'} = ''; $self->{'active'} = 0; - bless ($self, $class); - $self->init_delay($delay, 'mpd_display'); - $self->init(); return $self; }