1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
=head1 NAME
Sub::HandlesVia::HandlerLibrary::Scalar - library of scalar-related methods
=head1 SYNOPSIS
package My::Class {
use Moo;
use Sub::HandlesVia;
use Types::Standard 'Any';
has attr => (
is => 'rwp',
isa => Any,
handles_via => 'Scalar',
handles => {
'my_get' => 'get',
'my_make_getter' => 'make_getter',
'my_make_setter' => 'make_setter',
'my_scalar_reference' => 'scalar_reference',
'my_set' => 'set',
'my_stringify' => 'stringify',
},
);
}
=head1 DESCRIPTION
This is a library of methods for L<Sub::HandlesVia>.
=head1 DELEGATABLE METHODS
=head2 C<< get() >>
Gets the current value of the scalar.
=head2 C<< make_getter() >>
Returns a getter coderef.
my $object = My::Class->new( attr => 10 );
my $getter = $object->my_make_getter;
$object->_set_attr( 11 );
say $getter->(); ## ==> 11
=head2 C<< make_setter() >>
Returns a setter coderef.
my $object = My::Class->new( attr => 10 );
my $setter = $object->my_make_setter;
$setter->( 11 );
say $object->attr; ## ==> 11
=head2 C<< scalar_reference() >>
Returns a scalar reference to the attribute value's slot within its object.
my $object = My::Class->new( attr => 10 );
my $ref = $object->my_scalar_reference;
$$ref++;
say $object->attr; ## ==> 11
=head2 C<< set( $value ) >>
Sets the scalar to a new value.
=head2 C<< stringify() >>
Gets the current value of the scalar, but as a string.
=head1 BUGS
Please report any bugs to
L<https://github.com/tobyink/p5-sub-handlesvia/issues>.
=head1 SEE ALSO
L<Sub::HandlesVia>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2020, 2022 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|