vars::global

vars::global is a Perl module that tries to make global variables a little safer.
Download

vars::global Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Flavio Poletti
  • Publisher web site:
  • http://search.cpan.org/~polettix/

vars::global Tags


vars::global Description

vars::global is a Perl module that tries to make global variables a little safer. vars::global is a Perl module that tries to make global variables a little safer.SYNOPSIS # In the place/package where we want to create globals use vars::global create => qw( $foo @bar z ); # Add some more global symbols vars::global->create(qw( $hello @world %now )); # Somewhere else, where we need to access those globals use vars::global qw( $foo @bar z ); # Don't try to use globals that do not exist use vars::global qw( $Foo ); # typo, croaks use vars::global qw( @inexistent ); # we don't create by default # use 'create' as above # You can also import and create new globals use vars::global qw( $foo z ), create => qw( $hey @joe ); # If you're lazy, you can import all the globals defined so far use vars::global ':all';This module lets you define 'global' variables and gain a slight advantage over blind use of package variables.The global variables live inside the vars::global package, with the names given by the user. Where' the advantage? It's two-fold:there is an import mechanism that lets you access the global variable without the need to fully qualify its name (i.e. using $foo instead of $vars::global::foo);the import mechanism ensures that you can import only the global variables that have been explicitly declared so far, which reduces the possibility of a typo.If you have already "created" the global variable $foo, the import operation is equivalent to do: *{__PACKAGE__ . '::foo'} = $vars::global::foo;that is, the package variable in the current package is made an alias for the global variable.The anti-typo check is simply obtained by doing a check before the above import.Typical usage is as follows:creationEarly in the module or in the program you create variables prepending the create word, as follows: use vars::global create => qw( $foo @bar z );accessIn the modules where you need to access a given global variable, you can import them very simply: use vars::global qw( $foo z ); # I don't need @bar here ;)The creation step above automatically imports all the new globals into the current package. Requirements: · Perl


vars::global Related Software