Class::MOP::Method::Accessor(3) User Contributed Perl Documentation Class::MOP::Method::Accessor(3)

# [SYNOPSIS](#SYNOPSIS)

```
    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
```

# [DESCRIPTION](#DESCRIPTION)

This is a subclass of "Class::MOP::Method" which is used by "Class::MOP::Attribute" to generate accessor code. It handles generation of readers, writers, predicates and clearers. For each type of method, it can either create a subroutine reference, or actually inline code by generating a string and "eval"'ing it.

# [METHODS](#METHODS)

[**Class::MOP::Method::Accessor-&gt;new(%options)**](#Class::MOP::Method::Accessor)

This returns a new "Class::MOP::Method::Accessor" based on the %options provided.

- attribute
  
  This is the "Class::MOP::Attribute" for which accessors are being generated. This option is required.
- accessor\_type
  
  This is a string which should be one of "reader", "writer", "accessor", "predicate", or "clearer". This is the type of method being generated. This option is required.
- is\_inline
  
  This indicates whether or not the accessor should be inlined. This defaults to false.
- name
  
  The method name (without a package name). This is required.
- package\_name
  
  The package name for the method. This is required.

**$metamethod-&gt;accessor\_type**

Returns the accessor type which was passed to "new".

**$metamethod-&gt;is\_inline**

Returns a boolean indicating whether or not the accessor is inlined.

**$metamethod-&gt;associated\_attribute**

This returns the Class::MOP::Attribute object which was passed to "new".

**$metamethod-&gt;body**

The method itself is *generated* when the accessor object is constructed.

2026-10-01 perl v5.44.0

---

Document: Class::MOP::Method::Accessor(3pm) from perl-moose 2.4001-r0 (Chainguard OS)
Source: https://github.com/moose/Moose
