The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Raisin::Attributes - Simple attributes accessors for Raisin.

SYNOPSIS

use Raisin::Attributes;

has hello => sub { 'hello' };
say $self->hello; # -> hello

has 'new';
say $self->new; # -> undef

has key => 'value';
say $self->key; # -> value

DESCRIPTION

Simple implementation of attribute accessors.

METHODS

has

This code:

has key => 'value';

Will produce:

sub key {
    my ($self, $value) = @_;
    $self->{key} = $value if defined $value;
    return $self->{key} // 'value';
}