rev 1460 - in trunk/mariachi: . lib/Mariachi lib/Mariachi/DBI

[prev] [thread] [next] [lurker] [Date index for 2003/10/21]

From: richardc
Subject: rev 1460 - in trunk/mariachi: . lib/Mariachi lib/Mariachi/DBI
Date: 19:44 on 21 Oct 2003
Author: richardc
Date: 2003-10-21 19:44:34 +0100 (Tue, 21 Oct 2003)
New Revision: 1460

Added:
   trunk/mariachi/lib/Mariachi/DBI/
   trunk/mariachi/lib/Mariachi/DBI/Delay.pm
Modified:
   trunk/mariachi/Build.PL
   trunk/mariachi/lib/Mariachi/DBI.pm
   trunk/mariachi/lib/Mariachi/Message.pm
   trunk/mariachi/mariachi
Log:
neat-o Class::Delay stuff

Modified: trunk/mariachi/Build.PL
===================================================================
--- trunk/mariachi/Build.PL	2003-10-21 10:11:37 UTC (rev 1459)
+++ trunk/mariachi/Build.PL	2003-10-21 18:44:34 UTC (rev 1460)
@@ -11,8 +11,10 @@
         'Test::More'      => 0,
     },
     requires     => {
+        'perl'            => '5.006',
         'AppConfig'       => '1.55',
         'Class::Accessor' => 0,
+        'Class::Delay'    => 0,
         'Date::Parse'     => 0,
         'Email::Folder'   => '0.5',
         'Email::Thread'   => 0,

Added: trunk/mariachi/lib/Mariachi/DBI/Delay.pm
===================================================================
--- trunk/mariachi/lib/Mariachi/DBI/Delay.pm	2003-10-21 10:11:37 UTC (rev 1459)
+++ trunk/mariachi/lib/Mariachi/DBI/Delay.pm	2003-10-21 18:44:34 UTC (rev 1460)
@@ -0,0 +1,9 @@
+use strict;
+package Mariachi::DBI::Delay;
+use base 'Mariachi::DBI';
+use Class::Delay
+  methods => [qw( slacker_table set_up_table has_a has_many )],
+  release => [qw( set_db )],
+  reorder => sub { sort { $b->is_trigger <=> $a->is_trigger } @_ };
+
+1;

Modified: trunk/mariachi/lib/Mariachi/DBI.pm
===================================================================
--- trunk/mariachi/lib/Mariachi/DBI.pm	2003-10-21 10:11:37 UTC (rev 1459)
+++ trunk/mariachi/lib/Mariachi/DBI.pm	2003-10-21 18:44:34 UTC (rev 1460)
@@ -2,47 +2,14 @@
 package Mariachi::DBI;
 use base 'Class::DBI::SQLite';
 
-# XXX todo.  fix this api, call it Class::DBI::SQLite::AdHoc or something
-sub set_db {
-    my $class = shift;
-    $class->SUPER::set_db(@_);
-    $class->create_later;
-}
-
-my @create_later;
-sub create_later {
+# create table, for slackers
+sub slacker_table {
     my $self = shift;
-    for my $table ( @create_later ) {
-        my $sql = "CREATE TABLE ".$table->{name}. " ( "
-          . join(", ",
-                 # id goes without saying, so don't make me say it
-                 "id INTEGER PRIMARY KEY",
-                 keys %{ $table->{fields} },
-                ) . " ) ";
-        #warn $sql;
-        $self->db_Main->do( $sql )
-          or die "couldn't create '$table->{name}': " . $self->db_Main->errstr;
-        $table->{class}->set_up_table( $table->{name} );
-    }
 
-    # and now set up the tables and the has_a's
-    for my $table ( @create_later ) {
-        while ( my ($k, $v) = each %{ $table->{fields} }) {
-            next unless $v;
-            $table->{class}->has_a( $k => $v );
-        }
-    }
+    # id goes without saying, so don't make me say it
+    my $sql = "CREATE TABLE ".$self->moniker. " ( "
+      . join(", ", "id INTEGER PRIMARY KEY", @_ ) . " )";
+    #warn $sql;
+    $self->db_Main->do( $sql )
 }
-
-# I want to have my cake, and eat it.  Maybe if I eat it *later*... :)
-sub set_up_later {
-    my $class   = shift;
-
-    push @create_later, {
-        name   => $class->moniker,
-        class  => $class,
-        fields => { @_ },
-    };
-}
-
 1;

Modified: trunk/mariachi/lib/Mariachi/Message.pm
===================================================================
--- trunk/mariachi/lib/Mariachi/Message.pm	2003-10-21 10:11:37 UTC (rev 1459)
+++ trunk/mariachi/lib/Mariachi/Message.pm	2003-10-21 18:44:34 UTC (rev 1460)
@@ -7,22 +7,15 @@
 use Text::Original ();
 use Memoize;
 
-use base 'Mariachi::DBI';
-__PACKAGE__->set_up_later(
-    map { $_ => '' } qw(
-        hdr_message_id hdr_from hdr_subject hdr_date
-        hdr_references hdr_in_reply_to
-        body epoch_date day month year ),
-   );
-
-#these are just sops
+use base 'Mariachi::DBI::Delay';
+__PACKAGE__->slacker_table( qw(
+    hdr_message_id hdr_from hdr_subject hdr_date
+    hdr_references hdr_in_reply_to
+    body epoch_date day month year
+  ));
+__PACKAGE__->set_up_table( __PACKAGE__->moniker );
 __PACKAGE__->columns( TEMP => qw( prev next root ) );
 
-sub _header_column {
-    my $thing = shift;
-    $thing =~ tr/-/_/;
-    return "hdr_" . lc $thing;
-}
 
 =head1 NAME
 
@@ -38,6 +31,14 @@
 
 =cut
 
+
+sub _header_column {
+    my $thing = shift;
+    $thing =~ tr/-/_/;
+    return "hdr_" . lc $thing;
+}
+
+
 sub new {
     my $class = shift;
 

Modified: trunk/mariachi/mariachi
===================================================================
--- trunk/mariachi/mariachi	2003-10-21 10:11:37 UTC (rev 1459)
+++ trunk/mariachi/mariachi	2003-10-21 18:44:34 UTC (rev 1460)
@@ -200,7 +200,9 @@
     $config->name("no list name");
 }
 
-Mariachi::DBI->set_db( 'Main', 'dbi:SQLite:'.$config->output.'/mariachi.db', '', '' );
+Mariachi::DBI::Delay->set_db(
+    Main => 'dbi:SQLite:'.$config->output.'/mariachi.db'
+   );
 $config->class->new( config  => $config,
                      threads_per_page => 20,
                     )

Generated at 13:57 on 01 Jul 2004 by mariachi 0.52