Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Coding perl a plugin system?

by Revelation (Deacon)
on Dec 14, 2002 at 04:35 UTC ( [id://219821]=note: print w/replies, xml ) Need Help??


in reply to Coding perl a plugin system?

Your method works, and is in no way bad. If you need to load code into your package,  evaling it is the standard, as far as I know... (You'll see NMS Inlines a module, and then evals the require.)

However, there are other ways to do it, if you don't like how you're package is working right now:

Update: Errr... Forgot the best way to do things, in my opinion. Here it is: If your plugin module uses only subroutines, you can either create a custom import routine or use Exporter.pm to export your subroutines. This will work even if you have some special package variables, but I believe you'll have to specify those variables for export, and they will become package global to your new package (meaning they'll be like ours, not mys ). Look at perldoc -f import as well.

Otherwise, if this doesn't work, you could always runtime load  @ISA. This may be constituted as a sin:

If you do that, I would just put:
eval { @YOURapp::ISA = $mod }; # May *seem* mad, but I deem it permis +sible here
Or whatever the applicable set of modules is.
I like shotgunefx's advice of an OO rapper, though. That's what I for code I need to be accessible. If you don't feel like writing such a rapper, you could also look into an autoload function that got the variables for you. This would probably be easiest and best done by creating a hash of variable's references you wanted to share with other packages, and then sending them with an autoload of some sort.

However, it's easiest and probably best to just use package variables. Is there any specific reason not to do so? If so, is that reason large enough to use a more 'exotic' method for getting your variables?

Gyan Kapur
gyan.kapur@rhhllp.com

Replies are listed 'Best First'.
Re: Coding perl a plugin system?
by skx (Parson) on Dec 15, 2002 at 16:18 UTC

     I think I'll switch to using the Exporter machanism soon; that feels like the correct solution.

     Many thanks for your inspiration.

    Steve
    ---
    steve.org.uk

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found