Sub::Ha...WithMite(3)
π Sub::HandlesVia::Manual::WithMite π
okay bestie, so this is the manual page for Sub::HandlesVia::Manual::WithMite (from the Sub::HandlesVia docs, section 3 of the perl manual) β it's the whole "how do I use Sub::HandlesVia with Mite" situation and honestly it's giving effortless. Let's get into it π¦
β¨ SYNOPSIS β¨
package MyApp::Kitchen {
use MyApp::Mite;
has food => (
is => 'ro',
isa => 'ArrayRef[Str]',
handles_via => 'Array',
default => sub { [] },
handles => {
'add_food' => 'push',
'find_food' => 'grep',
},
);
}
πΈ MANUAL πΈ
Sub::HandlesVia lets you delegate methods from your class straight onto the values of your objects' attributes. no cap. π
Conceptually, it lets you define $object->push_number($n) as a shortcut for $object->numbers->push($n) β except plot twist: $object->numbers is an arrayref, so it doesn't have methods you can just call on it like push. the audacity, honestly π
Mite 0.009000 and above have built-in handles_via support. Mite will co-operate with Sub::HandlesVia to implement handles_via and avoid your project having a Sub::HandlesVia dependency! it's giving teamwork, it's giving low-dependency icon behavior π
π Which Methods Can Be Delegated To? π
The handles_via option tells you which library of methods should be available. Valid values include Array, Blessed, Bool, Code, Counter, Enum, Hash, Number, Scalar, and String.
An arrayref can be provided for handles_via, though many of the options are conceptually contradictory. yes bestie, you can mix them, it's just gonna be a little messy π
handles_via => [ 'Number', 'Scalar' ]
π use Sub::HandlesVia π
Mite goes to a lot of effort to avoid you needing to use Sub::HandlesVia directly in your classes and roles, and thus avoid you needing to add it as a dependency. so considerate of it fr fr π«Ά
However, there are edge cases that it might not handle. In these cases, you should be able to use SubHandlesVia in your code after your use MyApp::Mite and Sub::HandlesVia will intervene and make things work. This adds a dependency on Sub::HandlesVia though. trade-offs, bestie π
package MyApp::Kitchen {
use MyApp::Mite;
use Sub::HandlesVia;
has food => (
is => 'ro',
isa => 'ArrayRef[Str]',
handles_via => 'Array',
default => sub { [] },
handles => {
'add_food' => 'push',
'find_food' => 'grep',
},
);
}
Now Mite will no longer generate add_food and find_food methods in your Kitchen.pm.mite.pm file when you run mite compile. Instead, Sub::HandlesVia will generate them at run-time when your application runs. iconic behavior, honestly β¨
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>.
not me telling you where to drop the bug reportsβ¦ it's the responsible thing okay π€ go tell Toby, he wants to know π
π SEE ALSO π
- Misc advanced documentation:
Sub::HandlesVia::Manual::Advanced. Sub::HandlesVia,Mite.- 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, andSub::HandlesVia::HandlerLibrary::String.
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. king behavior, we love to see it π
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2022 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
π 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.
likeβ¦ no promises bestie, that's just how it is π
and that's the whole page!! this was rendered from perl v5.42.0, dated 2026-02-11, and you just read Sub::Ha...WithMite(3) β the User Contributed Perl Documentation. go forth and delegate, my love ππ¦π
π¦ where this page comes from
- fedora 44: perl-Sub-HandlesVia 0.053005-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms