]> git.etc.gen.nz Git - picture-display.git/commitdiff
Move display.pl into an FSpot module and start the framework for more modules.
authorAndrew Ruthven <andrew@etc.gen.nz>
Wed, 17 Sep 2008 00:59:34 +0000 (12:59 +1200)
committerAndrew Ruthven <andrew@etc.gen.nz>
Wed, 17 Sep 2008 01:00:14 +0000 (13:00 +1200)
lib/Display/Plugins/FSpot.pm [moved from display.pl with 54% similarity, mode: 0644]
picture.pl [new file with mode: 0755]

old mode 100755 (executable)
new mode 100644 (file)
similarity index 54%
rename from display.pl
rename to lib/Display/Plugins/FSpot.pm
index 16230ff..393e84c
@@ -1,38 +1,39 @@
-#!/usr/bin/perl -w
+package Display::Plugins::FSpot;
 
 use DBI;
 
 my $f_spot_db = "/home/andrew/.gnome2/f-spot/photos.db";
 
+sub new {
+  my ($class,$instance) = @_;
 
-my ($dbh, $sth) = init();
+  my $self = {};
 
-while (1) {
-  print fetch_uri($sth) . "\n";
-  sleep 10;
+  bless ($self, $class);
+  $self->init();
+  return $self;
 }
 
-finish($dbh, $sth);
-
-
-sub fetch_uri {
-  my $sth = shift;
-
+sub display {
+  my $self = shift;
+  
   my $uri;
-  $sth->bind_columns(\$uri);
-  my $rc = $sth->execute()
+  $self->{'sth'}->bind_columns(\$uri);
+  my $rc = $self->{'sth'}->execute()
     || die "Failed to execute statement: $DBI::errstr\n";
 
-  $sth->fetch;
+  $self->{'sth'}->fetch;
 
-  $sth->finish()
+  $self->{'sth'}->finish()
     || die "Failed to finish statement: $DBI::errstr\n";;
 
   return $uri;
 }
 
 sub init {
-  my $dbh = DBI->connect("dbi:SQLite:dbname=$f_spot_db","","")
+  my $self = shift;
+
+  $self->{'dbh'} = DBI->connect("dbi:SQLite:dbname=$f_spot_db","","")
     || die "Failed to connect to $f_spot_db: $DBI::errstr\n";
 
   my $sql = "
@@ -45,14 +46,8 @@ ORDER BY random()
 LIMIT 1
 ";
 
-  my $sth = $dbh->prepare($sql)
+  $self->{'sth'} = $self->{'dbh'}->prepare($sql)
     || die "Failed to prepare statement: $DBI::errstr\n";
-
-  return ($dbh, $sth);
 }
 
-sub finish {
-  my ($dbh, $sth) = @_;
-
-  $dbh->disconnect();
-}
+1;
diff --git a/picture.pl b/picture.pl
new file mode 100755 (executable)
index 0000000..82eae6c
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+use strict;
+use FindBin;
+use Module::Pluggable search_path => ['Display::Plugins'];
+
+use lib "$FindBin::Bin/lib";
+
+my @modules = loadModules();
+
+for my $module (@modules) {
+  print $module->display() . "\n";
+}
+
+sub loadModules {
+  my @modules;
+
+  for my $module (plugins()) {
+  warn "Considering $module\n";
+    eval "use $module";
+    if ($@) {
+      die "Failed to load plugin: $module ($@)\n";
+    }
+
+    push @modules, $module->new();
+  }
+
+  return @modules;
+} 
+