Rose::...s::Std(3pm)
πΈ NAME πΈ
Rose::DB::Object::MakeMethods::Std β creates object methods related to Rose::DB::Object::Std-derived objects. You're on the Rose::...s::Std(3pm) page, part of the User Contributed Perl Documentation, and yes bestie, we're gonna get through all of it together π«Ά
β¨ SYNOPSIS β¨
Okay so picture this: you've got a few classes and you want make-method magic. The whole setup goes a lil like this:
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;
π DESCRIPTION π
Okay so Rose::DB::Object::MakeMethods::Std creates methods related to Rose::DB::Object::Std-derived objects. It inherits from Rose::Object::MakeMethods β no cap, that's the parent vibe. Peep the Rose::Object::MakeMethods documentation to learn about the interface, bestie. The method types this module serves up are described below, periodt.
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, iykyk.
π§ METHODS TYPES π§
π« object_by_id π«
Creates get/set methods for a single Rose::DB::Object::Std-derived object loaded based on a primary key stored in an attribute of the current object. Main character energy: the object gets fetched by id.
π Options π
classβ the name of theRose::DB::Object::Std-derived class of the object to be loaded. This option is required, so don't forget it bestie.hash_keyβ the key inside the hash-based object to use for the storage of the object. Defaults to the name of the method.id_methodβ the name of the method that contains the primary key of the object to be loaded. Defaults to the method name concatenated with"_id".interfaceβ choose the interface. The only current interface is"get_set", which is the default.share_dbβ if true, thedbattribute of the current object is shared with the object loaded. Defaults to true.
π¦ Interfaces π¦
get_setβ creates a method that will attempt to create and load aRose::DB::Object::Std-derived object based on a primary key stored in an attribute of the current object.
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 πΈ
Same energy as the synopsis, but here's the example recipe in full:
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;
π AUTHOR π
John C. Siracusa (siracusa@gmail.com) β the icon who wrote this. π
π LICENSE π
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.
β¨ Cute sign-off: this page is from perl v5.40.1, dated 2025-08-21 β now go load those objects and slay, bestie! π
π
π¦ where this page comes from
- ubuntu resolute: librose-db-object-perl 1:0.822-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: librose-db-object-perl 1:0.822-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms