accessors::classic - create 'classic' read/write accessor methods in caller's package.


NAME

accessors::classic - create 'classic' read/write accessor methods in caller's package.

Back to Top


SYNOPSIS

  package Foo;
  use accessors::classic qw( foo bar baz );
  my $obj = bless {}, 'Foo';
  # always return the current value, even on set:
  $obj->foo( 'hello ' ) if $obj->bar( 'world' ) eq 'world';
  print $obj->foo, $obj->bar, $obj->baz( "!\n" );

Back to Top


DESCRIPTION

The accessors::classic pragma lets you create simple classic Perl accessors at compile-time.

The generated methods look like this:

  sub foo {
      my $self = shift;
      $self->{foo} = shift if (@_);
      return $self->{foo};
  }

They always return the current value.

Note that there is no dash (-) prepended to the property name as there are in the accessors manpage. This is for backwards compatability.

Back to Top


PERFORMANCE

There is little-to-no performace hit when using generated accessors; in fact there is usually a performance gain.

See the benchmark tests included with this distribution for more details.

Back to Top


CAVEATS

Classes using blessed scalarrefs, arrayrefs, etc. are not supported for sake of simplicity. Only hashrefs are supported.

Back to Top


AUTHOR

Steve Purkis <spurkis@cpan.org>

Back to Top


SEE ALSO

the accessors manpage, the accessors::rw manpage, the accessors::ro manpage, the accessors::chained manpage, base

Back to Top

 accessors::classic - create 'classic' read/write accessor methods in caller's package.