Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 - - - -
The PerformOperation folder has all the Operations/functionality which is adding day by day and 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 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.

Replies are listed 'Best First'.
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/ ./lib/Framework/Op/ ./lib/Framework/Op/ ./lib/Framework/Op/ ./lib/Framework/Op/ ./
    cat ops.conf
    Op PayBills Op TakeOutTrash Op WalkTheDog
    #!/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/
    package Framework::Op::PayBills; use Moose; sub execute { my ($self) = @_; warn 'paying the bills'; } 1;
    cat ./lib/Framework/Op/
    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 paying the bills at lib/Framework/Op/ line 7. taking out the trash at lib/Framework/Op/ line 7. walking the dog at lib/Framework/Op/ 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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2016-10-26 00:30 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.