From: Andrew Ruthven Date: Wed, 17 Sep 2008 00:59:34 +0000 (+1200) Subject: Move display.pl into an FSpot module and start the framework for more modules. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97465c58ae398022a56d967c2e113167b6566628;p=picture-display.git Move display.pl into an FSpot module and start the framework for more modules. --- diff --git a/display.pl b/lib/Display/Plugins/FSpot.pm old mode 100755 new mode 100644 similarity index 54% rename from display.pl rename to lib/Display/Plugins/FSpot.pm index 16230ff..393e84c --- a/display.pl +++ b/lib/Display/Plugins/FSpot.pm @@ -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 index 0000000..82eae6c --- /dev/null +++ b/picture.pl @@ -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; +} +