Sub::Ha...assTiny(3)

✨ Sub::HandlesVia::Manual::WithClassTiny ✨

okay bestie, so this is a page from the User Contributed Perl Documentation β€” it's the manual for Sub::HandlesVia::Manual::WithClassTiny, aka "how to use Sub::HandlesVia when your class is built with Class::Tiny". it's giving very specific but very useful, iykyk. πŸ’…


🌸 NAME 🌸

Sub::HandlesVia::Manual::WithClassTiny β€” using Sub::HandlesVia with Class::Tiny. periodt.


πŸŽ€ SYNOPSIS πŸŽ€

look at this absolute icon of a setup:

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',
);

like. the vibes. a Kitchen with foods and drinks and methods that just... show up. obsessed. πŸ“


πŸ’– MANUAL πŸ’–

so Sub::HandlesVia lets you delegate methods from your class straight to the values of your objects' attributes. it's the group project where nobody has to do anything because the delegation handles it. no cap.

conceptually, it lets you define $object->push_number($n) as a shortcut for $object->numbers->push($n) β€” except that $object->numbers is an arrayref, so it literally does not have methods you can call on it like push. tragic, honestly. that's the whole problem this module fixes. 😭

πŸ¦‹ Which Methods Can Be Delegated To? πŸ¦‹

the second parameter (that's Array in the synopsis, bestie) tells you which library of methods should be available. valid values include:

  • Array
  • Blessed
  • Bool
  • Code
  • Counter
  • Enum
  • Hash
  • Number
  • Scalar
  • String

you can also hand it an arrayref of them, though lowkey a lot of these options are conceptually contradictory, so maybe don't go feral:

use Sub::HandlesVia::Declare 'num', [ 'Number', 'Scalar' ] => (
  ...,
);

🌈 Run-Time Delegation 🌈

instead of Sub::HandlesVia::Declare, which operates at compile time, you can use the delegations function at run time. which one you pick is largely down to style and personal preference β€” main character energy either way. πŸ’…

package Kitchen;

use Class::Tiny {
  foods  => sub { [] },
  drinks => sub { [ 'water' ] },
};

use Sub::HandlesVia qw( delegations );

delegations(
  attribute    => 'foods',
  handles_via  => 'Array',
  handles      => {
    all_foods    => 'all',
    add_food     => 'push',
  },
);

delegations(
  attribute    => 'drinks',
  handles_via  => 'Array',
  handles      => {
    all_drinks   => 'all',
    add_drink    => 'push',
  },
);

πŸ’€ BUGS πŸ’€

please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>. do it fr fr, the maintainer wants to know. πŸ™ˆ


πŸ‘‘ 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
    • Sub::HandlesVia::HandlerLibrary::String

🫢 AUTHOR 🫢

Toby Inkster <tobyink@cpan.org>. an absolute legend, ngl. ⭐


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 yeah, no promises bestie, it's giving "use at your own risk" but make it legal. 😭


and that's the whole page!! this one's from perl v5.42.0, dated 2026-02-11, and it lives under the manual name Sub::Ha...assTiny(3) in the User Contributed Perl Documentation. slay, go delegate some methods, and remember: the attribute doesn't have methods, but you do now. πŸ’…βœ¨

πŸ“¦ where this page comes from