__PACKAGE__->mk_classdata('journal_deploy_on_connect');
__PACKAGE__->mk_classdata('journal_sources'); ## [ source names ]
__PACKAGE__->mk_classdata('journal_user'); ## [ class, field for user id ]
+__PACKAGE__->mk_classdata('journal_copy_sources');
+__PACKAGE__->mk_classdata('__journal_schema_prototype');
__PACKAGE__->mk_classdata('_journal_schema'); ## schema object for journal
+__PACKAGE__->mk_classdata('journal_component');
__PACKAGE__->mk_classdata('journal_nested_changesets');
-our $VERSION = '0.01';
-
use strict;
use warnings;
-# sub throw_exception
-# {
-# }
-
-# sub exception_action
-# {
-# my $self = shift;
-# # print STDERR Carp::longmess;
-
-# $self->next::method(@_);
-# }
-# sub load_classes
-# {
-# my $class = shift;
+sub _journal_schema_prototype
+{
+ my $self = shift;
+ if (my $proto = $self->__journal_schema_prototype)
+ {
+ return $proto;
+ }
+ my $proto = $self->__journal_schema_prototype
+ (
+ DBIx::Class::Schema::Journal::DB->compose_namespace
+ (
+ (blessed($self)||$self) . '::Journal'
+ )
+ );
+ my $comp = $self->journal_component || "Journal";
+ ## Create auditlog+history per table
+ my %j_sources = map { $_ => 1 } $self->journal_sources
+ ? @{$self->journal_sources}
+ : $self->sources;
-# $class->next::method(@_);
-
-# }
+ foreach my $s_name ($self->sources)
+ {
+ next unless($j_sources{$s_name});
+ $self->create_journal_for($s_name => $proto);
+ $self->class($s_name)->load_components($comp);
+ }
+ return $proto;
+}
sub connection
{
my $self = shift;
my $schema = $self->next::method(@_);
-# print STDERR join(":", $self->sources), "\n";
-
- my $journal_schema = DBIx::Class::Schema::Journal::DB->compose_namespace(blessed($self) . '::Journal');
+ my $journal_schema = (ref $self||$self)->_journal_schema_prototype->clone;
if($self->journal_connection)
{
$self->_journal_schema($journal_schema);
- ## Create auditlog+history per table
- my %j_sources = map { $_ => 1 } $self->journal_sources
- ? @{$self->journal_sources}
- : $self->sources;
-
- foreach my $s_name ($self->sources)
- {
- next unless($j_sources{$s_name});
- $self->create_journal_for($s_name);
- $self->class($s_name)->load_components('Journal');
-# print STDERR "$s_name :", $self->class($s_name), "\n";
- }
-
if ( $self->journal_nested_changesets ) {
$self->_journal_schema->nested_changesets(1);
die "FIXME nested changeset schema not yet supported... add parent_id to ChangeSet here";
sub create_journal_for
{
- my ($self, $s_name) = @_;
+ my ($self, $s_name, $journal_schema) = @_;
my $source = $self->source($s_name);
foreach my $audit (qw(AuditLog AuditHistory)) {
my $audit_source = join("", $s_name, $audit);
- my $class = blessed($self->_journal_schema) . "::$audit_source";
+ my $class = blessed($journal_schema) . "::$audit_source";
DBIx::Class::Componentised->inject_base($class, "DBIx::Class::Schema::Journal::DB::$audit");
$class->journal_define_table($source);
- $self->_journal_schema->register_class($audit_source, $class);
+ $journal_schema->register_class($audit_source, $class);
+
+ if ($self->journal_copy_sources)
+ {
+ $self->register_class($audit_source, $class);
+ }
}
}