Author image Jerome Eteve
and 1 contributors


Class::AutoAccess - Zero code dynamic accessors implementation.


Version 0.03


Base class for automated accessors implementation.

If you implement a class as a blessed hash reference, this class helps you not to write the fields accessors yourself. It uses the AUTOLOAD method to implement accessors on demand. Since the accessor is *REALLY* implemented the first time it is attempted to be used, using this class does NOT affect the performance of your program.

Inheriting from this class does not impose accessors. If you want to implement your own accessors for any reason (checking, implementation change ... ), just write them and they will be used in place of automated ones.

This class uses the AUTOLOAD method, so be careful when you implement your own AUTOLOAD method in subclasses.

If you want to keep this feature functionnal in this particular case, evaluate SUPER::AUTOLOAD in your own AUTOLOAD method before doing anything else.


    package Foo ;

    use base qw/Class::AutoAccess/ ;  # Just write this

    sub new{
        my ($class) = @_ ;
        my $self = {
                'bar' => undef ,
                'baz' => undef ,
                'toCheck' => undef
     return bless $self, $class ;

    sub toCheck{
        my ($self , $value ) = @_ ;
        # Behave the way you want. This accessor will be used in place of automated ones.


    package main ;

    my $o = Foo->new();
    # Since there is a bar attribute, the accessor will be implemented at the first use:
    # This time, the bar accessor is really implemented so there is no performance lost.
    $o->bar("new value");

    # Idem.
    $o->baz() ;
    # If you wrote your own accessor, it will be used (this is a Perl feature)


Jerome Eteve, <>


None known.

Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



Copyright 2005-2010 Jerome Eteve, all rights reserved.

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