From da8fac282bee7f72d79741367acf5676881f1d2e Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Wed, 1 Oct 2008 04:03:20 +1300 Subject: [PATCH] Add some protection to failing to connect to MPD. --- lib/Display/Plugins/MPD.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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; } -- 2.30.2