DBIx::...Missing(3pm)
πΈ DBIx::Class::Helper::Row::OnColumnMissing πΈ
okay bestie, so this is a page from User Contributed Perl Documentation for DBIx::Class::Helper::Row::OnColumnMissing, and no, the module name isn't broken β the man page title is literally DBIx::...Missing(3pm) because long names are rude to terminal widths π
β¨ NAME β¨
DBIx::Class::Helper::Row::OnColumnMissing β configurable handling for when you go reaching for a column that justβ¦ isn't there π
π SYNOPSIS π
so you drop this into your Result class, like:
package MyApp::Schema::Result::Account;
use parent 'DBIx::Class::Core';
__PACKAGE__->load_components(qw(Helper::Row::OnColumnMissing));
__PACKAGE__->table('Account');
__PACKAGE__->add_columns(
id => {
data_type => 'integer',
is_auto_increment => 1,
},
name => {
data_type => 'varchar',
size => 25,
},
book => { data_type => 'text' },
);
sub on_column_missing { 'die' }
1;
or, if you're a DBIx::Class::Candy girlie π:
package MyApp::Schema::Result::Account;
use DBIx::Class::Candy -components => ['Helper::Row::OnColumnMissing'];
table 'Account';
column id => {
data_type => 'integer',
is_auto_increment => 1,
};
column amount => {
data_type => 'float',
keep_storage_value => 1,
};
column book => { data_type => 'text' };
sub on_column_missing { 'die' }
1;
and then somewhere else entirely:
my $row = $rs->search(undef, { columns => [qw( id name )] })->one_row;
$row->book # dies
yeah. $row->book just dies. dramatic? absolutely. correct? also yes π
π¦ DESCRIPTION π¦
okay so here's the vibe: this module exists to handle that one specific cursed situation where you limited which columns got pulled from the database, and then you β or more likely future you β accidentally touched one of the ones you didn't grab. classic.
the way it works is fully configurable: you just tweak whatever the "on_column_missing" method returns. that's it. that's the whole knob. π
π MODES π
you pick your "mode" by returning that "mode" from the "on_column_missing" method. and the default "mode" it returns? that's "warn". so out of the box it's gonna yell at you, not end you.
the predefined modes are, in all their glory:
"die"β dies with"Column $name has not been loaded""warn"β warns with"Column $name has not been loaded""nothing"β does nothing. literally nothing. iconic behaviour honestly
and bestie, you can go further: predefine more modes by defining methods named "on_column_$mode", and you can even override the default modes by overriding the corresponding methods. if you need something ad-hoc, just return a code reference and that gets called as a method on the object. slay β¨
π ADVANCED USAGE π
if for some reason you find that you need to change your "mode" at runtime β chaotic, but valid β you can always replace the "on_column_missing" with an accessor. for example:
__PACKAGE__->mk_group_accessors(inherited => 'on_column_missing');
__PACKAGE__->on_column_missing('warn');
and elsewhere:
$row->on_column_missing('die');
and if you are especially crazy you could even do something like this:
$row->on_column_missing(sub {
my ($self, $column) = @_;
$self
->result_source
->resultset
->search({ id => $self->id })
->get_column($column)
->single
});
though if you do that, I would make it a named mode. maybe "retrieve"? just a thought π«Ά
πΈ THANKS πΈ
big love to ZipRecruiter <https://www.ziprecruiter.com> for funding the development of this module. paying for open source dev? that's main character energy fr fr π
π AUTHOR π
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie β no cap, every flag, mode, method and code snippet made it through intact. this one's from perl v5.40.0, dated 2024-11-16, and it's filed under that iconically truncated DBIx::...Missing(3pm) name. go forth and warn responsibly π
β¨
π¦ where this page comes from
- debian trixie: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdbix-class-helpers-perl 2.037000-1 Β· 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