NAME
DBIx::Class::Row::Delta - Keep track of and report on changes to a DBIC row object.
DESCRIPTION
Record an initial set of values for a DBIC row, and later on get a string with the changed values.
SYNOPSIS
use DBIx::Class::Row::Delta;
my $book = $book_rs->find(321);
my $book_notes_delta = DBIC::Row::Delta->new({
dbic_row => $book,
changes_sub => sub {
my ($row) = @_;
return {
"Book Type" => $row->book_type->type,
"Book Title" => $row->book_title->title // "N/A",
"Delivery Date" => $row->delivery_date->ymd,
};
},
});
# ...
# Do stuff to $book, ->update(), etc.
# ...
# Note: this will discard_changes on $book.
my $changes_string = $book_notes_delta->changes;
# e.g.
# Book SKU (1933021-002 => 1933023-001), Delivery Date (2012-01-18 => 2012-01-22)
METHODS
new({ $dbic_row!, &$changes_sub! }) : $new_object | die
Create a new object. Start by taking a snapshot of the contents of $dbic_row by calling $changes_sub->($dbic_row).
The sub ref $changes_sub should return a hash ref with keys and values that describe the state of the object. If the values look weird when stringified, you're responsible for formatting them properly. All the hash ref values should be strings or undef.
Both dbic_row and changes_sub are required.
changes() : $delta_string | undef
Return a string representation of the diff between the initial snapshot and the current state of $dbic_row, or return undef if they are the same. Only the changed values are reported.
Example:
Book SKU (1933021-002 => 1933023-001), Delivery Date (2012-01-18 => 2012-01-22)
Note: This will start by calling $dbic_row->discard to refresh the data properly.
BUGS
Please report any bugs or feature requests to bug-dbix-class-row-delta at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-Row-Delta. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc DBIx::Class::Row::Delta
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-Row-Delta
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
CONTRIBUTE
The source for this module is on GitHub: https://github.com/jplindstrom/p5-DBIx-Class-Row-Delta
Patches welcome, etc.
AUTHOR
Johan Lindstrom - johanl@cpan.org
on behalf of Net-A-Porter - http://www.net-a-porter.com/
LICENSE AND COPYRIGHT
Copyright 2012- Net-A-Porter.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
ACKNOWLEDGEMENTS
Thanks to Net-A-Porter for providing time during one of the regular Hack-days.