View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Eric Wilhelm > dotReader > dtRdr::Hack



Annotate this POD


New  2
Open  1
View/Report Bugs


dtRdr::Hack - self-documenting adaptive finger-wagging global vars


This is a global store for things that cannot otherwise be cleanly solved at the moment.

  package WayOver::OnThe::Left;
  use dtRdr::Hack;  dtRdr::Hack->set_variableB(45);

  package Bottom::Right::Corner;
  use dtRdr::Hack;
  my $variableB = dtRdr::Hack->get_variableB;

Basically, just a way to formalize global variable sharing.

Arrays, hashes, objects, and globs are all passed and stored directly as references.

Declarations ^

Variables are declared in the %declarations and %deprecated hashes in the code. To deprecate variables, move them rather than duplicating.

The behavior is controlled by the following constants, which should be similar to perl's warnings and strict pragmas (less the lexical aspects and dynamic switchability.)

  my %declared = (
    some_scalar => '',                       # scalar
    some_array  => [],                       # array
    some_hash   => {},                       # hash
    some_univ   => bless({}, 'UNIVERSAL'),   # any object
    some_obj    => bless({}, 'dtRdr::Book'), # class or subclass
    some_sub    => sub {_die 'ex_sub'},      # declare subs like this
    some_undef  => undef,                    # run-time typing

TODO: you can currently set an object where you declared a hash, but STRICT should probably not allow that.

Moving variables to %deprecated allows you to denote that your code should no longer be using these.

  my %deprecated = (
    some_other_scalar => '',
    some_other_array  => [],
    some_other_hash   => {},
    some_other_sub    => sub {_die 'ex_sub'},

NOTE: The sub {_die 'ex_sub'} idiom lets you stop yourself from calling what you thought was set elsewhere.


Throws errors when you:

  • get/set to an undeclared variable
  • set the wrong type to a variable
  • (TODO) set the wrong type to a dynamically typed variable

Complains when you:

  • get/set deprecated variables
  • get/set undeclared variables (allowed if STRICT=0)
  • get/set the wrong type for a variable (allowed if STRICT=0)

Is not implemented yet.

NOTE: Running without STRICT=1 is only lightly tested and is not recommended.


Eric Wilhelm <ewilhelm at cpan dot org>


See dtRdr


Copyright (C) 2006 OSoft, Eric L. Wilhelm, All Rights Reserved.

Portions derived from Jifty::DBI - Copyright Best Practical.


Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.


The dotReader(TM) is OSI Certified Open Source Software licensed under the GNU General Public License (GPL) Version 2, June 1991. Non-encrypted and encrypted packages are usable in connection with the dotReader(TM). The ability to create, edit, or otherwise modify content of such encrypted packages is self-contained within the packages, and NOT provided by the dotReader(TM), and is addressed in a separate commercial license.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

syntax highlighting: