DBIx::Class::SingletonRows - make database rows returned by DBIx::Class into singletons
When you do this with DBIx::Class:
my $row = $schema->... my $row2 = update_and_return(); sub update_and_return { my $row = $schema->... $row->somefield("HLAGH"); $row->update(); return $row; }
then even if both $row and $row2 have the same row_id, they'll have different values for somefield. This irritates me, so this mixin fixes it.
$row
$row2
somefield
When creating the class that respresents your table, load the 'SingletonRows' component thus. Make sure to load it before you load the 'Core' component:
package MyProject::DB::Employee; use base qw(DBIx::Class); __PACKAGE__->load_components(qw(SingletonRows Core)); __PACKAGE__->table('employees'); ...
It wraps around DBIx::Class::Row's inflate_result() method so that it always returns singletons.
DBIx::Class::Row
inflate_result()
This should be considered to be pre-production code. It's probably chock full of exciting data-eating bugs.
Written by David Cantrell <david@cantrell.org.uk>
Copyright 2008 Outcome Technologies Ltd
This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively.
To install DBIx::Class::SingletonRows, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::SingletonRows
CPAN shell
perl -MCPAN -e shell install DBIx::Class::SingletonRows
For more information on module installation, please visit the detailed CPAN module installation guide.