Add some protection to failing to connect to MPD.
authorAndrew Ruthven <puck@catalyst.net.nz>
Tue, 30 Sep 2008 15:03:20 +0000 (04:03 +1300)
committerAndrew Ruthven <puck@dirk.wgtn.cat-it.co.nz>
Tue, 30 Sep 2008 15:03:20 +0000 (04:03 +1300)
lib/Display/Plugins/MPD.pm

index 35442f7..11d7444 100644 (file)
@@ -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;
 }