accessors::ro - create 'classic' read-only accessor methods in caller's package.


NAME

accessors::ro - create 'classic' read-only accessor methods in caller's package.

Back to Top


SYNOPSIS

  package Foo;
  use accessors::ro qw( foo bar baz );
  my $obj = bless { foo => 'read only? ' }, 'Foo';
  # values are read-only, so set is disabled:
  print "oh my!\n" if $obj->foo( "set?" ) eq 'read only? ';
  # if you really need to change the vars,
  # you must use direct-variable-access:
  $obj->{bar} = 'i need a drink ';
  $obj->{baz} = 'now';
  # always returns the current value:
  print $obj->foo, $obj->bar, $obj->baz, "!\n";

Back to Top


DESCRIPTION

The accessors::ro pragma lets you create simple classic read-only accessors at compile-time.

The generated methods look like this:

  sub foo {
      my $self = shift;
      return $self->{foo};
  }

They always return the current value, just like the accessors::ro manpage.

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::classic manpage, the accessors::chained manpage, base

Back to Top

 accessors::ro - create 'classic' read-only accessor methods in caller's package.