RoPkg:...lection(3pm)
RoPkg::DBCollection π
okay bestie, so this is a page from the User Contributed Perl Documentation set, and the module in question is RoPkg::DBCollection β the base class you use when you want a whole collection of database objects, not just one lonely little row. π¦
β¨ NAME β¨
RoPkg::DBCollection β it's the base class you can use for collections of database objects. periodt.
πΈ VERSION πΈ
0.1.3 β yes, a real version number, she's official π
π DESCRIPTION π
So RoPkg::DBCollection is a class you use as a base class for a database collection of objects. Like, it's the blueprint, not the building. ποΈ
It's already being used by RoPkg::Simba::Mirrors, RoPkg::Simba::Commands and RoPkg::Simba::Excludes. Iconic trio honestly.
β οΈ Important vibe check: this class should not be used directly in your applications β it should be derived. She's the mother, not the main character. Do not instantiate her raw, bestie, I'm begging. π
π§ SUBROUTINES/METHODS π§
new()
The class constructor. She accepts a hash with parameters, and the parameters you can pass in are:
dboβ a database object (an instance ofRoPkg::DB)dbo_methodβ a database method (for use withRoPkg::DB)tableβ the sql table name where the objects' data can be found
π¨ If you don't specify thedboanddbo_methodparameters, aParam::Missingexception gets raised. Not optional, bestie, not a suggestion.
dbh()
returns the database handler (DBI object) used by the class. that's it, that's the whole method. short queen. π
_count($fields)
Returns the number of records who match the fields specified in $fields.
This method should be overriden by the child classes β like, it's your job now, she's handing you the mic. π€
The $fields must be specified in SQL::Abstract format. Please refer to the SQL::Abstract documentation for more details about the $fields format. (go read it, iykyk π)
_get($class_name, $fields, $order_by)
Returns a array of initialized objects. The values are read from the database. β¨
$class_nameis the name of the class who's gonna be instanciated. When creating the class instance,dboanddbo_methodparameters are passed to thenew()method.- The records from the database must match the
$fieldsparameter, and the order is given by$order_by. For more details of these 2 parameters please refer toSQL::Abstractdocumentation.
Exceptions throwed:
Param::Missingβ when$class_namehas not been specifiedParam::Wrongβ when$class_nameis not a class nameDB::NoResultsβ when the query returned 0 results
π SYNOPSIS π
here's the whole thing, verbatim, because code is sacred:
package RoPkg::Tester;
use strict;
use warnings;
use Scalar::Util qw(blessed);
use RoPkg::Exceptions;
use RoPkg::DBCollection;
use vars qw(@ISA);
@ISA=qw(RoPkg::DBCollection);
sub new {
my ($class, %opt) = @_;
my $self;
$self = $class->SUPER::new(%opt);
$self->{table} = 'Mirrors';
return $self;
}
sub Count {
my ($self) = @_;
if (!blessed($self)) {
OutsideClass->throw(
error => 'Called outside class instance',
pkg_name => 'RoPkg::Tester',
);
}
return $self->_count();
}
sub Get {
my ($self, $fields) = @_;
if (!blessed($self)) {
OutsideClass->throw(
error => 'Called outside class instance',
pkg_name => 'RoPkg::Tester'
);
}
return $self->_get('RoPkg::Simba::Mirror');
}
1;
sub main {
my ($dbc, $dbp);
$dbp = new RoPkg::DB();
$dbp->Add(
'dbi:mysql:database=mirrors_db;host=localhost',
'root',
'',
'mirrors'
);
$dbc = new RoPkg::Tester(
dbo => $dbp,
dbo_method => 'db_mirrors'
);
print $dbc->Count(),$/;
my @mirrors = $dbc->Get();
}
main();
like, look at her go. subclasses, SUPER::new, blessed checks, the whole little ecosystem. she ate. π₯
π©Ί DIAGNOSTICS π©Ί
This module comes with tests. To run them, unpack the source and use make test command. π»
π PERL CRITIC π
This modules is perlcritic level 2 compliant (with 1 exception). one tiny exception, we don't talk about her. π
βοΈ CONFIGURATION AND ENVIRONMENT βοΈ
This module does not use any configuration files or environment variables. π
However, it is possible that some dependencies to do so. Please read the man page of each dependency to find out more information. (yes, go read those too, bestie, do your homework π)
π§© DEPENDENCIES π§©
This module use the following modules:
SQL::AbstractDBIScalar::UtilRoPkg
π« INCOMPATIBILITIES π«
None known to the author. π (as in, nothing to report, not as in, dead)
π BUGS AND LIMITATIONS π
None known to the author. flawless behavior honestly, no cap. β¨
π SEE ALSO π
RoPkg::Exceptions RoPkg::DB RoPkg::DBObject RoPkg::Simba::Mirrors
go read the whole family, they're all connected. π«Ά
π AUTHOR π
Subredu Manuel <diablo@iasi.roedu.net> β thank you for your service, king π«‘
π LICENSE AND COPYRIGHT π
Copyright (C) 2006 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. π
and that's the whole page, bestie!! π
this one's perl v5.32.1, dated 2021-12-26, and it lives in the RoPkg:...lection(3pm) corner of the manual universe β love that for her πβ¨ mwah, go write a subclass, you got this π¦
π¦ 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