CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Basic Question about Perl Modules

 



ggal
New User

Apr 23, 2010, 9:33 AM

Post #1 of 3 (977 views)
Basic Question about Perl Modules Can't Post

Hi,

I'm trying to write a Perl Module for learning purposes and I have a few doubts regarding the usage of several .pm files within a module.

While writing the module, I realised I was trying to cram a bit too much in it, and therefore I decided to split it into 3 sub-modules: there's a core .pm file and then 2 "optional" .pm files. The idea is that a "user" would surely include the 1st .pm in his script, while the two supplementary "submodules" contain routines the user will optionally want to look at only AFTER having done a run of the core module.

For instance, let's say the first module outputs a TSV data file (eg use computeTSV). Then, the second data file might compute and add a further column of data to such tsv (eg use computeTSV::addScores). Same story for the third (eg computerTSV::getNetworkRepresentation).

Now my problem is: there are some constants and a couple of subroutines that I would happily keep, unchanged, in all of the three "submodules". E.g. I have the TSV header field names, but also some db connection subroutines,etc, that appear identical in the 3 .pm files.

In order not to have 3 copies of said constants/subroutines, I was considering adding a 4th file to the mix, (something like a .h file in the C programming language) where I'll dump all the these global constants, subroutines, and nothing else. Let's call this file globals.pm. Does this make sense or is there a better way to do this?

Now my question: it's clear I would like to export ALL of the content of global.pm in my three modules files. Is there a way to do this? Or, do I have to manually add ALL of the constants and subroutines in global.pm using the

@EXPORT = qw(...);

paradigm?

Your help is greatly appreciated.

Cheers
Giuseppe


rovf
Veteran

Apr 29, 2010, 4:57 AM

Post #2 of 3 (930 views)
Re: [ggal] Basic Question about Perl Modules [In reply to] Can't Post


Quote
Now my question: it's clear I would like to export ALL of the content of global.pm in my three modules files. Is there a way to do this? Or, do I have to manually add ALL of the constants and subroutines in global.pm using the

@EXPORT = qw(...);

paradigm?


If your constants are declared with

use constant ....

Export::NoWork (available on CPAN) could do what you want. If your constants are declared using the CPAN module

Readonly ....

you would have to write your own logic. Since you have access to the symbol table, you can write a import function which walks through all those constants and have it injected into the name space of the importing module.


Vlodiar
New User

May 18, 2010, 7:48 AM

Post #3 of 3 (754 views)
Re: [rovf] Basic Question about Perl Modules [In reply to] Can't Post

http://www.casino-spielen.biz/spielautomat/ Wink

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives