Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is my general approach when I need to do something similar, in this case, a poor man's Module::Pluggable system:

# NOTE! This is just a snippet from a larger work shown only to illust +rate the principle use strict; use warnings use Cwd (); use Try::Tiny; # used to find the location of THIS module. assumes that all plug-ins # will be under a directory named after this module (without the '.pm' +) sub _basename_dir { my $class = shift; # In this case, we want to always use THIS package's name, not a s +ub-class my $package = __PACKAGE__; $package =~ s/::/\//g; my $packpath = $INC{ join( '.', $package, 'pm' ) }; $packpath =~ s/\.pm$//; my $realpath = Cwd::realpath($packpath); return $realpath; } # be sure to get the method in THIS package, not a sub-class my $basedir = __PACKAGE__->_basename_dir(); my $pdir = "$basedir/Plugin"; opendir( my $dh, $pdir)or die "Can not open $pdir"; my @plugins = grep { /\.pm$/ && -f "$basedir/Plugin/$_" } readdir($dh) +; closedir( $dh ) or die "Can not close $pdir"; for my $plugin ( @plugins ) { my $ppkg = try { my $package = __PACKAGE__; # gotta change from '::' to '/' so require is happy. $package =~ s/::/\//g; my $ppath = join( '/', $package, 'Plugin', $plugin); require $ppath; # and now we change back to normal '::' without the .pm to use + as a class name. $plugin =~ s{(?:\.pm)$}{}; my $pname = join( '::', __PACKAGE__, 'Plugin', $plugin ); return ($pname->isa( __PACKAGE__ ) && $pname->_enabled) ? $pna +me : undef ; } catch { warn "Invalid plugin: $plugin\n$_\n"; return; } or next; $ppkg->register(); }

There are probably better or cleaner ways to do this (this is Perl, after all) but this has been a very stable approach for me.

It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

In reply to Re: dereferencing use module by boftx
in thread dereferencing use module by kcarpenter@soleo.com

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-23 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found