Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Don't know how to make a module for this repeating code

by zwon (Monsignor)
on Nov 24, 2012 at 16:24 UTC ( #1005391=note: print w/ replies, xml ) Need Help??


in reply to Don't know how to make a module for this repeating code

my $formType = "HR-Recruitment"; # hard coded my $lastVerion = "hr_re_v12"; # hard coded eval "use parent 'somepack::$formType::$lastVersion';";
If values are hardcoded, then why not just:
use parent 'somepack::HR-Recruitment::hr_re_v12';
Answering your question, I would probably wrote a function to generate a package from the name and data unique to this package, and then just generate all the packages. Details depend on your particular case. Have a look onto Class::MOP::Class, and Moose::Meta::Class, though you can do it without Moose too.


Comment on Re: Don't know how to make a module for this repeating code
Select or Download Code
Re^2: Don't know how to make a module for this repeating code
by exilepanda (Monk) on Nov 24, 2012 at 17:06 UTC
    Thanks for answering, and helped me to think deeper for what is my question...

    So, I think my problem is not worrying how to create this package. Perhaps I can make a module to auto update the interface version triggered by the implementation classes as well.

    But then, seems what really interested me is how to eliminate this kind of "code", when this code is a constructor. like.. can I eval() some text which return from a package that carrying the script body etc..

      can I eval() some text which return from a package that carrying the script body etc..

      What does that mean?

        umm... perhaps I can create something like this:
        package ExtConstructor; sub new { return <<" CODE"; eval 'use parent "parent::classes"'; sub new { return bless $_[0]->SUPER::new(); } CODE } 1; package Interface::Module; use ExtConstructor; my $code = new ExtConstructor; eval $code; # so that the constructor code created on-the-fly 1; package main; use Interface::Module; my $obj = new Interface::Module;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-04-18 02:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (460 votes), past polls