sub get_picture { my $self = shift; my %clauses = @_; my (@pictures, @params); my ($id, $user, $created, $title, $caption); my ($type, $category, $filename, $size); my ($width, $height); my $sql = " SELECT id, user, created, title, caption, category, type, filename, size, width, height FROM picture"; if (%clauses) { $sql .= " WHERE " . join " AND ", map { "$_ = ?" } sort keys %clauses; @params = map { $clauses{$_} } sort keys %clauses; } my $get = $self->dbh->prepare($sql); $get->execute(@params); $get->bind_columns( \( $id, $user, $created, $title, $caption, $category, $type, $filename, $size, $width, $height ) ); while ($get->fetchrow) { my $picture = new Phab::Picture ( id => $id, user => $user, created => $created, title => $title, caption => $caption, type => $self->get_type( id => $type ), category => $self->get_category( id => $category ), filename => $filename || "unknown", size => $size, width => $width || 0, height => $height || 0 ); push @pictures, $picture; } return wantarray ? @pictures : $pictures[0]; }