Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Messing with %INC.

by mr_mischief (Monsignor)
on Apr 24, 2014 at 13:36 UTC ( #1083591=note: print w/replies, xml ) Need Help??


in reply to Messing with %INC.

Well, this is certainly nicer than opening and reading a file full of code and then doing an eval on the code. Is there any way, though, that you could reread a configuration file that changes the behavior of the program and select among definitions of the routine?

Is this specifically a system designed to handle code plugins that are maintained separately and reload those while running? What you have is a fairly clean and straightforward way to do that I think. If those other files are not separately managed, though, I'd say write all your routines out and choose them dynamically through a reference rather than redefining them this way.

Replies are listed 'Best First'.
Re^2: Messing with %INC.
by Theodore (Friar) on Apr 24, 2014 at 13:46 UTC
    Is this specifically a system designed to handle code plugins that are maintained separately and reload those while running?
    It's exactly that.

      In that case, you may find mr_mischief's suggestion of using code references (such as anonymous subs in a hash) a much more flexible approach.

      For example, the different plugins can reside in their own packages, and register themselves with the main program, instead of having all plugins be in the same package or the main program having to figure out where the plugin's functions are.

      Reloading a file can be useful if you're reloading the same file repeatedly (e.g. after changes).

        Reloading a file can be useful if you're reloading the same file repeatedly (e.g. after changes).
        I do reload specific files, because they change.

        Anonymous subs would make things more complicated. I posted the example out of the context of the actual application and this made explaining difficult. :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-05-31 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?