[Bast-commits] r4725 - in DBIx-Class-Preview/1.000/trunk:
lib/DBIx/Class lib/DBIx/Class/Schema t/lib t/var
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Sat Aug 2 14:35:06 BST 2008
Author: lukes
Date: 2008-08-02 14:35:06 +0100 (Sat, 02 Aug 2008)
New Revision: 4725
Modified:
DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm
DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm
DBIx-Class-Preview/1.000/trunk/t/lib/DBICTest.pm
DBIx-Class-Preview/1.000/trunk/t/var/DBIxClass.db
Log:
wrote some docs and did some cleanup
Modified: DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm
===================================================================
--- DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm 2008-08-02 11:51:58 UTC (rev 4724)
+++ DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm 2008-08-02 13:35:06 UTC (rev 4725)
@@ -5,16 +5,112 @@
use Storable ();
use base qw/DBIx::Class/;
+=head1 VERSION
+
+Version 1.001000
+
+=cut
+
+our $VERSION = '1.001000';
+
=head1 NAME
-=head1 VERSION
+DBIx::Class::Preview
-Version 1.000
+=head1 SYNOPSIS
+Add component to schema class.
+
+ package MyApp::Schema;
+
+ __PACKAGE__->load_components(qw/Schema::Preview/);
+
+ ...
+
+Add component to result class.
+
+ package MyApp::Schema::Artist;
+
+__PACKAGE__->load_components('Preview');
+
+ ...
+
+And then elsewhere..
+
+ # turn on preview mode
+ $schema->preview_active(1);
+
+ # update a row of a previewed class
+ my $row = $schema->resultset('Artist')->create({ name => 'luke' });
+
+ # publish changes to live tables
+ $schema->publish();
+
+=head1 DESCRIPTION
+
+When preview mode is active, all reads and writes to the previewed sources are redirected to a preview table.
+When L</publish> is called, these changes are synced to the live table from the previewed table.
+
+You will need to set these additional preview tables up yourself - see L</SETUP>.
+
+A typical use of this would be for preview mode to be active for moderators for a website but not for normal users.
+The moderators would make changes as they see fit then when happy with them they can 'publish' those changes.
+
+=head1 SETUP
+
+For each table to be previewed, a separate table needs to be set up which has the same columns as the original
+table and also two extra columns - 'dirty' and 'deleted'. Also, these extra tables need to be populated
+with the rows from the original table before they can be used. For example, to setup a preview table for an
+'artist' table in MySQL, you might use the following SQL:
+
+ CREATE TABLE artist_preview LIKE artist;
+ ALTER TABLE artist_preview ADD COLUMN dirty TINYINT NOT NULL DEFAULT 0;
+ ALTER TABLE artist_preview ADD COLUMN deleted TINYINT NOT NULL DEFAULT 0;
+ INSERT INTO artist_preview (SELECT *, 0, 0 FROM artist);
+
+Or in SQLite:
+
+ CREATE TABLE artist_preview (
+ artistid INTEGER PRIMARY KEY NOT NULL,
+ name varchar(100),
+ dirty INTEGER DEFAULT '0',
+ deleted INTEGER DEFAULT '0'
+ );
+ insert into artist_preview select *, 0, 0 from artist;
+
+=head1 SCHEMA METHODS
+
+=head2 preview_active
+
+Accessor to activate or deactivate preview mode. Setting this to 0 will cause reads and writes to go to the
+original sources and 1 will cause the previewed sources.
+
+=head2 publish
+
+Copies all 'dirty' changes from the previewed sources to the original sources. Essentially this means finding and
+deleting all rows from the original table that are marked as deleted in the previewed table and finding and updating
+all rows from the original table with the columns from the rows marked as dirty in the previewed tables.
+
+=head2 ISSUES
+
+- Updating a row in the original source will not cause the change to be made to the previewed source as well.
+ Patches welcome to handle this behaviour, though beware of clashes with unpublished changes to the previewed rows.
+
+- Using the resultset methods 'update' and 'delete' will go uncaught by this module - what will happen is that
+ the previewed rows will be updated but will not be marked as dirty or deleted. You should use update_all or delete_all
+ instead or alternatively send a patch
+
+- You have to create the previewed tables. Some people might find it preferable for the module to provide a method to
+ do it for you. But it doesn't yet.
+
+=head2 BUGS / CONTRIBUTING
+
+The best way is to email the DBIx::Class mailing list (http://lists.scsys.co.uk/mailman/listinfo/dbix-class/)
+with a description and/or patch (against svn trunk - http://dev.catalyst.perl.org/repos/bast/DBIx-Class-Preview/1.000/trunk/).
+Alternatively email the author directly or use RT.
+
=cut
-our $VERSION = '1.000';
-
__PACKAGE__->mk_group_accessors( 'simple' => qw/_current_partition/ );
sub table {
@@ -68,4 +164,20 @@
return $self->next::method(@_);
}
+=head1 AUTHOR
+
+ Luke Saunders <luke.saunders at gmail.com>
+
+ Initial development sponsored by and (c) Takkle, Inc. 2007
+
+=head1 CONTRIBUTORS
+
+ Eden Cardim <eden at shadowcatsystems.co.uk>
+
+=head1 LICENSE
+
+ This library is free software under the same license as perl itself
+
+=cut
+
1;
Modified: DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm
===================================================================
--- DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm 2008-08-02 11:51:58 UTC (rev 4724)
+++ DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm 2008-08-02 13:35:06 UTC (rev 4725)
@@ -56,6 +56,7 @@
my $original_row = $original_rs->find($dirty_row->id);
my %dirty_cols = $dirty_row->get_columns;
delete $dirty_cols{dirty};
+ delete $dirty_cols{deleted};
if ($original_row) {
$original_row->update(\%dirty_cols);
Modified: DBIx-Class-Preview/1.000/trunk/t/lib/DBICTest.pm
===================================================================
--- DBIx-Class-Preview/1.000/trunk/t/lib/DBICTest.pm 2008-08-02 11:51:58 UTC (rev 4724)
+++ DBIx-Class-Preview/1.000/trunk/t/lib/DBICTest.pm 2008-08-02 13:35:06 UTC (rev 4725)
@@ -103,7 +103,6 @@
my $schema = shift;
my $file = shift;
- warn $file;
open IN, $file;
my $sql;
{ local $/ = undef; $sql = <IN>; }
Modified: DBIx-Class-Preview/1.000/trunk/t/var/DBIxClass.db
===================================================================
(Binary files differ)
More information about the Bast-commits
mailing list