RoPkg::DBObject(3pm)
β¨ RoPkg::DBObject(3pm) β¨
okay bestie, this is the user-contributed Perl documentation for RoPkg::DBObject, and honestly? it's giving "the database object to end all database objects" π it's a manual page for a Perl module, it lives in section 3pm, and it's here to make your objects and your database hold hands. let's get into it π«Ά
π NAME π
RoPkg::DBObject β a general-purpose database object. that's it, that's the whole vibe: one object, one database, endless slay β¨
π VERSION π
0.1.4</purl> β wait no, 0.1.4 πΈ (tiny but mighty, fr fr)
π¦ DESCRIPTION π¦
so the way that this works: this class can be used as a base class for objects who keep all their info in a database. she provides the base methods to add/delete/update/select the object to/from a database. iconic behaviour honestly π₯
and yes, RoPkg::DBObject inherits RoPkg::Object. family tree matters π
π SYNOPSIS π
here's the whole thing, verbatim, no notes, because code is sacred π§
package RoPkg::Person;
use strict;
use warnings;
use RoPkg::DBObject;
use RoPkg::Exceptions;
use vars qw($VERSION @ISA);
@ISA=qw(RoPkg::DBObject);
my $methods = {
id => '-',
Name => '-',
Addr => '-',
};
sub new {
my ($class, %opt) = @_;
my $self;
$opt{methods} = $methods;
$self = $class->SUPER::new(%opt);
return $self;
}
sub AddToDB {
my ($self) = @_;
OutsideClass->throw('Called from outside class')
if ( !$self or ref($self) ne $CLASS);
return $self->SQL_Insert();
}
1;
tester.pl
use warnings;
use strict;
use RoPkg::Person;
use RoPkg::DB;
sub main {
my ($p, $db);
$db = new RoPkg::DB();
$db->add('dsn...', 'user', 'pass', 'dbc');
$p = new RoPkg::Person(dbo => $db, dbo_method => 'db_dbc');
$p->id(1);
$p->Name('John Doe');
$p->Addr('home');
$p->AddToDB();
}
main();
like, look at her. setting @ISA, building $methods, throwing OutsideClass when somebody tries to be slick and call it from outside the class. main character energy the entire time π
π SUBROUTINES/METHODS π
πΈ new($hashref) πΈ
the constructor of the class, the birth of the object, the origin story β¨ at this moment new() accepts 3 parameters:
dbodbo_methodquote_char
so dbo and dbo_method must be given to the constructor. quote_char is optional, she's chill.
dbois the database object (a instance ofRoPkg::DB) πΎdbo_methodis the name of the method used to have access to the database handle πquote_charis the char used internally by DBI to quote the table names, field names and so on. default: thequote_charis empty (no quotation, live your truth). but bestie listen β if you are using PostgreSQL and you have upcase chars in table and fields names, usequote_char => q{"}π
π«Ά Exceptions π«Ά
RoPkg::DBObject uses the exceptions provided by RoPkg::Exceptions. new() throws the following exceptions:
Param::Mising(sic β¨ that's literally how it's spelled in the list, no I will not fix it, the vibes are immaculate)Param::Wrong
Param::Missing is raised when dbo or dbo_method parameters have not been specified in the parameters list π
Param::Wrong is raised when dbo or dbo_method parameters are not defined (or empty) π
π¦ dbo($dbo) π¦
a get/set method, the classic dual-threat π
if $dbo is present (and defined), the internal $dbo object will be replaced with the new one. if $dbo is not present, the method acts as a get method, and will return the database object.
β οΈ the method will raise OutsideClass exception if is called outside the class instance. don't try it. she'll know. π
π dbo_method($dbo_method) π
another get/set method, she's consistent π
if $dbo_method is present (and defined), the internal $dbo_method value will be replaced with the one specified by the $dbo_method parameter. otherwise, the get behaviour will be selected, and the method will return the current value of $dbo_method.
β οΈ same deal: the method will raise OutsideClass exception if is called outside the class instance. boundaries, bestie π«Ά
β dbh() β
returns the DBI object used by this object. that's it, that's the whole method, short and slay πΈ
π₯ SQL METHODS π₯
these following methods are responsable for all operations involving the database. every single one of them uses SQL::Abstract to generate sql queries, so that the queries stay portable. no cap, that's the whole point π₯
and the data that will be added/deleted to the database is taken from the methods provided by $methods. iykyk π§
πΎ SQL_Insert() πΎ
add the current object to the database. returns the value of DBI->execute. π«Ά
π SQL_Update(@fields) π
update the data from database. the fields array hold all the field names who will uniquely identify the object in the database (usually the id of the object) π
π SQL_Delete(@fields) π
update the data from database. the fields array hold all the field names who will uniquely identify the object in the database (usually the id of the object) π (yes, the manpage says "update" here too β I'm just telling you what she said, don't shoot the messenger π)
π¦ SQL_Select(@fields) π¦
searches into the database for the object and initialize the current object with the values found. the fields array hold all the field names who will uniquely identify the object in the database (usually the id of the object).
this method is special β¨ she will look only at the first record who meet the requirements (in sql 'LIMIT 1'). also, if no records are found, DB::NoResults exception is raised. so like, expect drama if the row isn't there π
π§ DEPENDENCIES π§
RoPkg::Object require perl 5.008 or later and the following modules:
SQL::AbstractRoPkg::ObjectRoPkg::Exceptions
π PERL CRITIC π
the code is perl critic level 2 compliant and almost level 1 compliant. almost!! so close!! she's trying her best and honestly we stan a self-aware queen π
π DIAGNOSTICS π
this module comes with his own tests π§ͺ to run the tests, unpack the source, and use the 'make test' command. go off, verify her πΈ
π CONFIGURATION AND ENVIRONMENT π
this module does not use any configuration files or environment variables. the dependencies however can use them β so please read the man page of each dependency to be sure. do your homework bestie π«Ά
π¦ INCOMPATIBILITIES π¦
β οΈ Do not install this version on the same machine with Simba <= 0.7.1 β οΈ
like, literally do not. they cannot coexist. it's giving exes at the same party π
π BUGS AND LIMITATIONS π
none known to the author. iconic. flawless. no notes. (for now π)
π AUTHOR π
Subredu Manuel <diablo@iasi.roedu.net> β the legend behind the whole thing, thank you for your service π«‘
π LICENSE AND COPYRIGHT π
Copyright (C) 2005 Subredu Manuel. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. the LICENSE file contains the full text of the license π
okay that's the whole page bestie, you're officially educated π this was perl v5.32.1, dated 2021-12-26, and it's the manual page for RoPkg::DBObject(3pm) β go build something iconic with it πΈβ¨π¦
π¦ where this page comes from
- ubuntu jammy: libropkg-perl 0.4-1.4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms