Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Creating a "Plug-In" Framework for a Module

by jZed (Prior)
on Jan 31, 2006 at 20:34 UTC ( [id://526871]=note: print w/replies, xml ) Need Help??


in reply to Creating a "Plug-In" Framework for a Module

Here's how I do it in DBI::SQL::Nano -
BEGIN { if ($ENV{DBI_SQL_NANO} || !eval { require "SQL/Statement.pm" }) { @DBI::SQL::Nano::Statement::ISA = qw(DBI::SQL::Nano::Statement +_); @DBI::SQL::Nano::Table::ISA = qw(DBI::SQL::Nano::Table_); } else { @DBI::SQL::Nano::Statement::ISA = qw( SQL::Statement ); @DBI::SQL::Nano::Table::ISA = qw( SQL::Eval::Table); } }
Doing it in the BEGIN block means the if statement will only be evaluated once per require. Using Environment Variables gives the flexibility of choosing alternate modules once per server, once per user, once per script, or once per script invocation. Doing the eval on the require allows for a default mode if one of the alternatives is not available in a given context.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://526871]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-18 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found