Sub::Accessor::Small(3pm)

Sub::Accessor::Small3pm

Small toolkit for generating getter/setter methods

Usage

  package MyClass;
  use Sub::Accessor::Small;
  use Types::Standard qw( Int );
  
  sub new {
    my $class = shift;
    my $self  = bless \$class, $class;
    my %args  = @_ == 1 ? %{ $_[0] } : @_;
    
    # Simple way to initialize each attribute
    for my $key ( sort keys %args ) {
      $self->$key( $args{$key} );
    }
    
    return $self;
  }
  
  'Sub::Accessor::Small'->new(
    package  => __PACKAGE__,
    name     => "foo",
    is       => "rw",
    isa      => Int,
  )->install_accessors();
  
  package main;
  
  my $obj = MyClass->new( foo => 42 );

Overview

This is a small toolkit for generating Moose-like attribute accessors. It does not generate a constructor.

It stores attribute values inside-out, but it is designed for Sub::Accessor::Small to be subclassed, making it easy to store attributes in other ways.

Disclaimer of warranties

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Releases

5 releases since Debian 9 (Stretch); the text changed 3 times.

  1. 9
  2. 10
  3. 11
  4. 12–13

Bugs

Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Lexical-Accessor>.

Author

Toby Inkster <[email protected]>.

From liblexical-accessor-perl 0.014-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.