The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Object::Pad - a simple syntax for lexical slot-based objects

SYNOPSIS

   use Object::Pad;

   class Point {
      has $x;
      has $y;

      method CREATE {
         $x = $y = 0;
      }

      method move {
         $x += shift;
         $y += shift;
      }

      method describe {
         print "A point at ($x, $y)\n";
      }
   }

DESCRIPTION

WARNING This is a highly experimental proof-of-concept. Please don't actually use this in production :)

This module provides a simple syntax for creating object classes, which uses private variables that look like lexicals as object member attributes.

KEYWORDS

class

   class Name {
      ...
   }

Behaves similarly to the package keyword, but provides a package that defines a new class. Such a class provides an automatic constructor method called new, which will invoke the class's CREATE method if it exists.

has

   has $var;
   has @var;
   has %var;

Declares that the instances of the class have a member attribute of the given name. This member attribute (called a "slot") will be accessible as a lexical variable within any method declarations in the class.

Array and hash members are permitted and behave as expected; you do not need to store references to anonymous arrays or hashes.

method

   method NAME {
      ...
   }

Declares a new named method. This behaves similarly to the sub keyword, except that within the body of the method all of the member attributes ("slots") are also accessible. In addition, the method body will have a lexical called $self which contains the invant object directly; it will already have been shifted from the @_ array.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>