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>.


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