Query: accessors::ro
OS: debian
Section: 3pm
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
accessors::ro(3pm) User Contributed Perl Documentation accessors::ro(3pm)NAMEaccessors::ro - create 'classic' read-only accessor methods in caller's package.SYNOPSISpackage 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! " 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, "! ";DESCRIPTIONThe 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 accessors::ro.PERFORMANCEThere is little-to-no performace hit when using generated accessors; in fact there is usually a performance gain. o typically 5-15% faster than hard-coded accessors (like the above example). o typically 0-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.CAVEATSClasses using blessed scalarrefs, arrayrefs, etc. are not supported for sake of simplicity. Only hashrefs are supported.AUTHORSteve Purkis <spurkis@cpan.org>SEE ALSOaccessors, accessors::rw, accessors::classic, accessors::chained, base perl v5.12.4 2011-10-16 accessors::ro(3pm)
Related Man Pages |
---|
class::accessor::fast(3pm) - linux |
class::accessor::fast(3pm) - debian |
hash::fieldhash(3pm) - debian |
object::accessor(3perl) - debian |
accessors::ro(3pm) - debian |
Similar Topics in the Unix Linux Community |
---|
What's your drink? |
awk command not woking |