DBIx::...Method(3pm)
π DBIx::Class::Helper::Row::ProxyResultSetMethod π
okay so real talk, bestie β this page lives in User Contributed Perl Documentation, and the module's whole government name is DBIx::Class::Helper::Row::ProxyResultSetMethod. yes it's long. no we are not shortening it. it's iconic that way. π
β¨ NAME β¨
DBIx::Class::Helper::Row::ProxyResultSetMethod β reuse your ResultSet methods from your results, efficiently, and with a lil fallback safety net for when you forgot to set things up. π¦
πΈ SYNOPSIS πΈ
so here's the ResultSet situation, bestie:
package MyApp::Schema::ResultSet::Foo;
use parent 'DBIx::Class::ResultSet';
__PACKAGE__->load_components(qw(
Helper::ResultSet::CorrelateRelationship
));
...;
sub with_friend_count {
shift->search(undef, {
'+columns' => {
'friend_count' => $self->correlate('friends')->count_rs->as_query,
},
})
}
and here's the Result side, being all cute and delegating:
package MyApp::Schema::Result::Foo;
use parent 'DBIx::Class::Core';
__PACKAGE__->load_components(qw( Helper::Row::ProxyResultSetMethod ));
__PACKAGE__->proxy_resultset_method('friend_count');
or if you're a DBIx::Class::Candy girlie (and honestly? valid):
package MyApp::Schema::Result::Foo;
use DBIx::Class::Candy -components => ['Helper::Row::ProxyResultSetMethod'];
proxy_resultset_method 'friend_count';
and Elsewhere, where the magic actually happens:
my $row = $foo_rs->first;
say $row->friend_count . ' friends';
it just works. periodt. π
π DESCRIPTION π
okay so the whole point: this module makes reusing resultset methods from a result trivially easy. like, laughably easy. and honestly?
You should be using it.
that's not me being dramatic, that's the module being dramatic. it said it. I'm just the messenger. π
π METHODS π
π proxy_resultset_method π
the signature, verbatim, don't come for me:
__PACKAGE__->proxy_resultset_method( $name => {
slot => $slot,
resultset_method => $rs_method
});
okay so let's break it down, bestie:
- the first argument is
$nameβ that's the name of the method we're generating. it is required. no name, no method, no vibes. π - the other two,
$slotand$resultset_method, are optional. yes queen, optional. - if you don't say anything,
$slotdefaults to$name, and$resultset_methoddefaults to"with_$name". cute, right? $slotis the column that the data being retrieved is stored as, inside the ResultSet method you're proxying to.$resultset_methodis (duh) the ResultSet method being proxied to.
and here's the part that's giving main character energy: if you did not call the "with_*" method on your ResultSet, and then you call the proxy method, it will transparently fallback and do the call itself and fetch the needed data. E.g.:
my $foo = $schema->resultset('Foo')->first; ## did not call with_friend_count
print $foo->friend_count; ## will produce desired result magically
magically. the manpage said magically. I'm just quoting. β¨
π CANDY EXPORTS π
if you use this component alongside DBIx::Class::Candy, it will export:
proxy_resultset_method
that's it. that's the whole export list. short and sweet, we love her. π
π§ DEDICATION π§
this module is dedicated to Ray Bradbury, who wrote Something Wicked This Way Comes, Dandelion Wine, and numerous short stories, plays, etc etc. Read this author's books.
like, actually read them. that's a direct instruction from the module. πβ¨
β 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 π«Ά β brought to you by perl v5.40.0, dated 2024-11-16, and yes the footer does say DBIx::...Method(3pm) because even the manpage header got tired of typing the whole name. slay. π
πΈ
π¦ 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