Index: trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm
===================================================================
--- trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm	(revision 5172)
+++ trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm	(revision 5185)
@@ -1,5 +1,5 @@
 # Copyright (C) 2005  Joshua Hoblitt
 #
-# $Id: MetaDB.pm,v 1.3 2005-09-28 21:45:08 jhoblitt Exp $
+# $Id: MetaDB.pm,v 1.4 2005-09-29 21:20:25 jhoblitt Exp $
 
 package PS::IPP::MetaDB;
@@ -15,5 +15,29 @@
 use Carp qw( croak );
 
-__PACKAGE__->set_db('Main', 'dbi:mysql:test', 'test', '');
+sub import {
+    my $class = shift;
+
+    $class->init( @_ ) if @_;
+}
+
+my @child_inits;
+
+sub init {
+    my $class = shift;
+    my %p = @_;
+    
+    croak "dsn is required" unless exists $p{dsn};
+
+    $class->set_db('Main', $p{dsn}, $p{user}, $p{passwd});
+
+    foreach my $init (@child_inits) {
+        &$init;
+    }
+}
+
+sub register_init {
+    my $class = shift;
+    push @child_inits, shift;
+}
 
 # lifted from Class::DBI docs (modified)
@@ -36,95 +60,9 @@
 }
 
-
-sub new2newed {
+sub add_new {
     my $class = shift;
     my %p = @_;
 
-    $class->do_transaction(sub { $class->_new2newed(%p) });
-}
-
-sub _new2newed {
-    my $class = shift;
-    my %p = @_;
-
-    "${class}::Image::New"->search(
-        exp_id      => $p{exp_id},
-        class_id    => $p{class_id},
-    )->delete_all;
-
-    "${class}::Image::Newed"->create({
-        exp_id      => $p{exp_id},
-        class_id    => $p{class_id},
-        url         => $p{url},
-    });
-}
-
-
-#package PS::IPP::MetaDB::Image::Prepared;
-#package PS::IPP::MetaDB::Image::Reduced;
-#package PS::IPP::MetaDB::Image::Analyzed;
-#package PS::IPP::MetaDB::Image::Combined;
-
-=pod
-
-=head2 Temporal Queues
-
-These queues all describe work that I<needs> to be performed but hasn't
-happened yet.
-
-=over 4
-
-=item * new
-
-This table contains a list of new data waiting to be downloaded from the
-summit.  The location of fetched data files is written into the C<newed> table.
-
-Table description:
-
-=over 4
-
-=item * url
-
-URL to retrieve data from
-
-=item * exp_id
-
-exposure ID #
-
-=item * camera
-
-Camera that this data was acquired from
-
-=item * class
-
-The 'type' of data this is
-
-=item * class_id
-
-A unique identifier for data of the same class in the same exposure.
-
-=back
-
-=cut
-
-package PS::IPP::MetaDB::Image::New;
-
-use base qw( PS::IPP::MetaDB );
-
-__PACKAGE__->table("new");
-__PACKAGE__->create_table(q{
-    exp_id      BIGINT          NOT NULL PRIMARY KEY,
-    class_id    BIGINT          NOT NULL,
-    camera      VARCHAR(255),
-    class       VARCHAR(255),
-    url         VARCHAR(255)    NOT NULL
-});
-__PACKAGE__->set_up_table;
-
-sub add_new {
-    my $class = shift;
-    my %p = @_;
-
-    $class->create({
+    PS::IPP::MetaDB::Image::New->create({
         exp_id      => $p{exp_id},
         class_id    => $p{class_id},
@@ -140,10 +78,103 @@
 
     if (exists $p{exp_id}) {
-        $class->search( $p{exp_id}, { order_by => 'class_id' } );
+        PS::IPP::MetaDB::Image::New->search(
+            $p{exp_id},
+            { order_by => 'class_id' },
+        );
     } else {
-        $class->retrieve_all;
+        PS::IPP::MetaDB::Image::New->retrieve_all;
     }
 }
 
+sub new2newed {
+    my $class = shift;
+    my %p = @_;
+
+    $class->do_transaction(sub { $class->_new2newed(%p) });
+}
+
+sub _new2newed {
+    my $class = shift;
+    my %p = @_;
+
+    $class->search(
+        exp_id      => $p{exp_id},
+        class_id    => $p{class_id},
+    )->delete_all;
+
+    $class->create({
+        exp_id      => $p{exp_id},
+        class_id    => $p{class_id},
+        url         => $p{url},
+    });
+}
+
+
+#package PS::IPP::MetaDB::Image::Prepared;
+#package PS::IPP::MetaDB::Image::Reduced;
+#package PS::IPP::MetaDB::Image::Analyzed;
+#package PS::IPP::MetaDB::Image::Combined;
+
+=pod
+
+=head2 Temporal Queues
+
+These queues all describe work that I<needs> to be performed but hasn't
+happened yet.
+
+=over 4
+
+=item * new
+
+This table contains a list of new data waiting to be downloaded from the
+summit.  The location of fetched data files is written into the C<newed> table.
+
+Table description:
+
+=over 4
+
+=item * url
+
+URL to retrieve data from
+
+=item * exp_id
+
+exposure ID #
+
+=item * camera
+
+Camera that this data was acquired from
+
+=item * class
+
+The 'type' of data this is
+
+=item * class_id
+
+A unique identifier for data of the same class in the same exposure.
+
+=back
+
+=cut
+
+package PS::IPP::MetaDB::Image::New;
+
+use base qw( PS::IPP::MetaDB );
+
+__PACKAGE__->register_init(\&init);
+
+sub init
+{
+    __PACKAGE__->table("new");
+    __PACKAGE__->create_table(q{
+        exp_id      BIGINT          NOT NULL PRIMARY KEY,
+        class_id    BIGINT          NOT NULL,
+        camera      VARCHAR(255),
+        class       VARCHAR(255),
+        url         VARCHAR(255)    NOT NULL
+    });
+    __PACKAGE__->set_up_table;
+}
+
 =item * raw
 
@@ -168,10 +199,15 @@
 use base qw( PS::IPP::MetaDB );
 
-__PACKAGE__->table("raw");
-__PACKAGE__->create_table(q{
-    exp_id      BIGINT          NOT NULL PRIMARY KEY,
-    class_id    BIGINT          NOT NULL 
-});
-__PACKAGE__->set_up_table;
+__PACKAGE__->register_init(\&init);
+
+sub init
+{
+    __PACKAGE__->table("raw");
+    __PACKAGE__->create_table(q{
+        exp_id      BIGINT          NOT NULL PRIMARY KEY,
+        class_id    BIGINT          NOT NULL 
+    });
+    __PACKAGE__->set_up_table;
+}
 
 =item * prepare
@@ -366,11 +402,16 @@
 use base qw( PS::IPP::MetaDB );
 
-__PACKAGE__->table("newed");
-__PACKAGE__->create_table(q{
-    exp_id      BIGINT          NOT NULL PRIMARY KEY,
-    class_id    BIGINT          NOT NULL,
-    url         VARCHAR(255)    NOT NULL
-});
-__PACKAGE__->set_up_table;
+__PACKAGE__->register_init(\&init);
+
+sub init
+{
+    __PACKAGE__->table("newed");
+    __PACKAGE__->create_table(q{
+        exp_id      BIGINT          NOT NULL PRIMARY KEY,
+        class_id    BIGINT          NOT NULL,
+        url         VARCHAR(255)    NOT NULL
+    });
+    __PACKAGE__->set_up_table;
+}
 
 =item * prepared
