.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MooX::HandlesVia 3" .TH MooX::HandlesVia 3 2023-07-26 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME MooX::HandlesVia \- NativeTrait\-like behavior for Moo. .SH VERSION .IX Header "VERSION" version 0.001009 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 4 \& { \& package Hashy; \& use Moo; \& use MooX::HandlesVia; \& \& has hash => ( \& is => \*(Aqrw\*(Aq, \& handles_via => \*(AqHash\*(Aq, \& handles => { \& get_val => \*(Aqget\*(Aq, \& set_val => \*(Aqset\*(Aq, \& all_keys => \*(Aqkeys\*(Aq \& } \& ); \& } \& \& my $h = Hashy\->new(hash => { a => 1, b => 2}); \& \& $h\->get_val(\*(Aqb\*(Aq); # 2 \& \& $h\->set_val(\*(Aqa\*(Aq, \*(AqBAR\*(Aq); # sets a to BAR \& \& my @keys = $h\->all_keys; # returns a, b .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" MooX::HandlesVia is an extension of Moo's 'handles' attribute functionality. It provides a means of proxying functionality from an external class to the given atttribute. This is most commonly used as a way to emulate 'Native Trait' behavior that has become commonplace in Moose code, for which there was no Moo alternative. .SH SHORTCOMINGS .IX Header "SHORTCOMINGS" Due to current Moo implementation details there are some deficiencies in how MooX::HandlesVia in comparison to what you would expect from Moose native traits. .IP \(bu 4 methods delegated via the Moo 'handles' interface are passed the attribue value directly. and there is no way to access the parent class. This means if an attribute is updated any triggers or type coercions \fBWILL NOT\fR fire. .IP \(bu 4 Moo attribute method delegations are passed the attribute value. This is fine for references (objects, arrays, hashrefs..) it means simple scalar types are \fBREAD ONLY\fR. This unfortunately means Number, String, Counter, Bool cannot modify the attributes value, rendering them largely useless. .PP If these are issues for you, consider Sub::HandlesVia, which uses a different architecture, respecting triggers and coercions, and allowing read-write access to non-reference values. It should be possible to use Sub::HandlesVia as a drop-in replacement for MooX::HandlesVia. .SH "PROVIDED INTERFACE/FUNCTIONS" .IX Header "PROVIDED INTERFACE/FUNCTIONS" .IP \fBprocess_has(@_)\fR 4 .IX Item "process_has(@_)" MooX::HandlesVia preprocesses arguments passed to \fBhas()\fR attribute declarations via the process_has function. In a given Moo class, If 'handles_via' is set to a ClassName string, and 'handles' is set with a hashref mapping of desired moo class methods that should map to ClassName methods, \fBprocess_has()\fR will create the appropriate binding to create the mapping IF ClassName provides that named method. .Sp .Vb 9 \& has options => ( \& is => \*(Aqrw\*(Aq, \& handles_via => \*(AqArray\*(Aq, \& handles => { \& mixup => \*(Aqshuffle\*(Aq, \& unique_options => \*(Aquniq\*(Aq, \& all_options => \*(Aqelements\*(Aq \& } \& ); .Ve .PP The following handles_via keywords are reserved as shorthand for mapping to Data::Perl: .IP \(bu 4 \&\fBHash\fR maps to Data::Perl::Collection::Hash::MooseLike .IP \(bu 4 \&\fBArray\fR maps to Data::Perl::Collection::Array::MooseLike .IP \(bu 4 \&\fBString\fR maps to Data::Perl::String::MooseLike .IP \(bu 4 \&\fBNumber\fR maps to Data::Perl::Number::MooseLike .IP \(bu 4 \&\fBBool\fR maps to Data::Perl::Bool::MooseLike .IP \(bu 4 \&\fBCode\fR maps to Data::Perl::Code .SH "SEE ALSO" .IX Header "SEE ALSO" .IP \(bu 4 Moo .IP \(bu 4 MooX::late .IP \(bu 4 Sub::HandlesVia .SH "ORIGINAL AUTHOR" .IX Header "ORIGINAL AUTHOR" Matthew Phillips .SH AUTHOR .IX Header "AUTHOR" Toby Inkster .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2020 by Matthew Phillips . .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.