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

Class::Accessor::Typed - Class::Accessor::Lite with Type

SYNOPSIS

    package Synopsis;

    use Class::Accessor::Typed (
        rw => {
            baz => { isa => 'Str', default => 'string' },
        },
        ro => {
            foo => 'Str',
            bar => 'Int',
        },
        wo => {
            hoge => 'Int',
        },
        rw_lazy => {
            foo_lazy => 'Str',
        }
        ro_lazy => {
            bar_lazy => { isa => 'Int', builder => 'bar_lazy_builder' },
        }
    );

    sub _build_foo_lazy  { 'string' }
    sub bar_lazy_builder { 'string' }

DESCRIPTION

Class::Accessor::Typed is variant of Class::Accessor::Lite. It supports argument validation like Smart::Args.

THE USE STATEMENT

The use statement of the module takes a single hash. An arguments specifies the read/write type (rw, ro, wo) and setting of properties. Setting of property is defined by hash reference that specifies property name as key and property rule as value.

    use Class::Accessor::Typed (
        rw => { # read/write type
            baz => 'Int', # property name => property rule
        },
    );
new => $true_of_false

If value evaluates to false, the default constructor is not created. The other cases, Class::Accessor::Typed provides the default constructor automatically.

rw => \%name_and_option_of_the_properties

create a read / write accessor.

ro => \%name_and_option_of_the_properties

create a read-only accessor.

wo => \%name_and_option_of_the_properties

create a write-only accessor.

rw_lazy => \%name_and_option_of_the_properties

create a read / write lazy accessor.

ro_lazy => \%name_and_option_of_the_properties

create a read-only lazy accessor.

PROPERTY RULE

Property rule can receive string of type name (e.g. Int) or hash reference (with isa/does, default, optional and builder). default can only use on rw, ro and wo, and builder can only use on rw_lazy and ro_lazy.

SEE ALSO

Class::Accessor::Lite

Smart::Args

LICENSE

Copyright (C) papix.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

papix <mail@papix.net>