.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45) .\" .\" 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 .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Sub::HandlesVia::Manual::WithCorinna 3" .TH Sub::HandlesVia::Manual::WithCorinna 3 2026-08-30 "perl v5.42.2" "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 Sub::HandlesVia::Manual::WithCorinna \- using Sub::HandlesVia with the "class" keyword .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use v5.038; \& use experimental \*(Aqclass\*(Aq; \& \& class Kitchen { \& field $foods :param = []; \& method foods () { return $foods } \& method _set_foods ($new) { $foods = $new } \& use Sub::HandlesVia::Declare [ \*(Aqfoods\*(Aq, \*(Aq_set_foods\*(Aq, sub { [] } ], \& Array => ( \& all_foods => \*(Aqall\*(Aq, \& add_food => \*(Aqpush\*(Aq, \& eat_all => \*(Aqreset\*(Aq, \& ); \& } \& \& my $kitchen = Kitchen\->new; \& $kitchen\->add_food( \*(Aqapples\*(Aq ); \& $kitchen\->add_food( \*(Aqcarrots\*(Aq ); \& \& say "I have:"; \& say "\- $_" for $kitchen\->all_foods; \& \& say "Now I will eat them all!"; \& $kitchen\->eat_all; .Ve .SH MANUAL .IX Header "MANUAL" Sub::HandlesVia allows you to delegate methods from your class to the values of your objects\*(Aq attributes. .PP Conceptually, it allows you to define \f(CW\*(C`$object\->push_number($n)\*(C'\fR to be a shortcut for \f(CW\*(C`$object\->numbers\->push($n)\*(C'\fR except that \&\f(CW\*(C`$object\->numbers\*(C'\fR is an arrayref, so doesn\*(Aqt have methods you can call on it like \f(CW\*(C`push\*(C'\fR. .PP Sub::HandlesVia provides support for the Perl 5.38+ \f(CW\*(C`class\*(C'\fR keyword via Sub::HandlesVia::Declare. .PP As of the current version, you need to provide a "getter" and "setter" method to allow Sub::HandlesVia to access the attribute\*(Aqs value. It\*(Aqs also recommended to provide a coderef that Sub::HandlesVia can use to "reset" the value. .SS "Which Methods Can Be Delegated To?" .IX Subsection "Which Methods Can Be Delegated To?" The second parameter ("Array" in the synopsis) indicates which library of methods should be available. Valid values include Array, Blessed, Bool, Code, Counter, Enum, Hash, Number, Scalar, and String. .PP An arrayref can be provided, though many of the options are conceptually contradictory. .PP .Vb 3 \& use Sub::HandlesVia::Declare \*(Aqnum\*(Aq, [ \*(AqNumber\*(Aq, \*(AqScalar\*(Aq ] => ( \& ..., \& ); .Ve .SH BUGS .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" Misc advanced documentation: Sub::HandlesVia::Manual::Advanced. .PP Sub::HandlesVia, Sub::HandlesVia::Declare. .PP Documentation for delegatable methods: Sub::HandlesVia::HandlerLibrary::Array, Sub::HandlesVia::HandlerLibrary::Blessed, Sub::HandlesVia::HandlerLibrary::Bool, Sub::HandlesVia::HandlerLibrary::Code, Sub::HandlesVia::HandlerLibrary::Counter, Sub::HandlesVia::HandlerLibrary::Enum, Sub::HandlesVia::HandlerLibrary::Hash, Sub::HandlesVia::HandlerLibrary::Number, Sub::HandlesVia::HandlerLibrary::Scalar, and Sub::HandlesVia::HandlerLibrary::String. .SH AUTHOR .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2022 by Toby Inkster. .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. .SH "DISCLAIMER OF WARRANTIES" .IX Header "DISCLAIMER OF WARRANTIES" THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.