rev 1415 - in trunk/mariachi: . lib/Mariachi

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

From: richardc
Subject: rev 1415 - in trunk/mariachi: . lib/Mariachi
Date: 23:30 on 15 Oct 2003
Author: richardc
Date: 2003-10-15 23:30:44 +0100 (Wed, 15 Oct 2003)
New Revision: 1415

Added:
   trunk/mariachi/lib/Mariachi/DBI.pm
Modified:
   trunk/mariachi/lib/Mariachi/Message.pm
   trunk/mariachi/mariachi
Log:
causing huge breakage in the name of insanely shiny

Added: trunk/mariachi/lib/Mariachi/DBI.pm
===================================================================
--- trunk/mariachi/lib/Mariachi/DBI.pm	2003-10-15 22:29:54 UTC (rev 1414)
+++ trunk/mariachi/lib/Mariachi/DBI.pm	2003-10-15 22:30:44 UTC (rev 1415)
@@ -0,0 +1,47 @@
+use strict;
+package Mariachi::DBI;
+use base 'Class::DBI::SQLite';
+
+sub set_db {
+    my $class = shift;
+    $class->SUPER::set_db(@_);
+    $class->create_later;
+}
+
+my @create_later;
+sub create_later {
+    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 );
+    }
+
+    # and now set up the tables and the has_a's
+    for my $table ( @create_later ) {
+        # ??? this next line seems to segv.  badness
+        $table->{class}->set_up_table( $table->{name} );
+        while ( my ($k, $v) = each %{ $table->{fields} }) {
+            next unless $v;
+            $table->{class}->has_a( $k => $v );
+        }
+    }
+}
+
+# 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-15 22:29:54 UTC (rev 1414)
+++ trunk/mariachi/lib/Mariachi/Message.pm	2003-10-15 22:30:44 UTC (rev 1415)
@@ -7,32 +7,22 @@
 use Text::Original ();
 use Memoize;
 
-use base qw(Class::Accessor::Fast);
-__PACKAGE__->mk_accessors(qw( body _header next prev root
-                              epoch_date day month year ymd linked
-                            ));
+use base 'Mariachi::DBI';
+__PACKAGE__->set_up_later(
+    rawmail    => 'Email::Simple',
+    body       => '',
+    epoch_date => '',
+   );
+__PACKAGE__->add_trigger( before_create => \&pre_create );
 
-=head1 NAME
+# copy things out of the email::simple message and into the columns
+sub pre_create {
+    my $data = shift;
+    warn "pre_create";
+}
 
-Mariachi::Message - representation of a mail message
+=for later
 
-=head1 METHODS
-
-=head2 ->new($message)
-
-C<$message> is a rfc2822 compliant message body
-
-your standard constructor
-
-=cut
-
-sub new {
-    my $class = shift;
-    my $source = shift;
-
-    my $self = $class->SUPER::new;
-    my $mail = Email::Simple->new($source) or return;
-
     $self->linked({});
     $self->_header({});
     $self->header_set( $_, $mail->header($_) ) for
@@ -53,9 +43,28 @@
     $self->year(  sprintf "%04d", @ymd );
 
     return $self;
+
 }
 
+=head1 NAME
 
+Mariachi::Message - representation of a mail message
+
+=head1 METHODS
+
+=head2 ->new($message)
+
+C<$message> is a rfc2822 compliant message body
+
+your standard constructor
+
+=cut
+
+sub new {
+    die "don't look at me";
+}
+
+
 sub _make_fake_id {
     my $self = shift;
     my $hash = substr( md5_hex( $self->header('from').$self->date ), 0, 8 );

Modified: trunk/mariachi/mariachi
===================================================================
--- trunk/mariachi/mariachi	2003-10-15 22:29:54 UTC (rev 1414)
+++ trunk/mariachi/mariachi	2003-10-15 22:30:44 UTC (rev 1415)
@@ -55,17 +55,18 @@
 =cut
 
 # define the command line options
-my $config = AppConfig->new({ PEDANTIC => 1,
-                              GLOBAL   => {
-                                  ARGCOUNT => ARGCOUNT_ONE,
-                              },
-                              ERROR    => sub {
-                                  my $format = shift;
-                                  $format = "mariachi: $format\n";
-                                  print STDERR sprintf $format, @_;
-                                  exit;
-                              },
-                             });
+my $config = AppConfig->new({
+    PEDANTIC => 1,
+    GLOBAL   => {
+        ARGCOUNT => ARGCOUNT_ONE,
+    },
+    ERROR    => sub {
+        my $format = shift;
+        $format = "mariachi: $format\n";
+        print STDERR sprintf $format, @_;
+        exit;
+    },
+});
 
 $config->define("input", { ALIAS => 'i' });
 
@@ -199,6 +200,7 @@
     $config->name("no list name");
 }
 
+Mariachi::DBI->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