Elizabeth Mattijsen
and 1 contributors


Class::ExtraAttributes - extra attributes for a class


This documentation describes version 0.02.


 package MyObject;
 use base qw( AnyClass );

 use Class::ExtraAttributes qw( foo );

 my $object = MyObject->new;
 my $value = $object->foo;

 sub update {  # in case you want persistence for extra attributes
     my $object= shift;

     my @extra= Class::ExtraAttributes->attributes;
     # perform update for extra attributes

 sub retrieve {  # in case you have persistence of extra attributes
     my $class= shift;

     my @extra= Class::ExtraAttributes->attributes;
     # perform retrieve of extra attributes


Ever ran into the problem that you want to subclass an existing class and add extra attributes to that class? And run into the problem of having to know the internal representation of that class in order to be able to do so? Look no further, this module is (at least a large part) of the solution.

This module makes it possible to transparently add attributes to an existing class (usually a subclass of a standard class) without interfering with the functionality of that class. This functionality is based on the OOB class which allows attributes to be added to any Perl data-structure.

Of course, this only applies to extra attributes on instantiated objects. If there is a persistent backend for the class ( as there e.g. is with Class::DBI or DBIx::Class ), then you will have to provide your own persistence "update" and "retrieve" to the class.


Calling the import routine in a given namespace (as is done with use) will export accessors / mutators with the given names into that namespace, provided they don't exist yet. These accessors / mutators in turn call the OOB_set and OOB_get functions of the OOB module.



 my @attributes = Class::ExtraAttributes->attributes; # caller's namespace

 my $attributes = Class::ExtraAttributes->attributes($namespace);

The attributes class method returns the names of the extra attributes that have been declared for the (implictely) given namespace. If no namespace is specified, then the caller's namespace will be assumed. The attributes are returned as either a list (in list context) or as a list reference (in scalar context).


 OOB (0.08)


Elizabeth Mattijsen, <liz@dijkmat.nl>.

Please report bugs to <perlbugs@dijkmat.nl>.


Copyright (c) 2008, 2012 Elizabeth Mattijsen <liz@dijkmat.nl>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.