remove Base
Yuval Kogman [Wed, 30 Jul 2008 05:04:21 +0000 (05:04 +0000)]
lib/DBIx/Class/Schema/Journal.pm
lib/DBIx/Class/Schema/Journal/DB.pm
lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm
lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm
lib/DBIx/Class/Schema/Journal/DB/Base.pm [deleted file]
t/02noautodeploy.t

index eaa4808..588e887 100644 (file)
@@ -112,60 +112,22 @@ sub journal_schema_deploy
     $self->_journal_schema->deploy( $sqlt_args, @args );
 }
 
-sub get_audit_log_class_name
-{
-    my ($self, $sourcename) = @_;
-
-    return blessed($self->_journal_schema) . "::${sourcename}AuditLog";
-}
-
-sub get_audit_history_class_name
-{
-    my ($self, $sourcename) = @_;
-
-    return blessed($self->_journal_schema) . "::${sourcename}AuditHistory";
-}
-
 sub create_journal_for
 {
     my ($self, $s_name) = @_;
 
     my $source = $self->source($s_name);
-    my $logclass = $self->get_audit_log_class_name($s_name);
-
-    DBIx::Class::Componentised->inject_base($logclass, 'DBIx::Class::Schema::Journal::DB::AuditLog');
-    $logclass->journal_define_table($source);
 
-    my $log_source = "${s_name}AuditLog";
-    $self->_journal_schema->register_class($log_source, $logclass);
-                           
+    foreach my $audit (qw(AuditLog AuditHistory)) {
+        my $audit_source = join("", $s_name, $audit);
+        my $class = blessed($self->_journal_schema) . "::$audit_source";
 
-    my $histclass = $self->get_audit_history_class_name($s_name);
-    DBIx::Class::Componentised->inject_base($histclass, 'DBIx::Class::Schema::Journal::DB::AuditHistory');
-    $histclass->table(lc($s_name) . "_audit_history");
-#    $histclass->result_source_instance->name(lc($s_name) . "_audit_hisory");
+        DBIx::Class::Componentised->inject_base($class, "DBIx::Class::Schema::Journal::DB::$audit");
 
-    foreach my $column ( $source->columns ) {
-        my $info = $source->column_info($column);
+        $class->journal_define_table($source);
 
-        my %hist_info = %$info;
-
-        delete $hist_info{$_} for qw(
-            is_foreign_key
-            is_primary_key
-            is_auto_increment
-            default_value
-        );
-        
-        $hist_info{is_nullable} = 1;
-
-        $histclass->add_column($column => \%hist_info);
+        $self->_journal_schema->register_class($audit_source, $class);
     }
-                           
-    my $hist_source = "${s_name}AuditHistory";
-    $self->_journal_schema->register_class($hist_source, $histclass);
-
-    return ( $log_source, $hist_source );
 }
 
 sub txn_do
index d41ff5a..da13faf 100644 (file)
@@ -7,13 +7,10 @@ __PACKAGE__->mk_group_accessors( simple => 'current_user' );
 __PACKAGE__->mk_group_accessors( simple => 'current_session' );
 __PACKAGE__->mk_group_accessors( simple => '_current_changeset_container' );
 
-DBIx::Class::Schema::Journal::DB->load_classes(qw/
-                                               ChangeSet
-                                               ChangeLog
-                                               AuditHistory
-                                               /);
+DBIx::Class::Schema::Journal::DB->load_classes(qw(ChangeSet ChangeLog));
 
 require DBIx::Class::Schema::Journal::DB::AuditLog;
+require DBIx::Class::Schema::Journal::DB::AuditHistory;
 
 sub _current_changeset {
     my $self = shift;
index bfa8fba..706addd 100644 (file)
@@ -1,14 +1,41 @@
 package DBIx::Class::Schema::Journal::DB::AuditHistory;
 
-use base 'DBIx::Class::Schema::Journal::DB::Base';
-__PACKAGE__->table(__PACKAGE__->table);
-
-__PACKAGE__->add_columns(
-                           audit_change_id => {
-                               data_type => 'integer',
-                               is_nullable => 0,
-                           });
-__PACKAGE__->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'audit_change_id');
+use base 'DBIx::Class';
+
+sub journal_define_table {
+    my ( $class, $source ) = @_;
+
+    $class->load_components(qw(Core));
+
+    $class->table($source->name . "_audit_log");
+    
+    $class->add_column( audit_change_id => {
+        data_type => 'integer',
+        is_nullable => 0,
+        is_primary_key => 1,
+    });
+
+    $class->set_primary_key("audit_change_id");
+
+    foreach my $column ( $source->columns ) {
+        my $info = $source->column_info($column);
+
+        my %hist_info = %$info;
+
+        delete $hist_info{$_} for qw(
+            is_foreign_key
+            is_primary_key
+            is_auto_increment
+            default_value
+        );
+        
+        $hist_info{is_nullable} = 1;
+
+        $class->add_column($column => \%hist_info);
+    }
+                           
+    $class->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'audit_change_id');
+}
 
 sub new
 {
index 83a1a90..ec9d2e0 100644 (file)
@@ -7,7 +7,7 @@ sub journal_define_table {
 
     $class->load_components(qw(Core));
 
-    $class->table($source->name . "_audit_log");
+    $class->table($source->name . "_audit_history");
 
     $class->add_columns(
         create_id => {
diff --git a/lib/DBIx/Class/Schema/Journal/DB/Base.pm b/lib/DBIx/Class/Schema/Journal/DB/Base.pm
deleted file mode 100644 (file)
index 54ed707..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package DBIx::Class::Schema::Journal::DB::Base;
-
-use base 'DBIx::Class';
-
-__PACKAGE__->load_components(qw/Core/);
-__PACKAGE__->table('dummy');
-
-
-1;
index 8ceb5fd..4e40910 100644 (file)
@@ -21,7 +21,7 @@ isa_ok($schema->_journal_schema->source('CDAuditHistory'), 'DBIx::Class::ResultS
 isa_ok($schema->_journal_schema->source('ArtistAuditLog'), 'DBIx::Class::ResultSource', 'ArtistAuditLog source exists');
 
 my $count = eval { 
-    $schema->_journal_schema->resultset('ArtistAuditLog')->count;
+    $schema->_journal_schema->resultset('ArtistAuditHistory')->count;
 };
 my $e = $@;
 
@@ -30,7 +30,7 @@ like( $e, qr/table.*artist_audit_log/i, "missing table error" );
 
 $schema->journal_schema_deploy();
 
-$count = eval { $schema->_journal_schema->resultset('ArtistAuditLog')->count };
+$count = eval { $schema->_journal_schema->resultset('ArtistAuditHistory')->count };
 
 is( $@, '', "no error" );
 is( $count, 0, "count is 0" );