]> git.etc.gen.nz Git - picture-display.git/commitdiff
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 35442f7043b831427fc455529f36d54292a1e8bf..11d744469e7c24c823ffa72c20a63cb9c4f5c6fa 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;
 }