SYNOPSIS

    use Class::Inner;

    my $object = Class::Inner->new(
        parent => 'ParentClass',
        methods => { method => sub { ... } }, },
        constructor => 'new',
        args => [@constructor_args],
    );

DESCRIPTION

Yet another implementation of an anonymous class with per object overrideable methods, but with the added attraction of sort of working dispatch to the parent class's method.

\s-1METHODS\s0

new \s-1HASH\s0

Takes a hash like argument list with the following keys.

parent

The name of the parent class. Note that you can only get single inheritance with this or \s-1SUPER\s0 won't work.

methods

A hash, keys are method names, values are CODEREFs.

constructor

The name of the constructor method. Defaults to 'new'.

args

An anonymous array of arguments to pass to the constructor. Defaults to an empty list.

Returns an object in an 'anonymous' class which inherits from the parent class. This anonymous class has a couple of 'extra' methods:

\s-1SUPER\s0

If you were to pass something like $obj = Class::Inner->new( parent => 'Parent', methods => { method => sub { ...; $self->SUPER::method(@_) } }, ); then \*(C`$self-\*(C`gt\*(C'SUPER::method\*(C' almost certainly wouldn't do what you expect, so we provide the \*(C`SUPER\*(C' method which dispatches to the parent implementation of the current method. There seems to be no good way of getting the full \*(C`SUPER::\*(C' functionality, but I'm working on it.

\s-1DESTROY\s0

Because Class::Inner works by creating a whole new class name for your object, it could potentially leak memory if you create a lot of them. So we add a \*(C`DESTROY\*(C' method that removes the class from the symbol table once it's finished with. If you need to override a parent's \s-1DESTROY\s0 method, adding a call to \*(C`Class::Inner::clean_symbol_table(ref $self)\*(C' to it. Do it at the end of the method or your other method calls won't work.

clean_symbol_table

The helper subroutine that \s-1DESTROY\s0 uses to remove the class from the symbol table.

new_classname

Returns a name for the next anonymous class.

AUTHOR

Maintained by Arun Prasaad \*(C`<[email protected]>\*(C'

Copyright (c) 2001 by Piers Cawley <[email protected]>.

All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.

Thanks to the Iterative Software people: Leon Brocard, Natalie Ford and Dave Cross. Also, this module was written initially for use in the PerlUnit project, \s-1AKA\s0 Test::Unit. Kudos to Christian Lemburg and the rest of that team.

RELATED TO Class::Inner…

There are a million and one differen Class constructors available on \s-1CPAN\s0, none of them does quite what I want, so I wrote this one to add to that population where hopefully it will live and thrive.

BUGS

Bound to be some. Actually the \*(C`SUPER\*(C' method is a workaround for what I consider to be a bug in perl.