1Sub::HandlesVia::ManualU:s:eWritChoMnotor(i3b)uted PerlSDuobc:u:mHeanntdalteisoVnia::Manual::WithMoo(3)
2
3
4

NAME

6       Sub::HandlesVia::Manual::WithMoo - using Sub::HandlesVia with Moo
7

SYNOPSIS

9        package Kitchen {
10          use Moo;
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

MANUAL

27       Sub::HandlesVia allows you to delegate methods from your class to the
28       values of your objects' attributes.
29
30       Conceptually, it allows you to define "$object->push_number($n)" to be
31       a shortcut for "$object->numbers->push($n)" except that
32       "$object->numbers" is an arrayref, so doesn't have methods you can call
33       on it like "push".
34
35       You should be able to use Sub::HandlesVia as a drop-in replacement for
36       MooX::HandlesVia, which provides a similar feature, though has a more
37       limited implementation. Sub::HandlesVia honours type constraints, plus
38       it can mutate non-reference values.
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       Enum, 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

BUGS

51       Please report any bugs to
52       <https://github.com/tobyink/p5-sub-handlesvia/issues>.
53
54   Potential load order bugs
55       Unlike Moose, Moo doesn't really offer much of an API for extensions.
56       As a result, most modules that provide extensions do so by wrapping the
57       Moo keywords (especially "has"). Sub::HandlesVia is no exception to
58       this.  If you are using multiple Moo extensions, you may need to adjust
59       the order you "use" them for them to work properly together. In some
60       combinations, there may be no order that fully works!
61
62       Some known modules that should be imported before Sub::HandlesVia if
63       you're using them: MooX::Should.
64
65       Some known modules that should be imported after Sub::HandlesVia if
66       you're using them: MooX::ProtectedAttributes.
67
68       Some known modules that conflict with Sub::HandlesVia: none so far!
69

SEE ALSO

71       Misc advanced documentation: Sub::HandlesVia::Manual::Advanced.
72
73       Sub::HandlesVia.
74
75       Documentation for delegatable methods:
76       Sub::HandlesVia::HandlerLibrary::Array,
77       Sub::HandlesVia::HandlerLibrary::Blessed,
78       Sub::HandlesVia::HandlerLibrary::Bool,
79       Sub::HandlesVia::HandlerLibrary::Code,
80       Sub::HandlesVia::HandlerLibrary::Counter,
81       Sub::HandlesVia::HandlerLibrary::Enum,
82       Sub::HandlesVia::HandlerLibrary::Hash,
83       Sub::HandlesVia::HandlerLibrary::Number,
84       Sub::HandlesVia::HandlerLibrary::Scalar, and
85       Sub::HandlesVia::HandlerLibrary::String.
86

AUTHOR

88       Toby Inkster <tobyink@cpan.org>.
89
91       This software is copyright (c) 2022 by Toby Inkster.
92
93       This is free software; you can redistribute it and/or modify it under
94       the same terms as the Perl 5 programming language system itself.
95

DISCLAIMER OF WARRANTIES

97       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
98       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
99       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
100
101
102
103perl v5.38.0                      2023-07-21Sub::HandlesVia::Manual::WithMoo(3)
Impressum