use Getopt::Long; use MyCompany::Schema::LogEntry; GetOptions( $opts, 'help|h','man','verbose+', 'quiet', 'dbic_dsn=s', 'dbic_user=s', 'dbic_password=s', 'db_table=s', ) or pod2usage(-verbose=>0, -message => "incorrect options"); # Change the log table to the real one. MyCompany::Schema::LogEntry->table( $opts->{'db_table'} ); my $log_schema = MyCompany::Schema->connect( @{$opts}{'dbic_dsn','dbic_user','dbic_password'} ) my $matching_log_RS = $log_schema->resultset('LogEntry')->search({%searchTerms}); print $matching_log_RS->as_query();