in reply to Code Reuse
Hello Mano_Man,
Looking through the various options in the thread linked by poj, the simplest/cleanest looks to be Syntax::Collector by tobyink. Here’s an example:
File GlobalDefined.pm:
package GlobalDefined; our $VERSION = 1; our $PROJECT_GLOBAL_VAR1 = 42; use Syntax::Collector q{ use strict 0; use warnings 0; use Data::Dumper 2.161; use Data::Dump 1.23 qw( pp ); }; 1;
File main.pl:
package GlobalDefined; use GlobalDefined; our $PROJECT_GLOBAL_VAR1; print 'My global = >', pp($PROJECT_GLOBAL_VAR1), "<\n";
Note that you still have to do a bit of work to access package globals in the calling script. This is probably a good thing, as globals should be used as sparingly as possible. (In my experimenting, I couldn’t get Exporter to play nicely with either Syntax::Collector or ToolSet when exporting package variables.)
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|