Matthew Simon Cavalletto

NAME

Class::MakeMethods::Template::PackageVar - Static methods with global variables

SYNOPSIS

  package MyObject;
  use Class::MakeMethods::Template::PackageVar (
    scalar          => [ 'foo' ]
  );
  
  package main;

  MyObject->foo('bar')
  print MyObject->foo();

  $MyObject::foo = 'bazillion';
  print MyObject->foo();

DESCRIPTION

These meta-methods provide access to package (class global) variables. These are essentially the same as the Static meta-methods, except that they use a global variable in the declaring package to store their values.

Common Parameters: The following parameters are defined for PackageVar meta-methods.

variable

The name of the variable to store the value in. Defaults to the same name as the method.

PackageVar:scalar

Creates methods to handle a scalar variable in the declaring package.

See the documentation on Generic:scalar for interfaces and behaviors.

PackageVar:array

Creates methods to handle a array variable in the declaring package.

See the documentation on Generic:array for interfaces and behaviors.

PackageVar:hash

Creates methods to handle a hash variable in the declaring package.

See the documentation on Generic:hash for interfaces and behaviors.

PackageVar:vars

This rewrite rule converts package variable names into PackageVar methods of the equivalent data type.

Here's an example declaration:

  package MyClass;
  
  use Class::MakeMethods::Template::PackageVar (
    vars => '$DEBUG %Index'
  );

MyClass now has methods that get and set the contents of its $MyClass::DEBUG and %MyClass::Index package variables:

  MyClass->DEBUG( 1 );
  MyClass->Index( 'foo' => 'bar' );