Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Perl Framework Help

by anshumangoyal (Scribe)
on Apr 29, 2012 at 17:48 UTC ( #967957=perlquestion: print w/ replies, xml ) Need Help??
anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a framework in perl in which there is a nerw functionality being added day by day. Now, instead of writing a new subroutine in a file every time there is some addition to the functionality I want a file should be created and placed in a folder and that file is called by main program. I need help how we do this? Here is my folder structure:
Framework - PerformOperation - Operation1.pm - Operation2.pm - Operation3.pm - Execute.pl
The PerformOperation folder has all the Operations/functionality which is adding day by day and Execute.pl is the main Perl file which is executed to start the framework. Now, I dont't know how this can be managed. More Info: From Execute.pl a file is read in which it is written which operations I need to perform and that particular operation is selected from PerformOperation and Executed. Let me know if more information is required.

Comment on Perl Framework Help
Download Code
Re: Perl Framework Help
by Corion (Pope) on Apr 29, 2012 at 17:54 UTC

    Do you need information how to best load Operation1 etc? Maybe Module::Pluggable is a solution for you? With it, you can list and load the available operations conveniently.

      It's Really difficult to understand Module::Pluggable Do you have a small snippet of code that can help. I just want to import all modules from one folder in my main program.

        Have you looked at the SYNOPSIS section of Module::Pluggable?

        use MyClass; my $mc = MyClass->new(); # returns the names of all plugins installed under MyClass::Plugin +::* my @plugins = $mc->plugins();

        If you blindly want to import all modules from a folder, take a look at glob and require. This is basically what Module::Pluggable does as well, but maybe you feel more confident in implementing it yourself.

Re: Perl Framework Help
by ww (Bishop) on Apr 29, 2012 at 18:53 UTC
    I hope the guess I'm taking -- that you're unfamiliar with the term "modules" and their uses -- causes no offense. Certainly, if I'm wrong, Corion's suggestion is the one you should pursue.

    But if modules are unfamiliar, you'll learn much from the tutorial, Modules: How to Create, Install, and Use.

Re: Perl Framework Help
by Arunbear (Parson) on Apr 30, 2012 at 11:32 UTC
    An outline of one way to do it ;)
    +% find ! -name "*~" . ./ops.conf ./lib ./lib/Framework ./lib/Framework/Op ./lib/Framework/Op/PayBills.pm ./lib/Framework/Op/TakeOutTrash.pm ./lib/Framework/Op/PickUpKids.pm ./lib/Framework/Op/WalkTheDog.pm ./lib/Framework/Op/CookDinner.pm ./runner.pl
    cat ops.conf
    Op PayBills Op TakeOutTrash Op WalkTheDog
    cat runner.pl
    #!/usr/bin/env perl use strict; use warnings; use Config::General qw(ParseConfig); my %config = ParseConfig("ops.conf"); foreach my $op_class (@{ $config{Op} }) { my $class = "Framework::Op::$op_class"; eval "require $class" or die $@; my $op = $class->new; $op->execute; }
    cat ./lib/Framework/Op/PayBills.pm
    package Framework::Op::PayBills; use Moose; sub execute { my ($self) = @_; warn 'paying the bills'; } 1;
    cat ./lib/Framework/Op/TakeOutTrash.pm
    package Framework::Op::TakeOutTrash; use Moose; sub execute { my ($self) = @_; warn 'taking out the trash'; } 1;
    The other modules are similar. Then:
    +% perl -I lib runner.pl paying the bills at lib/Framework/Op/PayBills.pm line 7. taking out the trash at lib/Framework/Op/TakeOutTrash.pm line 7. walking the dog at lib/Framework/Op/WalkTheDog.pm line 7.
      Love you Buddy. Excellent work. This is what I was looking for. It worked like a charm. A great thanks.
Re: Perl Framework Help
by sundialsvc4 (Abbot) on Apr 30, 2012 at 14:24 UTC

    I just commented on a parallel thread to this one, dealing with the same issue, wherein I was pointing specifically at UNIVERSAL::require.   See you there.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://967957]
Approved by ww
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2014-09-23 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls