windows - How to have a config file automatically add 'global' modules for all pages -


i building internal automation/web tool using perl apache. hosted in windows environment. question when dealing many pages have common modules. instead of manually adding each module each page, possible have 'global module' pull in modules available pages?

for example, if need add new modules , there 10 pages, instead of going each page , adding use new::package; possible in 1 config file make new::package available each file uses config module?

i have done php, include/require in init script , include init script on each page.

package myproj::configuration use package1; ... use package999; 

# main page use myproj::configuration;  # modules included in page, without needing add them manually 

tldr: can have configuration module import multiple modules/packages pages include magic configuration module?

edit: add new perl, if obvious thing, go easy :)

this not obvious thing @ all. exporter module provides export_to_level function can problem. normally, using exporter (i.e., making package subclass of exporter) exports symbols calling package. export_to_level method makes possible export symbols package higher stack trace, want here. here's proof-of-concept:

first modules exported functions:

# module1.pm package module1; use base 'exporter'; our @export = ('foo'); sub foo { "foo" } 1;  # module2.pm package module2; use base 'exporter'; our @export_ok = ('bar'); sub bar { "bar" } 1;  # module3.pm package module3; use base 'exporter'; our @export_ok = ('baz'); our %export_tags = ('all' => [ 'baz' ]); sub baz { "baz" } 1; 

and rather have say

use module1; use module2 'bar'; use module3 ':all'; use module4;         # other module doesn't need export 

in every 1 of dozens of scripts, you'd rather say

use module1234; 

so here's module1234.pm might like:

package module1234; # optional use module1; use module2; use module3; use module4;  # these commands go inside  import  method, too. module1->export_to_level(1, __package__); module2->export_to_level(1, __package__, 'bar'); module3->export_to_level(1, __package__, ':all'); 1; 

now calling

package mypackage; use module1234; 

in script load other 4 modules , handle exporting of desired functions mypackage package, and

use module1234; print foo(), bar(), baz(); 

is enough produce output "foobarbaz".


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -