1MooX::HandlesVia(3)   User Contributed Perl Documentation  MooX::HandlesVia(3)
2
3
4

NAME

6       MooX::HandlesVia - NativeTrait-like behavior for Moo.
7

VERSION

9       version 0.001008
10

SYNOPSIS

12         {
13           package Hashy;
14           use Moo;
15           use MooX::HandlesVia;
16
17           has hash => (
18             is => 'rw',
19             handles_via => 'Hash',
20             handles => {
21               get_val => 'get',
22               set_val => 'set',
23               all_keys => 'keys'
24             }
25           );
26         }
27
28         my $h = Hashy->new(hash => { a => 1, b => 2});
29
30         $h->get_val('b'); # 2
31
32         $h->set_val('a', 'BAR'); # sets a to BAR
33
34         my @keys = $h->all_keys; # returns a, b
35

DESCRIPTION

37       MooX::HandlesVia is an extension of Moo's 'handles' attribute
38       functionality. It provides a means of proxying functionality from an
39       external class to the given atttribute. This is most commonly used as a
40       way to emulate 'Native Trait' behavior that has become commonplace in
41       Moose code, for which there was no Moo alternative.
42

SHORTCOMINGS

44       Due to current Moo implementation details there are some deficiencies
45       in how MooX::HandlesVia in comparison to what you would expect from
46       Moose native traits.
47
48       ·   methods delegated via the Moo 'handles' interface are passed the
49           attribue value directly. and there is no way to access the parent
50           class. This means if an attribute is updated any triggers or type
51           coercions WILL NOT fire.
52
53       ·   Moo attribute method delegations are passed the attribute value.
54           This is fine for references (objects, arrays, hashrefs..) it means
55           simple scalar types are READ ONLY. This unfortunately means Number,
56           String, Counter, Bool cannot modify the attributes value, rendering
57           them largely useless.
58

PROVIDED INTERFACE/FUNCTIONS

60       process_has(@_)
61           MooX::HandlesVia preprocesses arguments passed to has() attribute
62           declarations via the process_has function. In a given Moo class, If
63           'handles_via' is set to a ClassName string, and 'handles' is set
64           with a hashref mapping of desired moo class methods that should map
65           to ClassName methods, process_has() will create the appropriate
66           binding to create the mapping IF ClassName provides that named
67           method.
68
69             has options => (
70               is => 'rw',
71               handles_via => 'Array',
72               handles => {
73                 mixup => 'shuffle',
74                 unique_options => 'uniq',
75                 all_options => 'elements'
76               }
77             );
78
79       The following handles_via keywords are reserved as shorthand for
80       mapping to Data::Perl:
81
82       ·   Hash maps to Data::Perl::Collection::Hash::MooseLike
83
84       ·   Array maps to Data::Perl::Collection::Array::MooseLike
85
86       ·   String maps to Data::Perl::String::MooseLike
87
88       ·   Number maps to Data::Perl::Number::MooseLike
89
90       ·   Bool maps to Data::Perl::Bool::MooseLike
91
92       ·   Code maps to Data::Perl::Code
93

SEE ALSO

95       ·   Moo
96
97       ·   MooX::late
98

AUTHOR

100       Matthew Phillips <mattp@cpan.org>
101
103       This software is copyright (c) 2015 by Matthew Phillips
104       <mattp@cpan.org>.
105
106       This is free software; you can redistribute it and/or modify it under
107       the same terms as the Perl 5 programming language system itself.
108
109
110
111perl v5.28.1                      2015-03-31               MooX::HandlesVia(3)
Impressum