logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Sub::Accessor::Small - small toolkit for generating getter/setter methods

Author

       Toby Inkster <tobyink@cpan.org>.

Bugs

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

Description

       This is a small toolkit for generating Moose-like attribute accessors.  Itdoesnotgenerateaconstructor.

       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.

perl v5.34.0                                       2022-08-18                          Sub::Accessor::Small(3pm)

Name

       Sub::Accessor::Small - small toolkit for generating getter/setter methods

See Also

       Lexical::Accessor.

Synopsis

         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 );

See Also