Class::...ccessor(3)
π NAME π
Class::MOP::Method::Accessor β it's the Method Meta Object for accessors, and yes bestie, that's literally the whole title. This is the Class::...ccessor(3) page you're reading rn π«Ά
β¨ VERSION β¨
version 2.4000 β that's the one, no cap π
π¦ SYNOPSIS π¦
Okay so this is how you actually use it:
use Class::MOP::Method::Accessor;
my $reader = Class::MOP::Method::Accessor->new(
attribute => $attribute,
is_inline => 1,
accessor_type => 'reader',
);
$reader->body->execute($instance); # call the reader method
And that last line? That's you calling the reader method. Main character energy fr π
πΈ DESCRIPTION πΈ
So listen π β this is a subclass of Class::MOP::Method, and Class::MOP::Attribute uses it to generate accessor code. It's the one handling the generation of readers, writers, predicates and clearers.
And here's the tea: for each type of method, it can either create a subroutine reference, or actually inline code by generating a string and eval'ing it. Two paths, one icon β¨
π METHODS π
Class::MOP::Method::Accessor->new(%options)
This returns a new Class::MOP::Method::Accessor based on the %options you handed over. The options, one by one:
attributeβ this is theClass::MOP::Attributefor which accessors are being generated. Required, so don't skip it πaccessor_typeβ a string, and it should be one ofreader,writer,accessor,predicate, orclearer. This is the type of method being generated. Also required.is_inlineβ tells you whether or not the accessor should be inlined. Defaults to false.nameβ the method name (no package name attached, just the name). Required.package_nameβ the package name for the method. Required.
$metamethod->accessor_type
Returns the accessor type which was passed to new. Simple as that π
$metamethod->is_inline
Returns a boolean indicating whether or not the accessor is inlined. True or false, that's it β
$metamethod->associated_attribute
This returns the Class::MOP::Attribute object which was passed to new. Your original attribute, back in your arms π«Ά
$metamethod->body
The method itself is generated when the accessor object is constructed. Like, it shows up already built β construction time is when it happens π₯
π AUTHORS π
Shoutout to the whole crew, every single one of them:
- Stevan Little <stevan@cpan.org>
- Dave Rolsky <autarch@urth.org>
- Jesse Luehrs <doy@cpan.org>
- Shawn M Moore <sartak@cpan.org>
- ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman) <nothingmuch@woobling.org>
- Karen Etheridge <ether@cpan.org>
- Florian Ragwitz <rafl@debian.org>
- Hans Dieter Pearcey <hdp@cpan.org>
- Chris Prather <chris@prather.org>
- Matt S Trout <mstrout@cpan.org>
Icons, all of them, periodt π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2006 by Infinity Interactive, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Free is free bestie, go wild πΈ
And that's the whole page! This little number was brought to you byperl v5.42.0and it was dated2025-07-25β talk about a glow up πβ¨ bye bestie, go write some accessors π
π¦ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms