Sub::Ha...thMoose(3)
π NAME π
Sub::HandlesVia::Manual::WithMoose β it's giving "using Sub::HandlesVia with Moose" bestie, no cap π¦
β¨ SYNOPSIS β¨
Okay so picture this, you got a class, you got attributes, you want methods to just happen for free. Look:
package Kitchen {
use Moose;
use Sub::HandlesVia;
use Types::Standard qw( ArrayRef Str );
has food => (
is => 'ro',
isa => ArrayRef[Str],
handles_via => 'Array',
default => sub { [] },
handles => {
'add_food' => 'push',
'find_food' => 'grep',
},
);
}
(Also real talk: if you have an actual moose in your kitchen, that might be a disaster! π)
πΈ MANUAL πΈ
So like, Sub::HandlesVia lets you delegate methods from your class straight to the values of your objects' attributes. Iconic behaviour honestly. π
Conceptually, it lets you define $object->push_number($n) to be a shortcut for $object->numbers->push($n) β EXCEPT that $object->numbers is an arrayref, so it literally doesn't have methods you can call on it like push. The way that whole thing is a scam π β that's exactly the gap this fills.
Moose does have a built-in feature (native traits) which provides a more limited version of this.
π Which Methods Can Be Delegated To? π
The handles_via option is basically the vibe check for which library of methods should be available. Valid values include Array, Blessed, Bool, Code, Counter, Enum, Hash, Number, Scalar, and String. Pick your fighter π
You can also hand it an arrayref for handles_via, though ngl many of the options are conceptually contradictory. It's giving chaos but okay:
handles_via => [ 'Number', 'Scalar' ]
π¦ Moose Native Types π¦
So even though the synopsis above shows Types::Standard being used for type constraints, Moose native types should also work fine. Both work, we don't gatekeep. π
package Kitchen {
use Moose;
use Sub::HandlesVia;
has food => (
is => 'ro',
isa => 'ArrayRef[Str]',
handles_via => 'Array',
default => sub { [] },
handles => {
'add_food' => 'push',
'find_food' => 'grep',
},
);
}
β True Moose Native Traits Drop-In Syntax β
Not only that, but Sub::HandlesVia will also recognize native-traits-style traits. It will jump in and handle them before Moose even notices! Sneaky queen behaviour honestly, main character energy π
package Kitchen {
use Moose;
use Sub::HandlesVia;
has food => (
is => 'ro',
isa => 'ArrayRef[Str]',
traits => ['Array'],
default => sub { [] },
handles => {
'add_food' => 'push',
'find_food' => 'grep',
},
);
}
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>.
Bestie if you find a bug, tell the maintainers, don't just suffer in silence fr fr π
π₯ SEE ALSO π₯
- Misc advanced documentation:
Sub::HandlesVia::Manual::Advanced. Sub::HandlesVia.- 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>. β the literal legend, we stan π
π 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.
No promises, no cap, you're on your own if it breaks π
And that's the whole thing, bestie! This page came to you from perl v5.42.0, dated 2026-02-11, and it's the manual for Sub::Ha...thMoose(3) β go forth and delegate, mwah ππ
π¦ 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