Swank Wiki
Recently Visited

Swank v0.04.04


This is on cpan at Class::Classless::C3. See the documentation there.

This is very similar to Class::Classless, with a couple improvements. 

First, it uses Algorithm::C3 to simplify the inheritance tree calculations. This may be more of a simplification than an improvement, since there are cases when Algorithm::C3 will throw an exception because of a bad inheritance tree.

Second, and more importantly, it uses Sub::Name in order to avoid the hackish context variable that Class::Classless has to pass around.  In this version of Classless, we simply call $self->NEXT to pass control to the next parent object.

It also has an autoload feature for automatic compilation of page methods.

Class::Classless::C3 provides the basis for the inheritance between swank pages.  Each page is compiled into a Swank::Page object, which is a Classless object, and inherits from other pages.


Algorithm::C3 , Sub::Name


$Class::Classless::C3::ROOT  -- The one and only root object.

$Class::Classless::C3::autoload -- If you assign a coderef to this variable, it will activate an autoload-like feature.

$parent->new( 'name')
$parent->new( 'name', 'method_name'=>\&sub, ... )

Creates a new classless object.   If 'name' is omitted, an auto-generated name will be assigned.  A name can be assigned or changed later with $obj->meta->name('name').  Any additional method_name=>sub pairs are passed on to $obj->meta->addmethod.

NEXT -- call $self->NEXT to pass control to a parent object.  Returns undef (does not throw exception) if there is nothing to call in the parents.

isa -- Returns true if $obj is a descendant of the argument, which can be an object or an object name. The 'can' method is more useful.

can -- Checks whether an object (or its parents) can execute the given method, and returns a code reference for the method.

meta() -- The only reserved field name is "meta", which stores a Swank::Classless::Meta object for storing object meta-data.  This is the accessor for it.  Changing the object name, changing the object's parent(s), adding and removing methods are done by calling methods on the meta object.


Implements meta-data for Swank::Classless objects.

name( 'whatever' ) -- Gets or sets the name for this object, which should be unique.  An autogenerated default is provided.

parent( $object )  -- Gets or sets the parent object for this object.  If the object has multiple parents, only returns the first.

parents( @objects ) -- Gets or sets multiple parents for this object, to support multiple inheritance.

addparent( $object ) -- Adds another parent to this object.

addmethod( 'method_name' => \&sub ) -- Adds a method to this object.

delmethod( 'method_name' ) -- Removes a method from this object.

clone -- not yet implemented

declassify( 'class_name' ) -- Creates a Swank::Classless object from a perl class.  The new classless object is named 'class_name' and all of its methods are copied to the classless object.  This is a convenient way to setup a new heirarchy of classless objects.
example:  $base = Swank::Classless::Meta::declassify('Swank::Page');