Class::Accessor::Typed - Class::Accessor::Lite with Type
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' }
Class::Accessor::Typed is variant of Class::Accessor::Lite. It supports argument validation like Smart::Args.
Class::Accessor::Lite
Smart::Args
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 }, );
If value evaluates to false, the default constructor is not created. The other cases, Class::Accessor::Typed provides the default constructor automatically.
create a read / write accessor.
create a read-only accessor.
create a write-only accessor.
create a read / write lazy accessor.
create a read-only lazy accessor.
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.
Int
isa
does
default
optional
builder
rw
ro
wo
rw_lazy
ro_lazy
Copyright (C) papix.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
papix <mail@papix.net>
To install Class::Accessor::Typed, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Accessor::Typed
CPAN shell
perl -MCPAN -e shell install Class::Accessor::Typed
For more information on module installation, please visit the detailed CPAN module installation guide.