Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 !@monks...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2018-07-23 15:55 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (471 votes). Check out past polls.