in reply to "use vars" will remain (Re: Win32 EXPORT_OK problems)
in thread Win32 EXPORT_OK problems
What is wrong with:
Try the following sample script:package Our; require strict; # Must be sure it has been loaded sub import { if ($] < 5.006) { my $pkg = caller(); *{"$pkg\::our"} = \*our; @_ = qw(strict vars); goto &strict::unimport; } } sub our { } 1; __END__ =head1 NAME Our - pragma to gracefully degrade 'our' on older Perl's. =head1 SYNOPSIS use strict; use Our; # Must appear after strict our($foo); =head1 DESCRIPTION On older versions of Perl this undoes strict vars, and imports an our function. This allows modules to be developed on newer Perl's using 'our' yet still run on older installations. =head1 BUGS This provides backwards but not forwards compatibility. Caveat developer.
OK, so you have to put the Our after the strict. And to get the benefit from strict you need to be doing your development on a recent version of Perl. But this lets you get all of the development benefits of our while still retaining backwards compatibility.use strict; use Our; our ($foo); $foo = "hello\n"; print $foo;
|
---|
Replies are listed 'Best First'. | |
---|---|
Oops
by tilly (Archbishop) on Dec 27, 2000 at 03:20 UTC | |
(tye)Re: "use vars" will remain (Re: Win32 EXPORT_OK problems)
by tye (Sage) on Dec 27, 2000 at 01:39 UTC | |
by tilly (Archbishop) on Dec 27, 2000 at 02:20 UTC | |
by chipmunk (Parson) on Dec 27, 2000 at 01:44 UTC | |
by tye (Sage) on Dec 27, 2000 at 01:48 UTC |
In Section
Seekers of Perl Wisdom