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 the Class::MOP::Attribute for which accessors are being generated. Required, so don't skip it πŸ™ˆ
  • accessor_type β€” a string, and it should be one of reader, writer, accessor, predicate, or clearer. 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 πŸ‘‘


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 by perl v5.42.0 and it was dated 2025-07-25 β€” talk about a glow up πŸ’–βœ¨ bye bestie, go write some accessors πŸŽ€
πŸ“¦ where this page comes from