-#!/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 = "
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;
--- /dev/null
+#!/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;
+}
+