blazar has asked for the wisdom of the Perl Monks concerning the following question:
At work we have a whole infrastructure built mainly around CDBI for what regards db interface. I'm fairly new to it, but with the help of the developers here I'm managing my way through it.
I'm doing some statistics, generally involving joins, and I wrote a generic base class Newstats which accepts, as "main" parameter a subref to be used as a callback. Then I subclass it so that the typical module for a specific statistic may look like this:
# -*- 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__
(code trimmed down to a bare minimum and names changed for convenience)
Now I have many such modules and I thought: what could possibly happen if I call set_sql() on the same class and with the same $sql_name (in the terminology of the docs) as I've already done? I searched with Google, which brough up pages like Using joins - ClassDBI none of which really cleared my perplexities. So I conjured up a quick experiment and I see that CDBI doesn't complain, and I guess it just redefines the method. I would prefer the former alternative instead. I also checked the documentation, to no avail, or maybe the answer is just in front of me and I just fail to see it...
So, to make a long story short: how can I have set_sql complain if I try to redefine a method that has already been generated? Or more generally, how do I -easily- avoid doing so?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [CDBI] avoiding set_sql() redefinitions
by perrin (Chancellor) on Jan 05, 2006 at 16:00 UTC | |
by blazar (Canon) on Jan 05, 2006 at 16:23 UTC | |
by perrin (Chancellor) on Jan 05, 2006 at 16:45 UTC | |
by blazar (Canon) on Jan 05, 2006 at 17:13 UTC | |
by perrin (Chancellor) on Jan 05, 2006 at 18:44 UTC | |
by duct_tape (Hermit) on Jan 05, 2006 at 16:43 UTC |