anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I have a file Execute.pl which reads a file PerformTheseOperations.file </p?

The File: PerformTheseOperations.file file specify which operations has to be performed. There are around 100 Operations and this file list/filters out which operations I have to execute.

Each of the operations are written in a seperate .pm file and saved in Operations Folder. Now, I want that when I run Execute.pl, it should read the operations from PerformTheseOperations.file file and select the corresponding file and perform the operation.

I also want the functionality to be so robust that when I have to add more operation, i just add the file in Operations Folder and mentione that has to be executed in PerformTheseOperations.file

Can some one help me with this. I have been working on Module:pluggable but it is not the one which i want to use.

Replies are listed 'Best First'.
Re: Perl Modules Question
by moritz (Cardinal) on Apr 30, 2012 at 06:24 UTC
      do is also a choice.
Re: Perl Modules Question
by locked_user sundialsvc4 (Abbot) on Apr 30, 2012 at 14:20 UTC

    I wish that I had found this little jewel m-u-c-h sooner:   UNIVERSAL::require.

    You are definitely on the right path by defining each Operation as a .pm file in a folder.   Now, simply let that entire folder become a Perl package.   Begin each file with package Operations::name;, and end each file with 1; (since every package-file must return True), and you are pretty much there.   You can also create an Operations.pm package in the parent folder and put common-methods there ... a parent class, of which each of the specific operations is now a descendent.   Then, before invoking a particular operation, you require it (using UNIVERSAL::require for much Perl Goodness).   (It’s not a problem if it’s already there.)   And now, you have now achieved your (extendable) goal with an excellent base architecture.   You can add new Operations files as often as you want to, and it will Just Work.™

    My superficial sense of the pluggables module that you’ve been looking at, is that it is not quite aiming to solve the same problem that you are.   (But a peek into its source-code might be informative, to see just how it does what it does set out to do ...)

      Can you give a small snippet of code how to use it. This will be a great help.