RapidApp::ScopedGlobals
use RapidApp::ScopedGlobals; sub foo_0 { RapidApp::ScopedGlobals->applyForSub({ x => 1 }, \&foo_1 ); } use RapidApp::ScopedGlobals qw( sEnv ); sub foo_1 { sEnv->applyForSub({ x => 2 }, \&foo_2 ); print sEnv->x; } sub foo_2 { print sEnv->x, ","; } # calling foo_0 prints "2,1"
This ScopedGlobals package implements a type of "constant environment" global. No code may modify the value of the global for its current scope, but it may redefine a global for the scope of a sub-method (often an anonymous sub).
By using globals this way, they become much more like environment variables in nested shell scripts. It limits "spooky action from a distance" because no routine can modify its parents' variables (though unfortunately it is still possible to modify the deep contents of a hash which could be seen by a parent). Instead, they act much more like invisible parameters to a method, which can help when working with frameworks where it is impossible or just inconvenient to pass those parameters to an inner module or method.
This is a very simple sugar constant which returns "RapidApp::ScopedGlobals".
It makes it easy to call methods on this package.
Calls the given coderef with the given alterations of the "global" variables. When the coderef returns, the global values will revert to what they were before the call. See perl's "local" keyword for implementation details.
Returns true of the named global has been set by a parent function of the current call stack.
Returns the value of the named scoped-global, or undef if it has not been set. Note that a scoped-global could have been set to undef. Use "varExists" to determine the difference.
RapidApp::ScopedGlobals defines an auto-loader that allows you to use any named global as if it were a method. If the global has not been defined in this call stack, an exception is thrown. This allows better debugging of typo'd var names, but if you don't want an exception, use "get".
1 POD Error
The following errors were encountered while parsing the POD:
Unknown directive: =head
To install RapidApp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RapidApp
CPAN shell
perl -MCPAN -e shell install RapidApp
For more information on module installation, please visit the detailed CPAN module installation guide.