$self->result_source->schema->_journal_schema;
}
-sub insert
-{
+sub insert {
my ($self, @args) = @_;
- return if($self->in_storage);
+ return if $self->in_storage;
my $res = $self->next::method(@args);
- $self->journal_log_insert();
+ $self->journal_log_insert;
return $res;
}
-sub journal_log_insert
-{
+sub journal_log_insert {
my ($self) = @_;
if ( $self->in_storage ) {
## On delete, update delete_id of AuditLog
-sub delete
-{
- my ($self, @rest) = @_;
- $self->next::method(@rest);
- $self->journal_log_delete(@rest);
+sub delete {
+ my $self = shift;
+ $self->next::method(@_);
+ $self->journal_log_delete(@_);
}
-sub journal_log_delete
-{
+sub journal_log_delete {
my ($self) = @_;
unless ($self->in_storage) {
## On update, copy previous row's contents to AuditHistory
-sub update
-{
- my ($self, $upd, @rest) = @_;
- $self->journal_log_update($upd, @rest);
- $self->next::method($upd, @rest);
+sub update {
+ my $self = shift;
+ $self->journal_log_update(@_);
+ $self->next::method(@_);
}
-sub journal_log_update
-{
- my ($self, $upd, @rest) = @_;
+sub journal_log_update {
+ my $self = shift;
- if($self->in_storage)
- {
+ if($self->in_storage) {
my $j = $self->_journal_schema;
my $change = $j->journal_create_change;
use warnings;
-sub _journal_schema_prototype
-{
+sub _journal_schema_prototype {
my $self = shift;
- if (my $proto = $self->__journal_schema_prototype)
- {
+ if (my $proto = $self->__journal_schema_prototype) {
return $proto;
}
my $c = blessed($self)||$self;
my $journal_schema_class = "${c}::_JOURNAL";
Class::C3::Componentised->inject_base($journal_schema_class, 'DBIx::Class::Schema::Journal::DB');
- my $proto = $self->__journal_schema_prototype
- (
- $journal_schema_class->compose_namespace
- (
- $c.'::Journal'
- )
+ my $proto = $self->__journal_schema_prototype (
+ $journal_schema_class->compose_namespace( $c.'::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;
+ ? @{$self->journal_sources}
+ : $self->sources;
- foreach my $s_name ($self->sources)
- {
+ 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
-{
+sub connection {
my $self = shift;
my $schema = $self->next::method(@_);
my $journal_schema = (ref $self||$self)->_journal_schema_prototype->clone;
- if($self->journal_connection)
- {
- if($self->journal_storage_type)
- {
- $journal_schema->storage_type($self->journal_storage_type);
- }
+ if($self->journal_connection) {
+ $journal_schema->storage_type($self->journal_storage_type)
+ if $self->journal_storage_type;
$journal_schema->connection(@{ $self->journal_connection });
} else {
$journal_schema->storage( $schema->storage );
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";
+ die 'FIXME nested changeset schema not yet supported... add parent_id to ChangeSet here';
}
$self->journal_schema_deploy()
if $self->journal_deploy_on_connect;
## Set up relationship between changeset->user_id and this schema's user
- if(!@{$self->journal_user || []})
- {
+ if(!@{$self->journal_user || []}) {
#warn "No Journal User set!"; # no need to warn, user_id is useful even without a rel
return $schema;
}
return $schema;
}
-sub deploy
-{
- my ( $self, $sqlt_args, @args ) = @_;
+sub deploy {
+ my $self = shift;
- $self->next::method($sqlt_args, @args);
+ $self->next::method(@_);
- $self->journal_schema_deploy($sqlt_args, @args);
+ $self->journal_schema_deploy(@_);
}
-sub journal_schema_deploy
-{
- my ( $self, $sqlt_args, @args ) = @_;
+sub journal_schema_deploy {
+ my $self = shift;
- $self->_journal_schema->deploy( $sqlt_args, @args );
+ $self->_journal_schema->deploy(@_);
}
-sub create_journal_for
-{
+sub create_journal_for {
my ($self, $s_name, $journal_schema) = @_;
my $source = $self->source($s_name);
$journal_schema->register_class($audit_source, $class);
- if ($self->journal_copy_sources)
- {
- $self->register_class($audit_source, $class);
- }
+ $self->register_class($audit_source, $class)
+ if $self->journal_copy_sources;
}
}
-sub txn_do
-{
+sub txn_do {
my ($self, $user_code, @args) = @_;
my $jschema = $self->_journal_schema;
my $code = $user_code;
my $current_changeset = $jschema->_current_changeset;
- if ( !$current_changeset || $self->journal_nested_changesets )
- {
+ if ( !$current_changeset || $self->journal_nested_changesets ) {
my $current_changeset_ref = $jschema->_current_changeset_container;
unless ( $current_changeset_ref ) {
return $self->next::method($code, @args);
}
-sub changeset_user
-{
+sub changeset_user {
my ($self, $userid) = @_;
- return $self->_journal_schema->current_user() if(@_ == 1);
+ return $self->_journal_schema->current_user()
+ if @_ == 1;
$self->_journal_schema->current_user($userid);
}
-sub changeset_session
-{
+sub changeset_session {
my ($self, $sessionid) = @_;
- return $self->_journal_schema->current_session() if(@_ == 1);
+ return $self->_journal_schema->current_session()
+ if @_ == 1;
$self->_journal_schema->current_session($sessionid);
}
sub current_changeset {
my ( $self, @args ) = @_;
- $self->throw_exception("setting current_changeset is not supported, use txn_do to create a new changeset") if @args;
+ $self->throw_exception(
+ 'setting current_changeset is not supported, use txn_do to create a new changeset'
+ ) if @args;
my $id = $self->_current_changeset;
- $self->throw_exception("Can't call current_changeset outside of a transaction") unless $id;
+ $self->throw_exception(
+ q{Can't call current_changeset outside of a transaction}
+ ) unless $id;
return $id;
}
delete $changesetdata{parent_id} unless $self->nested_changesets;
- if( defined( my $user = $self->current_user() ) )
- {
+ if( defined( my $user = $self->current_user() ) ) {
$changesetdata{user_id} = $user;
}
- if( defined( my $session = $self->current_session() ) )
- {
+ if( defined( my $session = $self->current_session() ) ) {
$changesetdata{session_id} = $session;
}
sub journal_create_change {
my $self = shift;
- $self->resultset("ChangeLog")->create({ changeset_id => $self->current_changeset });
+ $self->resultset('ChangeLog')->create({
+ changeset_id => $self->current_changeset
+ });
}
-sub journal_update_or_create_log_entry
-{
+sub journal_update_or_create_log_entry {
my ($self, $row, @cols) = @_;
my $s_name = $row->result_source->source_name;
$self->resultset("${s_name}AuditLog")->update_or_create({ @cols, %id });
}
-sub journal_record_in_history
-{
+sub journal_record_in_history {
my ($self, $row, @cols) = @_;
my $s_name = $row->result_source->source_name;