Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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

by jZed (Prior)
on Jan 31, 2006 at 20:34 UTC ( #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/" }) { @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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://526871]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-01-23 06:48 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (240 votes). Check out past polls.