puterboy has asked for the wisdom of the Perl Monks concerning the following question:

For various portability reasons, I need to include a couple of custom packages in the same file as my application.

I have no problem wrapping each package in a BEGIN block and accessing methods the usual way. I can also export subroutines using exporter/import. However, I can't seem to export global variables. My code uses the following paradigm:
use strict; use warnings; MyPackage->import; #My main code $globalVar=1; myfunction(); #===================== BEGIN{ package MyPackage; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(globalVar myfunction); our $globalVar; sub myfunction {} #Rest of package code... }
Running, yields the error 'symbol "$globalVar" requires explicit package name'

When I dump the namespace for %main::, I get:
$VAR79 = 'globalVar'; $VAR80 = *::globalVar;
So, $globalVar seems to be in the namespace, I just can't seem to be able to use it (unless of course I explicitly address it using its originating namespace location as $MyPackage::globalVar)

If I put the package in a separate file and include it using 'use MyPackage', I get the same listing in the %main:: namespace as above but I am then able to access the global error directly without error.

Any ideas what is causing $globalVar not to be recognized when the package is in the same file as main?