Rose::DB::Object::Helpers - A mix-in class containing convenience methods for Rose::DB::Object.
package MyDBObject; use Rose::DB::Object; our @ISA = qw(Rose::DB::Object); use Rose::DB::Object::Helpers { load_or_insert => 'find_or_create' }); ... $obj = MyDBObject->new(id => 123); $obj->find_or_create();
Rose::DB::Object::Helpers provides convenience methods from use with Rose::DB::Object-derived classes. These methods do not exist in Rose::DB::Object in order to keep the method namespace clean. (Each method added to Rose::DB::Object is another potential naming conflict with a column accessor.)
This class inherits from Rose::DB::Object::MixIn. See the Rose::DB::Object::MixIn documentation for a full explanation of how to import methods from this class. The helper methods themselves are described below.
Try to load the object, passing PARAMS to the call to the load() method. The parameter "speculative => 1" is automatically added to PARAMS. If no such object is found, then the object is inserted.
Example:
# Get object id 123 if it exists, otherwise create it now. $obj = MyDBObject->new(id => 123)->load_or_insert;
Try to load the object, passing PARAMS to the call to the load() method along with the "speculative => 1" parameter. See the documentation for Rose::DB::Object's load method for more information.
$obj = MyDBObject->new(id => 123); if($obj->load_speculative) { print "Found object id 123\n"; } else { print "Object id 123 not found\n"; }
John C. Siracusa (siracusa@mindspring.com)
Copyright (c) 2006 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Rose::DB::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rose::DB::Object
CPAN shell
perl -MCPAN -e shell install Rose::DB::Object
For more information on module installation, please visit the detailed CPAN module installation guide.