decorators::providers::accessors - A set of decorators to generate accessor methods
version 0.01
use decorators ':accessors'; sub foo : ro; # infer the 'foo' slot name sub get_foo : ro; # infer the 'foo' slot name ignoring the 'get_' sub test_zero : ro(foo); # specify the 'foo' slot name explcitly sub bar : rw; # infer the 'bar' slot name sub rw_bar : rw(bar); # specity the 'bar' slot name explcitly sub set_bar : wo; # infer the 'bar' name ignoring the 'set_' sub _baz : ro; # infer the '_baz' name sub baz : rw(_); # infer the private slot name (prefix with '_') sub set_baz : wo(_); # infer the private slot name (prefix with '_') ignoring the 'set_' sub get_baz : ro(_); # infer the private slot name (prefix with '_') ignoring the 'get_'
ro( ?$slot_name )
This will generate a simple read-only accessor for a slot. The $slot_name can optionally be specified, otherwise it will use the name of the method that the trait is being applied to.
$slot_name
sub foo : ro; sub foo : ro(_bar);
If the $slot_name is simply an underscore (_) then this decorator will assume the slot name is the same name as the subroutine only with an underscore prefix. This means that this:
_
sub foo : ro(_);
Is the equivalent of writing this:
sub foo : ro(_foo);
If the method name is prefixed with get_, then this trait will infer that the slot name intended is the remainder of the method's name, minus the get_ prefix, such that this:
get_
sub get_foo : ro;
sub get_foo : ro(foo);
rw( ?$slot_name )
This will generate a simple read-write accessor for a slot. The $slot_name can optionally be specified, otherwise it will use the name of the method that the trait is being applied to.
sub foo : rw; sub foo : rw(_foo);
sub foo : rw(_);
sub foo : rw(_foo);
If the method name is prefixed with set_, then this trait will infer that the slot name intended is the remainder of the method's name, minus the set_ prefix, such that this:
set_
sub set_foo : ro;
sub set_foo : ro(foo);
wo( ?$slot_name )
This will generate a simple write-only accessor for a slot. The $slot_name can optionally be specified, otherwise it will use the name of the method that the trait is being applied to.
sub foo : wo; sub foo : wo(_foo);
sub foo : wo(_);
sub foo : wo(_foo);
sub set_foo : wo;
sub set_foo : wo(foo);
predicate( ?$slot_name )
This will generate a simple predicate method for a slot. The $slot_name can optionally be specified, otherwise it will use the name of the method that the trait is being applied to.
sub foo : predicate; sub foo : predicate(_foo);
sub foo : predicate(_);
sub foo : predicate(_foo);
If the method name is prefixed with has_, then this trait will infer that the slot name intended is the remainder of the method's name, minus the has_ prefix, such that this:
has_
sub has_foo : predicate;
sub has_foo : predicate(foo);
clearer( ?$slot_name )
This will generate a simple clearing method for a slot. The $slot_name can optionally be specified, otherwise it will use the name of the method that the trait is being applied to.
sub foo : clearer; sub foo : clearer(_foo);
sub foo : clearer(_);
sub foo : clearer(_foo);
If the method name is prefixed with clear_, then this trait will infer that the slot name intended is the remainder of the method's name, minus the clear_ prefix, such that this:
clear_
sub clear_foo : clearer;
sub clear_foo : clearer(foo);
Stevan Little <stevan@cpan.org>
This software is copyright (c) 2018 by Stevan Little.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install decorators, copy and paste the appropriate command in to your terminal.
cpanm
cpanm decorators
CPAN shell
perl -MCPAN -e shell install decorators
For more information on module installation, please visit the detailed CPAN module installation guide.