[Bast-commits] r8744 - in DBIx-Class-Journal/1.000/tags: .
0.900001_03 0.900001_03/lib/DBIx/Class
0.900001_03/lib/DBIx/Class/Journal 0.900001_03/lib/DBIx/Class/Schema
0.900001_03/lib/DBIx/Class/Schema/Journal
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Thu Feb 18 20:36:23 GMT 2010
Author: frew
Date: 2010-02-18 20:36:21 +0000 (Thu, 18 Feb 2010)
New Revision: 8744
Added:
DBIx-Class-Journal/1.000/tags/0.900001_03/
DBIx-Class-Journal/1.000/tags/0.900001_03/Changes
DBIx-Class-Journal/1.000/tags/0.900001_03/Makefile.PL
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal.pm
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal/EvalWrap.pm
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal.pm
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal/DB.pm
Removed:
DBIx-Class-Journal/1.000/tags/0.900001_03/Changes
DBIx-Class-Journal/1.000/tags/0.900001_03/Makefile.PL
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal.pm
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal/EvalWrap.pm
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal.pm
DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal/DB.pm
Log:
tag for latest dev release
Copied: DBIx-Class-Journal/1.000/tags/0.900001_03 (from rev 8737, DBIx-Class-Journal/1.000/trunk)
Deleted: DBIx-Class-Journal/1.000/tags/0.900001_03/Changes
===================================================================
--- DBIx-Class-Journal/1.000/trunk/Changes 2010-02-17 23:27:39 UTC (rev 8737)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/Changes 2010-02-18 20:36:21 UTC (rev 8744)
@@ -1,33 +0,0 @@
-0.900001_02
- - The one time I forget to run disttest, the MANIFEST file mysteriously
- disappears... *sigh*
-
-0.900001_01
- - insert records a history row as well
- - SQL::Translator is required to run the test suite
- - Add EvalWrap subclass, that suppressed errors and warns instead, useful
- for when having no errors is preferable over partial journal data
- - various refactoring
- - correct journalling of recreated data (data with a primary key that
- previously existed)
- - update to DBIx::Class's versioning scheme
-
-0.02_01 2008-07-30
- - deployment at connect time is disabled by default, set journal_auto_deploy to reenable
- - $main_schema->deploy deploys the journalling tables too
- - support multi column primary keys
- - rename Change to ChangeLog to avoid conflict with mysql reserved word
- - fix schema composition when sharing connection
- - support for nested transactions (produce one changeset, but support stubs
- for nested changesets in place)
- - removed dummy table
- - various other cleanups
- - calling current_changeset outside of txn_do is fatal
- - fix 'now()' default value, timestamp happens in perl space instead
- - also call txn_do on the journal schema if the storage object differs
- - don't call txn_begin twice
-
-0.01 2007-08-11:
-Initial version
-
-
Copied: DBIx-Class-Journal/1.000/tags/0.900001_03/Changes (from rev 8743, DBIx-Class-Journal/1.000/trunk/Changes)
===================================================================
--- DBIx-Class-Journal/1.000/tags/0.900001_03/Changes (rev 0)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/Changes 2010-02-18 20:36:21 UTC (rev 8744)
@@ -0,0 +1,43 @@
+0.900001_03 2010-02-18
+ - Journal schema is now in it's own virtual package instead of being in
+ DBIx::Class::Schema::Journal::DB so a user should be able to have
+ multiple journals without them mingling
+ - No longer depend on Test::TempDir so this should build on windows
+ - Use Class::C3::Componentised instead of DBIx::Class::Componentised
+ - Fixed syntax error in SYNOPSIS
+ - Lots of cleanup (deleting unused files, commented out code, etc)
+ - Switched to Module::Install instead of EU::MM
+
+0.900001_02
+ - The one time I forget to run disttest, the MANIFEST file mysteriously
+ disappears... *sigh*
+
+0.900001_01
+ - insert records a history row as well
+ - SQL::Translator is required to run the test suite
+ - Add EvalWrap subclass, that suppressed errors and warns instead, useful
+ for when having no errors is preferable over partial journal data
+ - various refactoring
+ - correct journalling of recreated data (data with a primary key that
+ previously existed)
+ - update to DBIx::Class's versioning scheme
+
+0.02_01 2008-07-30
+ - deployment at connect time is disabled by default, set journal_auto_deploy to reenable
+ - $main_schema->deploy deploys the journalling tables too
+ - support multi column primary keys
+ - rename Change to ChangeLog to avoid conflict with mysql reserved word
+ - fix schema composition when sharing connection
+ - support for nested transactions (produce one changeset, but support stubs
+ for nested changesets in place)
+ - removed dummy table
+ - various other cleanups
+ - calling current_changeset outside of txn_do is fatal
+ - fix 'now()' default value, timestamp happens in perl space instead
+ - also call txn_do on the journal schema if the storage object differs
+ - don't call txn_begin twice
+
+0.01 2007-08-11:
+Initial version
+
+
Deleted: DBIx-Class-Journal/1.000/tags/0.900001_03/Makefile.PL
===================================================================
--- DBIx-Class-Journal/1.000/trunk/Makefile.PL 2010-02-17 23:27:39 UTC (rev 8737)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/Makefile.PL 2010-02-18 20:36:21 UTC (rev 8744)
@@ -1,27 +0,0 @@
-use inc::Module::Install 0.89;
-use strict;
-use warnings;
-
-use 5.008001;
-
-# ****** DO NOT ADD OPTIONAL DEPENDENCIES. EVER. --mst ******
-
-name 'DBIx-Class-Journal';
-perl_version '5.008001';
-all_from 'lib/DBIx/Class/Journal.pm';
-
-
-test_requires 'Test::More' => '0.94';
-test_requires 'DBD::SQLite' => '1.29';
-test_requires 'SQL::Translator' => '0.1103'; # we'll make this optional for release
-
-requires 'DBIx::Class' => '0.08115';
-requires 'Class::C3::Componentised' => '1.0006';
-
-tests_recursive ('t');
-
-resources 'license' => 'http://dev.perl.org/licenses/';
-resources 'repository' => 'http://dev.catalyst.perl.org/repos/bast/DBIx-Class-Journal/';
-
-WriteAll();
-
Copied: DBIx-Class-Journal/1.000/tags/0.900001_03/Makefile.PL (from rev 8743, DBIx-Class-Journal/1.000/trunk/Makefile.PL)
===================================================================
--- DBIx-Class-Journal/1.000/tags/0.900001_03/Makefile.PL (rev 0)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/Makefile.PL 2010-02-18 20:36:21 UTC (rev 8744)
@@ -0,0 +1,27 @@
+use inc::Module::Install 0.89;
+use strict;
+use warnings;
+
+use 5.008001;
+
+# ****** DO NOT ADD OPTIONAL DEPENDENCIES. EVER. --mst ******
+
+name 'DBIx-Class-Journal';
+perl_version '5.008001';
+all_from 'lib/DBIx/Class/Journal.pm';
+
+
+test_requires 'Test::More' => '0.94';
+test_requires 'DBD::SQLite' => '1.29';
+test_requires 'SQL::Translator' => '0.11003'; # we'll make this optional for release
+
+requires 'DBIx::Class' => '0.08115';
+requires 'Class::C3::Componentised' => '1.0006';
+
+tests_recursive ('t');
+
+resources 'license' => 'http://dev.perl.org/licenses/';
+resources 'repository' => 'http://dev.catalyst.perl.org/repos/bast/DBIx-Class-Journal/';
+
+WriteAll();
+
Deleted: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal/EvalWrap.pm
===================================================================
--- DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal/EvalWrap.pm 2010-02-17 23:27:39 UTC (rev 8737)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal/EvalWrap.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -1,46 +0,0 @@
-#!/usr/bin/perl
-
-package DBIx::Class::Journal::EvalWrap;
-use base qw(DBIx::Class::Journal);
-
-use strict;
-use warnings;
-
-foreach my $method qw(journal_log_update journal_log_insert journal_log_delete) {
- local $@;
- eval "sub $method " . ' {
- my ( $self, @args ) = @_;
- local $@;
- eval { $self->next::method(@args) };
- warn $@ if $@;
- }; 1' || warn $@;
-}
-
-__PACKAGE__
-
-__END__
-
-=pod
-
-=head1 NAME
-
-DBIx::Class::Journal::EvalWrap - Wrap all journal ops with an eval { }
-
-=head1 SYNOPSIS
-
- __PACKAGE__->journal_component("Journal::EvalWrap");
-
-=head1 DESCRIPTION
-
-This component is a wrapper for the row methods in L<DBIx:Class::Journal> that
-aides in retrofitting a schema for journaling, by wrapping all the journal CRUD
-operations with a C<local $@; eval { ... }}.
-
-This is desirable if you'd rather lose journal data than create runtime errors
-when retrofitting existing code.
-
-Use with caution.
-
-=cut
-
-
Copied: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal/EvalWrap.pm (from rev 8740, DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal/EvalWrap.pm)
===================================================================
--- DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal/EvalWrap.pm (rev 0)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal/EvalWrap.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -0,0 +1,44 @@
+package DBIx::Class::Journal::EvalWrap;
+use base qw(DBIx::Class::Journal);
+
+use strict;
+use warnings;
+
+foreach my $method qw(journal_log_update journal_log_insert journal_log_delete) {
+ local $@;
+ eval "sub $method " . ' {
+ my ( $self, @args ) = @_;
+ local $@;
+ eval { $self->next::method(@args) };
+ warn $@ if $@;
+ }; 1' || warn $@;
+}
+
+__PACKAGE__
+
+__END__
+
+=pod
+
+=head1 NAME
+
+DBIx::Class::Journal::EvalWrap - Wrap all journal ops with an eval { }
+
+=head1 SYNOPSIS
+
+ __PACKAGE__->journal_component("Journal::EvalWrap");
+
+=head1 DESCRIPTION
+
+This component is a wrapper for the row methods in L<DBIx:Class::Journal> that
+aides in retrofitting a schema for journaling, by wrapping all the journal CRUD
+operations with a C<local $@; eval { ... }}.
+
+This is desirable if you'd rather lose journal data than create runtime errors
+when retrofitting existing code.
+
+Use with caution.
+
+=cut
+
+
Deleted: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal.pm
===================================================================
--- DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm 2010-02-17 23:27:39 UTC (rev 8737)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -1,252 +0,0 @@
-package DBIx::Class::Journal;
-
-use base qw/DBIx::Class/;
-
-use strict;
-use warnings;
-
-our $VERSION = '0.900001_02';
-$VERSION = eval $VERSION; # no errors in dev versions
-
-## On create/insert, add new entry to AuditLog
-
-sub _journal_schema {
- my $self = shift;
- $self->result_source->schema->_journal_schema;
-}
-
-sub insert
-{
- my ($self, @args) = @_;
-
- return if($self->in_storage);
-
- my $res = $self->next::method(@args);
-
- $self->journal_log_insert();
-
- return $res;
-}
-
-sub journal_log_insert
-{
- my ($self) = @_;
-
- if ( $self->in_storage ) {
- my $j = $self->_journal_schema;
- my $change_id = $j->journal_create_change()->id;
- $j->journal_update_or_create_log_entry( $self, create_id => $change_id );
- $j->journal_record_in_history( $self, audit_change_id => $change_id );
- }
-}
-
-## On delete, update delete_id of AuditLog
-
-sub delete
-{
- my ($self, @rest) = @_;
- $self->next::method(@rest);
- $self->journal_log_delete(@rest);
-}
-
-sub journal_log_delete
-{
- my ($self) = @_;
-
- unless ($self->in_storage) {
- my $j = $self->_journal_schema;
- $j->journal_update_or_create_log_entry( $self, delete_id => $j->journal_create_change->id );
- }
-}
-
-## 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 journal_log_update
-{
- my ($self, $upd, @rest) = @_;
-
- if($self->in_storage)
- {
- my $j = $self->_journal_schema;
-
- my $change = $j->journal_create_change;
- my $prev = $self->result_source->resultset->find( $self->ident_condition );
- $j->journal_record_in_history( $prev, audit_change_id => $change );
- }
-}
-
-=head1 NAME
-
-DBIx::Class::Journal - auditing for tables managed by DBIx::Class
-
-=head1 SYNOPSIS
-
- package My::Schema;
- use base 'DBIx::Class::Schema';
-
- __PACKAGE__->load_components(qw/Schema::Journal/);
-
- __PACKAGE__->journal_connection(['dbi:SQLite:t/var/Audit.db']);
- __PACKAGE__->journal_user(['My::Schema::User', {'foreign.userid' => 'self.user_id'}]);
-
-
- #######
-
- $schema->changeset_user($user->id);
- my $new_artist = $schema->txn_do( sub {
- return $schema->resultset('Artist')->create({ name => 'Fred' });
- });
-
-
-=head1 DESCRIPTION
-
-The purpose of this L<DBIx::Class> component module is to create an
-audit-trail for all changes made to the data in your database (via a
-DBIx::Class schema). It creates changesets and assigns each
-create/update/delete operation an id. The creation and deletion date
-of each row is stored, as well as the previous contents of any row
-that gets changed.
-
-All queries which need auditing must be called using
-L<DBIx::Class::Schema/txn_do>, which is used to create changesets for
-each transaction.
-
-To track who did which changes, the user_id (an integer) of the
-current user can be set, a session_id can also be set, both are
-optional.
-
-To access the auditing schema to look at the auditdata or revert a
-change, use C<< $schema->_journal_schema >>.
-
-=head2 TABLES
-
-The journal schema contains a number of tables.
-
-=over
-
-=item ChangeSet
-
-Each changeset row has an auto-incremented ID, optional user_id and
-session_id, and a set_date which defaults to the current datetime.
-
-A ChangeSet has_many Changes.
-
-=item ChangeLog
-
-Each change/operation done in the transaction is recorded as a row in
-the ChangeLog table. It contains an auto-incrementing ID, the
-changeset_id and an order column for the ordering of each change in
-the changeset.
-
-=item AuditLog
-
-For every table in the original database that is to be audited, an
-AuditLog table is created. Each auditlog row has an id which will
-contain the primary key of the table it is associated with. (NB:
-currently only supports integer-based single column PKs). The
-create_id and delete_id fields contain the IDs of the Changes that
-created or deleted this row.
-
-=item AuditHistory
-
-For every table in the original database to be audited, an
-AuditHistory table is created. Each row has a change_id field
-containing the ID of the ChangeLog row. The other fields correspond to
-all the fields from the original table. Each time a column value in
-the original table is changed, the entire row contents before the
-change are added as a new row in this table.
-
-=back
-
-=head2 METHODS
-
-=over
-
-=item journal_connection \@connect_info
-
-Set the connection information for the database to save your audit
-information to.
-
-Leaving this blank assumes you want to store the audit data into your current
-database. The storage object will be shared by the regular schema and the
-journalling schema.
-
-=item journal_sources \@source_names
-
-Set a list of source names you would like to audit, if unset, all
-sources are used.
-
-NOTE: Currently only sources with a single-column PK are supported, so
-use this method if you have sources with multi-column PKs.
-
-=item journal_storage_type $type
-
-Enter the special storage type of your journal schema if needed. See
-L<DBIx::Class::Storage::DBI> for more information on storage types.
-
-=item journal_user \@rel
-
-The user_id column in the L</ChangeSet> will be linked to your user id
-with a belongs_to relation, if this is set with the appropriate
-arguments.
-
-=item journal_deploy_on_connect $bool
-
-If set to a true value will cause C<journal_schema_deploy> to be called on
-C<connect>.
-
-Not reccomended, but present for backwards compatibility.
-
-=item changeset_user $user_id
-
-Set the user_id for the following changeset(s). This must be an integer.
-
-=item changeset_session $session_id
-
-Set the session_id for the following changeset(s). This must be an integer.
-
-=item txn_do $code_ref, @args
-
-Overloaded L<DBIx::Class::Schema/txn_do>, this must be used to start a
-new changeset to cover a group of changes. Each subsequent change to
-an audited table will use the changeset_id created in the most recent
-txn_do call.
-
-Currently nested C<txn_do> calls cause a single ChangeSet object to be created.
-
-=back
-
-=head1 SEE ALSO
-
-L<DBIx::Class> - You'll need it to use this.
-
-=head1 NOTES
-
-Only single-column integer primary key'd tables are supported for auditing so far.
-
-Updates made via L<DBIx::Class::ResultSet/update> are not yet supported.
-
-No API for viewing or restoring changes yet.
-
-Patches for the above welcome ;)
-
-=head1 AUTHOR
-
-Jess Robinson <castaway at desert-island.me.uk>
-
-Matt S. Trout <mst at shadowcatsystems.co.uk> (ideas and prodding)
-
-=head1 LICENCE
-
-You may distribute this code under the same terms as Perl itself.
-
-=cut
-
-1;
Copied: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal.pm (from rev 8743, DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm)
===================================================================
--- DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal.pm (rev 0)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Journal.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -0,0 +1,245 @@
+package DBIx::Class::Journal;
+
+use base qw/DBIx::Class/;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.900001_03';
+$VERSION = eval $VERSION; # no errors in dev versions
+
+## On create/insert, add new entry to AuditLog
+
+sub _journal_schema {
+ my $self = shift;
+ $self->result_source->schema->_journal_schema;
+}
+
+sub insert {
+ my ($self, @args) = @_;
+
+ return if $self->in_storage;
+
+ my $res = $self->next::method(@args);
+
+ $self->journal_log_insert;
+
+ return $res;
+}
+
+sub journal_log_insert {
+ my ($self) = @_;
+
+ if ( $self->in_storage ) {
+ my $j = $self->_journal_schema;
+ my $change_id = $j->journal_create_change()->id;
+ $j->journal_update_or_create_log_entry( $self, create_id => $change_id );
+ $j->journal_record_in_history( $self, audit_change_id => $change_id );
+ }
+}
+
+## On delete, update delete_id of AuditLog
+
+sub delete {
+ my $self = shift;
+ $self->next::method(@_);
+ $self->journal_log_delete(@_);
+}
+
+sub journal_log_delete {
+ my ($self) = @_;
+
+ unless ($self->in_storage) {
+ my $j = $self->_journal_schema;
+ $j->journal_update_or_create_log_entry( $self, delete_id => $j->journal_create_change->id );
+ }
+}
+
+## On update, copy previous row's contents to AuditHistory
+
+sub update {
+ my $self = shift;
+ $self->journal_log_update(@_);
+ $self->next::method(@_);
+}
+
+sub journal_log_update {
+ my $self = shift;
+
+ if($self->in_storage) {
+ my $j = $self->_journal_schema;
+
+ my $change = $j->journal_create_change;
+ my $prev = $self->result_source->resultset->find( $self->ident_condition );
+ $j->journal_record_in_history( $prev, audit_change_id => $change );
+ }
+}
+
+=head1 NAME
+
+DBIx::Class::Journal - auditing for tables managed by DBIx::Class
+
+=head1 SYNOPSIS
+
+ package My::Schema;
+ use base 'DBIx::Class::Schema';
+
+ __PACKAGE__->load_components(qw/Schema::Journal/);
+
+ __PACKAGE__->journal_connection(['dbi:SQLite:t/var/Audit.db']);
+ __PACKAGE__->journal_user(['My::Schema::User', {'foreign.userid' => 'self.user_id'}]);
+
+
+ #######
+
+ $schema->changeset_user($user->id);
+ my $new_artist = $schema->txn_do( sub {
+ return $schema->resultset('Artist')->create({ name => 'Fred' });
+ });
+
+
+=head1 DESCRIPTION
+
+The purpose of this L<DBIx::Class> component module is to create an
+audit-trail for all changes made to the data in your database (via a
+DBIx::Class schema). It creates changesets and assigns each
+create/update/delete operation an id. The creation and deletion date
+of each row is stored, as well as the previous contents of any row
+that gets changed.
+
+All queries which need auditing must be called using
+L<DBIx::Class::Schema/txn_do>, which is used to create changesets for
+each transaction.
+
+To track who did which changes, the user_id (an integer) of the
+current user can be set, a session_id can also be set, both are
+optional.
+
+To access the auditing schema to look at the auditdata or revert a
+change, use C<< $schema->_journal_schema >>.
+
+=head2 TABLES
+
+The journal schema contains a number of tables.
+
+=over
+
+=item ChangeSet
+
+Each changeset row has an auto-incremented ID, optional user_id and
+session_id, and a set_date which defaults to the current datetime.
+
+A ChangeSet has_many Changes.
+
+=item ChangeLog
+
+Each change/operation done in the transaction is recorded as a row in
+the ChangeLog table. It contains an auto-incrementing ID, the
+changeset_id and an order column for the ordering of each change in
+the changeset.
+
+=item AuditLog
+
+For every table in the original database that is to be audited, an
+AuditLog table is created. Each auditlog row has an id which will
+contain the primary key of the table it is associated with. (NB:
+currently only supports integer-based single column PKs). The
+create_id and delete_id fields contain the IDs of the Changes that
+created or deleted this row.
+
+=item AuditHistory
+
+For every table in the original database to be audited, an
+AuditHistory table is created. Each row has a change_id field
+containing the ID of the ChangeLog row. The other fields correspond to
+all the fields from the original table. Each time a column value in
+the original table is changed, the entire row contents before the
+change are added as a new row in this table.
+
+=back
+
+=head2 METHODS
+
+=over
+
+=item journal_connection \@connect_info
+
+Set the connection information for the database to save your audit
+information to.
+
+Leaving this blank assumes you want to store the audit data into your current
+database. The storage object will be shared by the regular schema and the
+journalling schema.
+
+=item journal_sources \@source_names
+
+Set a list of source names you would like to audit, if unset, all
+sources are used.
+
+NOTE: Currently only sources with a single-column PK are supported, so
+use this method if you have sources with multi-column PKs.
+
+=item journal_storage_type $type
+
+Enter the special storage type of your journal schema if needed. See
+L<DBIx::Class::Storage::DBI> for more information on storage types.
+
+=item journal_user \@rel
+
+The user_id column in the L</ChangeSet> will be linked to your user id
+with a belongs_to relation, if this is set with the appropriate
+arguments.
+
+=item journal_deploy_on_connect $bool
+
+If set to a true value will cause C<journal_schema_deploy> to be called on
+C<connect>.
+
+Not reccomended, but present for backwards compatibility.
+
+=item changeset_user $user_id
+
+Set the user_id for the following changeset(s). This must be an integer.
+
+=item changeset_session $session_id
+
+Set the session_id for the following changeset(s). This must be an integer.
+
+=item txn_do $code_ref, @args
+
+Overloaded L<DBIx::Class::Schema/txn_do>, this must be used to start a
+new changeset to cover a group of changes. Each subsequent change to
+an audited table will use the changeset_id created in the most recent
+txn_do call.
+
+Currently nested C<txn_do> calls cause a single ChangeSet object to be created.
+
+=back
+
+=head1 SEE ALSO
+
+L<DBIx::Class> - You'll need it to use this.
+
+=head1 NOTES
+
+Only single-column integer primary key'd tables are supported for auditing so far.
+
+Updates made via L<DBIx::Class::ResultSet/update> are not yet supported.
+
+No API for viewing or restoring changes yet.
+
+Patches for the above welcome ;)
+
+=head1 AUTHOR
+
+Jess Robinson <castaway at desert-island.me.uk>
+
+Matt S. Trout <mst at shadowcatsystems.co.uk> (ideas and prodding)
+
+=head1 LICENCE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut
+
+1;
Deleted: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal/DB.pm
===================================================================
--- DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal/DB.pm 2010-02-17 23:27:39 UTC (rev 8737)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal/DB.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -1,82 +0,0 @@
-package DBIx::Class::Schema::Journal::DB;
-
-use base 'DBIx::Class::Schema';
-
-__PACKAGE__->mk_classdata('nested_changesets');
-__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));
-
-require DBIx::Class::Schema::Journal::DB::AuditLog;
-require DBIx::Class::Schema::Journal::DB::AuditHistory;
-
-sub _current_changeset {
- my $self = shift;
- my $ref = $self->_current_changeset_container;
- $ref && $ref->{changeset};
-}
-
-# this is for localization of the current changeset
-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;
-
- my $id = $self->_current_changeset;
-
- $self->throw_exception("Can't call current_changeset outside of a transaction") unless $id;
-
- return $id;
-}
-
-sub journal_create_changeset {
- my ( $self, @args ) = @_;
-
- my %changesetdata = ( @args, ID => undef );
-
- delete $changesetdata{parent_id} unless $self->nested_changesets;
-
- if( defined( my $user = $self->current_user() ) )
- {
- $changesetdata{user_id} = $user;
- }
- if( defined( my $session = $self->current_session() ) )
- {
- $changesetdata{session_id} = $session;
- }
-
- ## Create a new changeset, then run $code as a transaction
- my $cs = $self->resultset('ChangeSet');
-
- $cs->create({ %changesetdata });
-}
-
-sub journal_create_change {
- my $self = shift;
- $self->resultset("ChangeLog")->create({ changeset_id => $self->current_changeset });
-}
-
-sub journal_update_or_create_log_entry
-{
- my ($self, $row, @cols) = @_;
-
- my $s_name = $row->result_source->source_name;
-
- my %id = map { $_ => $row->get_column($_)} $row->primary_columns;
-
- $self->resultset("${s_name}AuditLog")->update_or_create({ @cols, %id });
-}
-
-sub journal_record_in_history
-{
- my ($self, $row, @cols) = @_;
-
- my $s_name = $row->result_source->source_name;
-
- $self->resultset("${s_name}AuditHistory")->create({ $row->get_columns, @cols });
-}
-
-
-1;
Copied: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal/DB.pm (from rev 8742, DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal/DB.pm)
===================================================================
--- DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal/DB.pm (rev 0)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal/DB.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -0,0 +1,84 @@
+package DBIx::Class::Schema::Journal::DB;
+
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->mk_classdata('nested_changesets');
+__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));
+
+require DBIx::Class::Schema::Journal::DB::AuditLog;
+require DBIx::Class::Schema::Journal::DB::AuditHistory;
+
+sub _current_changeset {
+ my $self = shift;
+ my $ref = $self->_current_changeset_container;
+ $ref && $ref->{changeset};
+}
+
+# this is for localization of the current changeset
+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;
+
+ my $id = $self->_current_changeset;
+
+ $self->throw_exception(
+ q{Can't call current_changeset outside of a transaction}
+ ) unless $id;
+
+ return $id;
+}
+
+sub journal_create_changeset {
+ my ( $self, @args ) = @_;
+
+ my %changesetdata = ( @args, ID => undef );
+
+ delete $changesetdata{parent_id} unless $self->nested_changesets;
+
+ if( defined( my $user = $self->current_user() ) ) {
+ $changesetdata{user_id} = $user;
+ }
+ if( defined( my $session = $self->current_session() ) ) {
+ $changesetdata{session_id} = $session;
+ }
+
+ ## Create a new changeset, then run $code as a transaction
+ my $cs = $self->resultset('ChangeSet');
+
+ $cs->create({ %changesetdata });
+}
+
+sub journal_create_change {
+ my $self = shift;
+ $self->resultset('ChangeLog')->create({
+ changeset_id => $self->current_changeset
+ });
+}
+
+sub journal_update_or_create_log_entry {
+ my ($self, $row, @cols) = @_;
+
+ my $s_name = $row->result_source->source_name;
+
+ my %id = map { $_ => $row->get_column($_)} $row->primary_columns;
+
+ $self->resultset("${s_name}AuditLog")->update_or_create({ @cols, %id });
+}
+
+sub journal_record_in_history {
+ my ($self, $row, @cols) = @_;
+
+ my $s_name = $row->result_source->source_name;
+
+ $self->resultset("${s_name}AuditHistory")->create({ $row->get_columns, @cols });
+}
+
+
+1;
Deleted: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal.pm
===================================================================
--- DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal.pm 2010-02-17 23:27:39 UTC (rev 8737)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -1,190 +0,0 @@
-package DBIx::Class::Schema::Journal;
-
-use base qw/DBIx::Class/;
-
-use Scalar::Util 'blessed';
-use DBIx::Class::Schema::Journal::DB;
-use Class::C3::Componentised ();
-
-__PACKAGE__->mk_classdata('journal_storage_type');
-__PACKAGE__->mk_classdata('journal_connection');
-__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');
-
-use strict;
-use warnings;
-
-
-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;
-
- 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(@_);
-
- 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);
- }
- $journal_schema->connection(@{ $self->journal_connection });
- } else {
- $journal_schema->storage( $schema->storage );
- }
-
- $self->_journal_schema($journal_schema);
-
-
- 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";
- }
-
- $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 || []})
- {
- #warn "No Journal User set!"; # no need to warn, user_id is useful even without a rel
- return $schema;
- }
-
- $self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user});
- $self->_journal_schema->storage->disconnect();
-
- return $schema;
-}
-
-sub deploy
-{
- my ( $self, $sqlt_args, @args ) = @_;
-
- $self->next::method($sqlt_args, @args);
-
- $self->journal_schema_deploy($sqlt_args, @args);
-}
-
-sub journal_schema_deploy
-{
- my ( $self, $sqlt_args, @args ) = @_;
-
- $self->_journal_schema->deploy( $sqlt_args, @args );
-}
-
-sub create_journal_for
-{
- my ($self, $s_name, $journal_schema) = @_;
-
- my $source = $self->source($s_name);
-
- foreach my $audit (qw(AuditLog AuditHistory)) {
- my $audit_source = $s_name.$audit;
- my $class = blessed($journal_schema) . "::$audit_source";
-
- Class::C3::Componentised->inject_base($class, "DBIx::Class::Schema::Journal::DB::$audit");
-
- $class->journal_define_table($source);
-
- $journal_schema->register_class($audit_source, $class);
-
- if ($self->journal_copy_sources)
- {
- $self->register_class($audit_source, $class);
- }
- }
-}
-
-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 )
- {
- my $current_changeset_ref = $jschema->_current_changeset_container;
-
- unless ( $current_changeset_ref ) {
- # this is a hash because scalar refs can't be localized
- $current_changeset_ref = { };
- $jschema->_current_changeset_container($current_changeset_ref);
- }
-
- # wrap the thunk with a new changeset creation
- $code = sub {
- my $changeset = $jschema->journal_create_changeset( parent_id => $current_changeset );
- local $current_changeset_ref->{changeset} = $changeset->id;
- $user_code->(@_);
- };
-
- }
-
- if ( $jschema->storage != $self->storage ) {
- my $inner_code = $code;
- $code = sub { $jschema->txn_do($inner_code, @_) };
- }
-
- return $self->next::method($code, @args);
-}
-
-sub changeset_user
-{
- my ($self, $userid) = @_;
-
- return $self->_journal_schema->current_user() if(@_ == 1);
-
- $self->_journal_schema->current_user($userid);
-}
-
-sub changeset_session
-{
- my ($self, $sessionid) = @_;
-
- return $self->_journal_schema->current_session() if(@_ == 1);
-
- $self->_journal_schema->current_session($sessionid);
-}
-
-
-1;
Copied: DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal.pm (from rev 8742, DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal.pm)
===================================================================
--- DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal.pm (rev 0)
+++ DBIx-Class-Journal/1.000/tags/0.900001_03/lib/DBIx/Class/Schema/Journal.pm 2010-02-18 20:36:21 UTC (rev 8744)
@@ -0,0 +1,174 @@
+package DBIx::Class::Schema::Journal;
+
+use base qw/DBIx::Class/;
+
+use Scalar::Util 'blessed';
+use DBIx::Class::Schema::Journal::DB;
+use Class::C3::Componentised ();
+
+__PACKAGE__->mk_classdata('journal_storage_type');
+__PACKAGE__->mk_classdata('journal_connection');
+__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');
+
+use strict;
+use warnings;
+
+
+sub _journal_schema_prototype {
+ my $self = shift;
+ 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 $comp = $self->journal_component || "Journal";
+
+ ## 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 => $proto);
+ $self->class($s_name)->load_components($comp);
+ }
+ return $proto;
+}
+
+sub connection {
+ my $self = shift;
+ my $schema = $self->next::method(@_);
+
+ my $journal_schema = (ref $self||$self)->_journal_schema_prototype->clone;
+
+ 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 );
+ }
+
+ $self->_journal_schema($journal_schema);
+
+
+ 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';
+ }
+
+ $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 || []}) {
+ #warn "No Journal User set!"; # no need to warn, user_id is useful even without a rel
+ return $schema;
+ }
+
+ $self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user});
+ $self->_journal_schema->storage->disconnect();
+
+ return $schema;
+}
+
+sub deploy {
+ my $self = shift;
+
+ $self->next::method(@_);
+
+ $self->journal_schema_deploy(@_);
+}
+
+sub journal_schema_deploy {
+ my $self = shift;
+
+ $self->_journal_schema->deploy(@_);
+}
+
+sub create_journal_for {
+ my ($self, $s_name, $journal_schema) = @_;
+
+ my $source = $self->source($s_name);
+
+ foreach my $audit (qw(AuditLog AuditHistory)) {
+ my $audit_source = $s_name.$audit;
+ my $class = blessed($journal_schema) . "::$audit_source";
+
+ Class::C3::Componentised->inject_base($class, "DBIx::Class::Schema::Journal::DB::$audit");
+
+ $class->journal_define_table($source);
+
+ $journal_schema->register_class($audit_source, $class);
+
+ $self->register_class($audit_source, $class)
+ if $self->journal_copy_sources;
+ }
+}
+
+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 ) {
+ my $current_changeset_ref = $jschema->_current_changeset_container;
+
+ unless ( $current_changeset_ref ) {
+ # this is a hash because scalar refs can't be localized
+ $current_changeset_ref = { };
+ $jschema->_current_changeset_container($current_changeset_ref);
+ }
+
+ # wrap the thunk with a new changeset creation
+ $code = sub {
+ my $changeset = $jschema->journal_create_changeset( parent_id => $current_changeset );
+ local $current_changeset_ref->{changeset} = $changeset->id;
+ $user_code->(@_);
+ };
+
+ }
+
+ if ( $jschema->storage != $self->storage ) {
+ my $inner_code = $code;
+ $code = sub { $jschema->txn_do($inner_code, @_) };
+ }
+
+ return $self->next::method($code, @args);
+}
+
+sub changeset_user {
+ my ($self, $userid) = @_;
+
+ return $self->_journal_schema->current_user()
+ if @_ == 1;
+
+ $self->_journal_schema->current_user($userid);
+}
+
+sub changeset_session {
+ my ($self, $sessionid) = @_;
+
+ return $self->_journal_schema->current_session()
+ if @_ == 1;
+
+ $self->_journal_schema->current_session($sessionid);
+}
+
+
+1;
More information about the Bast-commits
mailing list