NAME
Class::Unique - Create a unique subclass for every instance
VERSION
Version 0.01
SYNOPSIS
package MyClass;
use base 'Class::Unique';
sub foo { print "foo!\n"; }
sub bar { print "bar!\n"; }
...
use MyClass;
my $obj1 = MyClass->new;
my $obj2 = MyClass->new;
my $new_foo = sub { print "new foo!\n"; };
$obj2->install( foo => $new_foo );
$obj1->foo; $obj1->bar;
$obj2->foo; $obj2->bar;
DESCRIPTION
Class::Unique is a base class which provides a constructor and some utility routines for creating objects which instantiate into a unique subclass. If MyClass is a subclass of Class::Unique, and inherrits Class::Unique's constructor, then every object returned by MyClass->new will be blessed into a dynamically created subclass of MyClass. This allows you to modify package data on a per-instance basis. Class::Prototyped provides similar functionality; use this module if you want per-instance subclasses but you don't require a full-fledged prototype-based OO framework.
METHODS
The following methods are inherrited.
new()
-
Constructor. Returns a hash ref blessed into a new dynamically created package.
install()
-
Install a new package variable into an object's class.
$obj->install( varname => $some_ref );
This is really just a shortcut for doing:
my $pkg = ref $obj; no strict 'refs'; *{ $pkg . '::varname' } = $code_ref;
The most useful thing to do is probably to assign coderefs in order to play with your object's methods:
$obj->install( some_method => sub { print "this is a method for just this object!" } ); $obj->some_method;
But you can use
install
to install a hash, array or scalar reference as well.
AUTHOR
Mike Friedman, <friedo@friedo.com>
BUGS
Please report any bugs or feature requests to bug-class-unique@rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Unique. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
COPYRIGHT & LICENSE
Copyright 2005 Mike Friedman, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.