Sub::Ha...WithMoo(3)

πŸ’– Sub::HandlesVia::Manual::WithMoo πŸ’–

okay bestie, so this is the manual page for Sub::HandlesVia::Manual::WithMoo β€” the glow-up guide for using Sub::HandlesVia with Moo. it's part of the User Contributed Perl Documentation, and it's lowkey iconic. let's get into it ✨


🌸 SYNOPSIS 🌸

package Kitchen {
  use Moo;
  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',
    },
  );
}

πŸ¦‹ MANUAL πŸ¦‹

so here's the tea: Sub::HandlesVia lets you delegate methods from your class to the values of your objects' attributes. that's it, that's the whole vibe. πŸ’…

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 doesn't have methods you can call on it like push. so Sub::HandlesVia is out here doing the work so you don't have to. main character energy fr fr. πŸ‘‘

you should be able to use Sub::HandlesVia as a drop-in replacement for MooX::HandlesVia, which provides a similar feature but has a more limited implementation. Sub::HandlesVia actually honours type constraints, plus it can mutate non-reference values. no cap. πŸ”₯

✨ Which Methods Can Be Delegated To? ✨

the handles_via option is the one that says which library of methods should be available. valid values include Array, Blessed, Bool, Code, Counter, Enum, Hash, Number, Scalar, and String. periodt. πŸ’«

you can hand it an arrayref for handles_via, though ngl many of the options are conceptually contradictory. like, bestie, pick a lane:

handles_via => [ 'Number', 'Scalar' ]

πŸ’€ BUGS πŸ’€

please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>. we love a good bug report, it's giving community care. 🫢

πŸ™ˆ Potential load order bugs πŸ™ˆ

unlike Moose, Moo doesn't really offer much of an API for extensions. as a result, most modules that provide extensions do so by wrapping the Moo keywords (especially has). Sub::HandlesVia is no exception to this. if you're using multiple Moo extensions, you may need to adjust the order you use them for them to work properly together. and in some combinations, there may be no order that fully works! 😭 yes really.

  • some known modules that should be imported before Sub::HandlesVia if you're using them: MooX::Should.
  • some known modules that should be imported after Sub::HandlesVia if you're using them: MooX::ProtectedAttributes.
  • some known modules that conflict with Sub::HandlesVia: none so far! 🌈

πŸŽ€ 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, and Sub::HandlesVia::HandlerLibrary::String.

πŸ‘‘ AUTHOR πŸ‘‘

Toby Inkster <tobyink@cpan.org>. absolute legend, we stan. πŸ’œ


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.

okay that one's in all caps and kinda scary but it's just the standard legal bit, bestie. it means no promises, use at your own risk. πŸ’–

and that's the whole page!! πŸŽ‰ this was documented for perl v5.42.0 on 2026-02-11, and it's filed under Sub::HandlesVia::Manual::WithMoo(3) in the User Contributed Perl Documentation. go forth and delegate, queen. πŸ¦‹βœ¨

πŸ“¦ where this page comes from