Rose::DB::Object::MakeMethods::Std(3pm) | User Contributed Perl Documentation | Rose::DB::Object::MakeMethods::Std(3pm) |
Rose::DB::Object::MakeMethods::Std - Create object methods related to Rose::DB::Object::Std-derived objects.
package Category; our @ISA = qw(Rose::DB::Object::Std); ... package Color; our @ISA = qw(Rose::DB::Object::Std); ... package Product; our @ISA = qw(Rose::DB::Object); ... use Rose::DB::Object::MakeMethods::Std ( object_by_id => [ color => { class => 'Color' }, category => { class => 'Category', id_method => 'cat_id', share_db => 0, }, ], ); ... $prod = Product->new(...); $color = $prod->color; # $prod->color call is roughly equivalent to: # # $color = Color->new(id => $prod->color_id, # db => $prod->db); # $ret = $color->load; # return $ret unless($ret); # return $color; $cat = $prod->category; # $prod->category call is roughly equivalent to: # # $cat = Category->new(id => $prod->cat_id); # $ret = $cat->load; # return $ret unless($ret); # return $cat;
"Rose::DB::Object::MakeMethods::Std" creates methods related to Rose::DB::Object::Std-derived objects. It inherits from Rose::Object::MakeMethods. See the Rose::Object::MakeMethods documentation to learn about the interface. The method types provided by this module are described below.
All method types defined by this module are designed to work with objects that are subclasses of (or otherwise conform to the interface of) Rose::DB::Object. In particular, the object is expected to have a "db" method that returns a Rose::DB-derived object. See the Rose::DB::Object::Std documentation for more details.
If passed a single argument of undef, the "hash_key" used to store the object is set to undef. Otherwise, the argument is assumed to be an object of type "class" and is assigned to "hash_key" after having its primary key set to the corresponding value in the current object.
If called with no arguments and the "hash_key" used to store the object is defined, the object is returned. Otherwise, the object is created and loaded.
The load may fail for several reasons. The load will not even be attempted if the primary key attribute in the current object is undefined. Instead, undef will be returned. If the call to the newly created object's "load" method returns false, that false value is returned.
If the load succeeds, the object is returned.
Example:
package Category; our @ISA = qw(Rose::DB::Object::Std); ... package Color; our @ISA = qw(Rose::DB::Object::Std); ... package Product; our @ISA = qw(Rose::DB::Object); ... use Rose::DB::Object::MakeMethods::Std ( object_by_id => [ color => { class => 'Color' }, category => { class => 'Category', id_method => 'cat_id', share_db => 0, }, ], ); ... $prod = Product->new(...); $color = $prod->color; # $prod->color call is roughly equivalent to: # # $color = Color->new(id => $prod->color_id, # db => $prod->db); # $ret = $color->load; # return $ret unless($ret); # return $color; $cat = $prod->category; # $prod->category call is roughly equivalent to: # # $cat = Category->new(id => $prod->cat_id); # $ret = $cat->load; # return $ret unless($ret); # return $cat;
John C. Siracusa (siracusa@gmail.com)
Copyright (c) 2010 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.
2022-10-14 | perl v5.34.0 |