Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

How do I subclass DB?

by larryk (Friar)
on May 10, 2005 at 11:16 UTC ( #455517=perlquestion: print w/ replies, xml ) Need Help??
larryk has asked for the wisdom of the Perl Monks concerning the following question:

Maybe I'm just having an attack of premature senile dementia, but looking at the DB module documentation it looks like subclassing should be easy - something along the lines of:
package Devel::larryk; use base qw(DB); use strict; Devel::larryk->new()->register(); # create instance and register sub new { bless {} } sub init { my $self = shift; $self->ready(); print "larryk initialised\n"; } 1;
This should then be invokable from the command line, as:
perl -d:larryk foo.pl
...but it doesn't work. Why?

Because as soon as I use the DB module (in order to subclass it) it immediately calls ->init() on all registered clients. But of course I haven't registered as a client yet because I only just used it. So I seem to have a chicken and egg situation.

How can this work?

   larryk                                          
perl -le "s,,reverse killer,e,y,rifle,lycra,,print"

Comment on How do I subclass DB?
Select or Download Code
Re: How do I subclass DB?
by thcsoft (Monk) on May 10, 2005 at 11:32 UTC
    because you should either type:
    perl -MDevel::larryk -e' ...'
    or
    perl -e 'use Devel::larryk; ...'
    :)

    language is a virus from outer space.
      perldoc perlrun
          -d:*foo=bar,baz*
               runs the program under the control of a debugging, profiling, or
               tracing module installed as Devel::foo. E.g., -d:DProf executes the
               program using the Devel::DProf profiler. As with the -M flag,
               options may be passed to the Devel::foo package where they will be
               received and interpreted by the Devel::foo::import routine. The
               comma-separated list of options must follow a "=" character. See
               perldebug.
      
      Thanks, but that's not actually the problem. The Devel:: is assumed with the -d switch.

      My problem is that the DB module does something as soon as it is included to organise registered debugging "clients". Unfortunately, this does not give me any time to actually register, as I have to include the code before I can subclass it (or at any rate, the register function must be defined so I can call it _to_ register).

      I don't really fancy what seems to be the answer which is to doubly declare the DB package so I can step through the use of DB.pm itself in order to call register() before it inits the registered clients *ugh*.

      Thanks for your suggestion, though.

         larryk                                          
      perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
      

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://455517]
Approved by tlm
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2014-10-22 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls