Swank Wiki
Recently Visited

Swank v0.04.04


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 a Swank-specific hack for automatic compilation of page methods, but I would like to find a good way to factor that out into something overridable by other applications.

It probably needs profiling and performance improvements.

Swank::Classless 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


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

$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.

AUTOLOAD -- used for calling methods on classless objects.

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 -- not yet implemented

can -- finds the (next) sub to invoke when a method call is made on a classless object.  (The Swank auto-compile feature is in here too.)

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');