accessors::ro(3pm)
π accessors::ro π
okay so bestie, this is the manual page for accessors::ro, a lil Perl pragma that lives in the User Contributed Perl Documentation corner of the internet. she's got one job and she does it slayfully: making read-only accessor methods in your caller's package. no cap. β¨
π NAME π
accessors::ro β create 'classic' read-only accessor methods in caller's package.
πΈ 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";
π¦ DESCRIPTION π¦
so the accessors::ro pragma is literally the girl who shows up at compile-time and hands you simple classic read-only accessors. that's it. that's her whole deal. π
the methods she generates look exactly like this:
sub foo {
my $self = shift;
return $self->{foo};
}
and they always return the current value, just like accessors::ro. periodt. π«Ά
π PERFORMANCE π
ngl there is little-to-no performace hit when you use the generated accessors β lowkey there's usually a performance gain. main character energy fr fr.
- typically 5-15% faster than hard-coded accessors (like the above example). π₯
- typically 0-15% slower than optimized accessors (less readable).
- typically a small performance hit at startup (accessors are created at compile-time).
- uses the same anonymous sub to reduce memory consumption (sometimes by 80%).
see the benchmark tests included with this distribution for more details, bestie. π
β οΈ CAVEATS β οΈ
classes using blessed scalarrefs, arrayrefs, etc. are not supported β for sake of simplicity. only hashrefs are supported. so if your object is giving anything other than hashref... it's not gonna work, sorry gorgeous. π
π AUTHOR π
Steve Purkis <spurkis@cpan.org>
π SEE ALSO π
accessorsaccessors::rwaccessors::classicaccessors::chainedbase
that's the whole vibe, bestie β go write some read-only accessors and eat. π β¨
this page ships withperl v5.36.0and is dated2022-10-13. iconic. no notes. ππ
π¦ where this page comes from
- ubuntu noble: libaccessors-perl 1.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libaccessors-perl 1.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libaccessors-perl 1.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms