1Sub::HandlesVia::ManualU:s:eWritChoMnotorsieb(u3t)ed PerSlubD:o:cHuamnednlteastViioan::Manual::WithMoose(3)
2
3
4

NAME

6       Sub::HandlesVia::Manual::WithMoose - using Sub::HandlesVia with Moose
7

SYNOPSIS

9        package Kitchen {
10          use Moose;
11          use Sub::HandlesVia;
12          use Types::Standard qw( ArrayRef Str );
13
14          has food => (
15            is          => 'ro',
16            isa         => ArrayRef[Str],
17            handles_via => 'Array',
18            default     => sub { [] },
19            handles     => {
20              'add_food'    => 'push',
21              'find_food'   => 'grep',
22            },
23          );
24        }
25
26       (If you have a moose in your kitchen, that might be a disaster!)
27

MANUAL

29       Sub::HandlesVia allows you to delegate methods from your class to the
30       values of your objects' attributes.
31
32       Conceptually, it allows you to define "$object->push_number($n)" to be
33       a shortcut for "$object->numbers->push($n)" except that
34       "$object->numbers" is an arrayref, so doesn't have methods you can call
35       on it like "push".
36
37       Moose does have a built-in feature (native traits) which provides a
38       more limited version of this.
39
40   Which Methods Can Be Delegated To?
41       The "handles_via" option indicates which library of methods should be
42       available. Valid values include Array, Blessed, Bool, Code, Counter,
43       Hash, Number, Scalar, and String.
44
45       An arrayref can be provided for "handles_via", though many of the
46       options are conceptually contradictory.
47
48        handles_via => [ 'Number', 'Scalar' ]
49
50   Moose Native Types
51       Although the synopsis shows Types::Standard being used for type
52       constraints, Moose native types should also work fine.
53
54        package Kitchen {
55          use Moose;
56          use Sub::HandlesVia;
57
58          has food => (
59            is          => 'ro',
60            isa         => 'ArrayRef[Str]',
61            handles_via => 'Array',
62            default     => sub { [] },
63            handles     => {
64              'add_food'    => 'push',
65              'find_food'   => 'grep',
66            },
67          );
68        }
69
70   True Moose Native Traits Drop-In Syntax
71       Sub::HandlesVia will also recognize native-traits-style traits. It will
72       jump in and handle them before Moose notices!
73
74        package Kitchen {
75          use Moose;
76          use Sub::HandlesVia;
77
78          has food => (
79            is          => 'ro',
80            isa         => 'ArrayRef[Str]',
81            traits      => ['Array'],
82            default     => sub { [] },
83            handles     => {
84              'add_food'    => 'push',
85              'find_food'   => 'grep',
86            },
87          );
88        }
89

BUGS

91       Please report any bugs to
92       <https://github.com/tobyink/p5-sub-handlesvia/issues>.
93

SEE ALSO

95       Misc advanced documentation: Sub::HandlesVia::Manual::Advanced.
96
97       Sub::HandlesVia.
98
99       Documentation for delegatable methods:
100       Sub::HandlesVia::HandlerLibrary::Array,
101       Sub::HandlesVia::HandlerLibrary::Blessed,
102       Sub::HandlesVia::HandlerLibrary::Bool,
103       Sub::HandlesVia::HandlerLibrary::Code,
104       Sub::HandlesVia::HandlerLibrary::Counter,
105       Sub::HandlesVia::HandlerLibrary::Hash,
106       Sub::HandlesVia::HandlerLibrary::Number,
107       Sub::HandlesVia::HandlerLibrary::Scalar, and
108       Sub::HandlesVia::HandlerLibrary::String.
109

AUTHOR

111       Toby Inkster <tobyink@cpan.org>.
112
114       This software is copyright (c) 2022 by Toby Inkster.
115
116       This is free software; you can redistribute it and/or modify it under
117       the same terms as the Perl 5 programming language system itself.
118

DISCLAIMER OF WARRANTIES

120       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
121       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
122       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
123
124
125
126perl v5.36.0                      2022-12-S1u7b::HandlesVia::Manual::WithMoose(3)
Impressum