NAME
DBIx::Squirrel::Result - the base class of the rows a result set hands out
SYNOPSIS
my $results = $dbh->results('SELECT id, Name FROM artist');
while (my($artist) = $results->next) {
say $artist->id, ' ', $artist->name;
}
DESCRIPTION
A DBIx::Squirrel::Results hands out each row as an array, blessed into a class with a method for each column. Each method is named as its column is, in lower case. The class is a subclass of this one. Or it's a subclass of the class given as the ekorn_result_class attribute, which must itself be a subclass of this one. That class can give rows methods of their own:
package My::Artist {
our @ISA = 'DBIx::Squirrel::Result';
sub shout ($self) { return uc $self->name }
}
my $results = $dbh->results($sql, {ekorn_result_class => 'My::Artist'});
There's one class for each base class and list of column names. It's made the first time a result set fetches rows with those columns, and kept, so a row can be kept after its result set has gone.
A column gets no method if its name can't be a method's, such as count(*). Nor does it if the base class already has a method of that name, such as can, isa or get_column, or one of its own. When two columns have one name, as in SELECT a.id, b.id, the method is the first's. "get_column" reaches every column.
To give such a column a method, give it another name in the statement, with AS:
my $row = $dbh->results(
'SELECT COUNT(*) AS total, class AS kind, b.id AS b_id FROM ...'
)->single;
say $row->total, ' ', $row->kind, ' ', $row->b_id;
METHODS
get_column
$value = $row->get_column($name);
$value = $row->get_column($position);
Returns a column's value, by its name, in any case, or by its position, from 0, as the row is an array.
class_for
For DBIx::Squirrel::Results, which makes the row classes. It's not for use elsewhere.
DIAGNOSTICS
- Expected a column of the row (%s)
-
"get_column" was given a name or a position the row doesn't have.
SEE ALSO
AUTHOR
Iain Campbell <cpanic@cpan.org>
LICENSE
Copyright (c) 2024-2026 by Iain Campbell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.