Class:...Loader(3pm)
πΈ NAME πΈ
okay so bestie, welcome to Class::DBI::Loader β it's the dynamic definition of Class::DBI sub classes π it lives in the User Contributed Perl Documentation section of the manual (3pm, iykyk).
β¨ SYNOPSIS β¨
no thoughts, just vibes and a loader:
use Class::DBI::Loader;
my $loader = Class::DBI::Loader->new(
dsn => "dbi:mysql:dbname",
user => "root",
password => "",
options => { RaiseError => 1, AutoCommit => 0 },
namespace => "Data",
additional_classes => qw/Class::DBI::AbstractSearch/, # or arrayref
additional_base_classes => qw/My::Stuff/, # or arrayref
left_base_classes => qw/Class::DBI::Sweet/, # or arrayref
constraint => '^foo.*',
relationships => 1,
options => { AutoCommit => 1 },
inflect => { child => 'children' },
require => 1
);
my $class = $loader->find_class('film'); # $class => Data::Film
my $obj = $class->retrieve(1);
(yes bestie, options shows up twice up there, that's literally how the page prints it, I'm not touching it π
)
now the mod_perl arc π§ β use with mod_perl:
in your startup.pl:
# load all tables
use Class::DBI::Loader;
my $loader = Class::DBI::Loader->new(
dsn => "dbi:mysql:dbname",
user => "root",
password => "",
namespace => "Data",
);
in your web application.
use strict;
# you can use Data::Film directly
my $film = Data::Film->retrieve($id);
π¦ DESCRIPTION π¦
Class::DBI::Loader automates the definition of Class::DBI sub-classes β it scans table schemas and sets up columns and the primary key for you. main character energy, fr fr π
class names are defined by table names and the namespace option, and here's the little chart so you can see it:
+-----------+-----------+-----------+
| table | namespace | class |
+-----------+-----------+-----------+
| foo | Data | Data::Foo |
| foo_bar | | FooBar |
+-----------+-----------+-----------+
Class::DBI::Loader supports MySQL, Postgres and SQLite π
also go see Class::DBI::Loader::Generic.
π METHODS π
new %args
all the little knobs and dials, bestie:
additional_base_classesβ a list of extra base classes your table classes are gonna use.left_base_classesβ a list of extra base classes that need to be leftmost, for example Class::DBI::Sweet (the former Catalyst::Model::CDBI::Sweet).additional_classesβ a list of extra classes that your table classes will use.constraintβ only load tables matching this regex πexcludeβ exclude tables matching this regex π«debugβ turn on debug messages.dsnβ the DBI Data Source Name.namespaceβ the namespace under which your table classes get initialized.passwordβ password. (yeah. that's it. that's the description π)optionsβ optional hashref to specify DBI connect options.relationshipsβ try to automatically detect/set uphas_aandhas_manyrelationships π«Άinflectβ a hashref containing exceptions toLingua::EN::Inflect::PL(). super useful for foreign language column names.userβ username.requireβ attempt torequirethe dynamically defined module, so that extensions defined in files work. by default, errors from imported modules are suppressed. when you wanna debug, userequire_warn.require_warnβ warn about import errors when requiring modules. π£
π AUTHOR π
Daisuke Maki <dmaki@cpan.org>
AUTHOR EMERITUS
Sebastian Riedel, <sri@oook.de> β IKEBE Tomohiro, <ikebe@edge.co.jp>
π THANK YOU π
Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, Randal Schwartz, Simon Flack and all the others who've helped. absolute legends, every single one π
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π SEE ALSO π
Class::DBI, Class::DBI::mysql, Class::DBI::Pg, Class::DBI::SQLite, Class::DBI::Loader::Generic, Class::DBI::Loader::mysql, Class::DBI::Loader::Pg, Class::DBI::Loader::SQLite
okay that's the whole page bestie, go forth and load some tables π β¨ this lil manual is perl v5.36.0, dated 2022-12-07, and it's filed under Class:...Loader(3pm) β mwah, periodt π«Άπ
π¦ where this page comes from
- debian bookworm: libclass-dbi-loader-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-dbi-loader-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-dbi-loader-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-dbi-loader-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-dbi-loader-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms