# -*- Perl -*- use strict; use warnings; package Newstats::Fred_by_this; use Foo::DBI::Fred; use base 'Newstats'; Foo::DBI::Fred->set_sql(by_this => <<".EOSQL"); SELECT this,nvl(that(*),0) as tot FROM __TABLE(=r)__, __TABLE(Foo::DBI::Barney=n)__ WHERE status='cool' AND r.quux=n.quux AND (tstamp between ? AND ?) GROUP BY this .EOSQL sub new { my $rf=Foo::DBI::Fred->sql_by_this; Newstats->new( action => sub { my $caller=shift; $rf->execute(@_) or $caller->complain("Error executing sql_by_this() method."); $rf->fetchall_arrayref; }, other_param => 'something else' ); } 1; __END__