1Sub::HandlesVia::DeclarUes(e3r)Contributed Perl DocumentSautbi:o:nHandlesVia::Declare(3)
2
3
4

NAME

6       Sub::HandlesVia::Declare - declare delegations at compile-time
7

SYNOPSIS

9        use Sub::HandlesVia::Declare( $attr, $via => %delegations );
10
11       This is roughly equivalent to the following:
12
13        use Sub::HandlesVia qw(delegations);
14
15        BEGIN {
16          delegations(
17            attribute    => $attr,
18            handles_via  => $via,
19            handles      => \%delegations,
20          );
21        };
22
23       Except it doesn't import the "delegations" function into your
24       namespace.
25

DESCRIPTION

27       Useful for Object::Pad and kind of nice for Class::Tiny. Basically any
28       class builder than does its stuff at compile time.
29
30   Object::Pad
31        use Object::Pad;
32
33        class Kitchen {
34          has @foods;
35          use Sub::HandlesVia::Declare '@foods', Array => (
36            all_foods => 'all',
37            add_food  => 'push',
38          );
39        }
40
41       If an attribute begins with a '@' or '%', $via can be omitted.
42
43        use Object::Pad;
44
45        class Kitchen {
46          has @foods;
47          use Sub::HandlesVia::Declare '@foods', (
48            all_foods => 'all',
49            add_food  => 'push',
50          );
51        }
52
53   Class::Tiny
54        package Kitchen;
55        use Class::Tiny {
56          foods  => sub { [] },
57          drinks => sub { [ 'water' ] },
58        };
59        use Sub::HandlesVia::Declare 'foods', Array => (
60          all_foods  => 'all',
61          add_food   => 'push',
62        );
63        use Sub::HandlesVia::Declare 'drinks', Array => (
64          all_drinks => 'all',
65          add_drink  => 'push',
66        );
67

BUGS

69       Please report any bugs to
70       <https://github.com/tobyink/p5-sub-handlesvia/issues>.
71

SEE ALSO

73       Sub::HandlesVia.
74

AUTHOR

76       Toby Inkster <tobyink@cpan.org>.
77
79       This software is copyright (c) 2022 by Toby Inkster.
80
81       This is free software; you can redistribute it and/or modify it under
82       the same terms as the Perl 5 programming language system itself.
83

DISCLAIMER OF WARRANTIES

85       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
86       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
87       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
88
89
90
91perl v5.36.0                      2023-04-06       Sub::HandlesVia::Declare(3)
Impressum