GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  ACCESSORS::CLASSIC (3)

.ds Aq ’

NAME

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

CONTENTS

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" );



DESCRIPTION

The <B>accessors::classicB> 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 accessors. This is for backwards compatability.

PERFORMANCE

There is <B>little-to-no performace hitB> when using generated accessors; in fact there is <B>usually a performance gainB>.
o typically 5-15% faster than hard-coded accessors (like the above example).
o typically 1-15% slower than optimized accessors (less readable).
o typically a small performance hit at startup (accessors are created at compile-time).
o uses the same anonymous sub to reduce memory consumption (sometimes by 80%).
See the benchmark tests included with this distribution for more details.

CAVEATS

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

AUTHOR

Steve Purkis <spurkis@cpan.org>

SEE ALSO

accessors, accessors::rw, accessors::ro, accessors::chained, base
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 ACCESSORS::CLASSIC (3) 2016-03-17

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.