Sub::Accessor::Small(3pm) | User Contributed Perl Documentation | Sub::Accessor::Small(3pm) |
Sub::Accessor::Small - small toolkit for generating getter/setter methods
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 );
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.
Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Lexical-Accessor>.
Lexical::Accessor.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2013-2014, 2017, 2020 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
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.
2022-08-18 | perl v5.34.0 |