Sub::Ha...Declare(3)
β¨ NAME β¨
Sub::HandlesVia::Declare β bestie, it's literally just declaring delegations at compile-time π
(and yeah, the manual is filed under User Contributed Perl Documentation, which is why the header goes all mysterious and truncates it to Sub::Ha...Declare(3) β the drama of it all π)
π SYNOPSIS π
use Sub::HandlesVia::Declare( $attr, $via => %delegations );
Okay so this is roughly equivalent to the following, no cap:
use Sub::HandlesVia qw(delegations);
BEGIN {
delegations(
attribute => $attr,
handles_via => $via,
handles => \%delegations,
);
};
Except β and this is the little glow-up β it doesn't import the delegations function into your namespace. So polite of it. π
πΈ DESCRIPTION πΈ
Super useful for Object::Pad, and kind of nice for Class::Tiny. Basically any class builder that does its stuff at compile time. It's giving "works with your fave." β¨
π Object::Pad
use Object::Pad;
class Kitchen {
has @foods;
use Sub::HandlesVia::Declare '@foods', Array => (
all_foods => 'all',
add_food => 'push',
);
}
And here's the cute shortcut: if an attribute begins with a '@' or '%', then $via can be omitted. π¦
use Object::Pad;
class Kitchen {
has @foods;
use Sub::HandlesVia::Declare '@foods', (
all_foods => 'all',
add_food => 'push',
);
}
π§ Class::Tiny
package Kitchen;
use Class::Tiny {
foods => sub { [] },
drinks => sub { [ 'water' ] },
};
use Sub::HandlesVia::Declare 'foods', Array => (
all_foods => 'all',
add_food => 'push',
);
use Sub::HandlesVia::Declare 'drinks', Array => (
all_drinks => 'all',
add_drink => 'push',
);
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>.
Not me asking you to actually file the issue though β like, please do, for real fr fr π
π¦ SEE ALSO π¦
- Sub::HandlesVia.
π AUTHOR π
Toby Inkster <tobyink@cpan.org>.
π 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 warranty bestie, you're on your own and that's iconic π )
Sign-off time π β this was brought to you by perl v5.42.0, dated 2026-02-11, and filed in the manual as Sub::Ha...Declare(3). Slay, go declare some delegations. π¦β¨
π¦ 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