NAME

decorators::providers::accessors - A set of decorators to generate accessor methods

VERSION

version 0.01

SYNOPSIS

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_'

DESCRIPTION

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.

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:

sub get_foo : ro;

Is the equivalent of writing this:

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);

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 : rw(_);

Is the equivalent of writing this:

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:

sub set_foo : ro;

Is the equivalent of writing this:

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);

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 : wo(_);

Is the equivalent of writing this:

sub foo : wo(_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:

sub set_foo : wo;

Is the equivalent of writing this:

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);

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 : predicate(_);

Is the equivalent of writing this:

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:

sub has_foo : predicate;

Is the equivalent of writing this:

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);

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 : clearer(_);

Is the equivalent of writing this:

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:

sub clear_foo : clearer;

Is the equivalent of writing this:

sub clear_foo : clearer(foo);

AUTHOR

Stevan Little <stevan@cpan.org>

COPYRIGHT AND LICENSE

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.