[Dbix-class] DBIx::Class::ResultSet / resolve_prefetch() / Use of uninitialized value in pattern match

Chisel Wright chisel at herlpacker.co.uk
Fri Aug 1 09:37:57 BST 2008


On Thu, Jul 31, 2008 at 09:22:56PM +0100, Matt S Trout wrote:
> I've never seen a case where it is - do you have "normal" code that causes
> that warning?

I don't know if this is "normal" but we have this in our codebase:

---- cut here ----
package XTracker::Schema::Product::ListItem;

# ... DBIC stuff

sub prefetch_columns {
    my ($resultset, $prefetch_clause) = @_;
    my $source = $resultset->result_source;

    my @columns = $source->resolve_prefetch(
        $prefetch_clause
    );

    my @column_names =
        map (
            "me.$_",
            $source->columns()
        );

    push @column_names,
        map (
            $_->[0],
            @columns
        );

    return \@column_names;
}
---- cut here ----

Which we use as:

---- cut here ----
    if (defined $attrs->{prefetch}) {
        $attrs->{group_by} = prefetch_columns(
            $self,
            $attrs->{prefetch}
        );
    }
---- cut here ----

I can't remember the exact reasoning for this, I think it was "I'm sure
we can work out what to put in the group-by instead of copying and
pasting it all over the place".

If it's wrong, stupid, etc, please let me know why/how.

Cheers,

Chiz
-- 
Chisel Wright
e: chisel at herlpacker.co.uk
w: http://www.herlpacker.co.uk/

  When good is dumb, evil will always triumph.



More information about the DBIx-Class mailing list