Sub::Ha...::Scalar(3)

✨ NAME ✨

Sub::HandlesVia::HandlerLibrary::Scalar β€” bestie, it's a whole library of scalar-related methods πŸ’…

(okay so quick vibe check: this is a Perl manual page, Sub::Ha...::Scalar(3), from the User Contributed Perl Documentation. yes the title got abbreviated by the man renderer, that's just how it be πŸŽ€)


πŸ¦‹ SYNOPSIS πŸ¦‹

no cap, here's the whole thing:

package My::Class {
  use Moo;
  use Sub::HandlesVia;
  use Types::Standard 'Any';
  has attr => (
    is => 'rwp',
    isa => Any,
    handles_via => 'Scalar',
    handles => {
      'my_get' => 'get',
      'my_make_getter' => 'make_getter',
      'my_make_setter' => 'make_setter',
      'my_scalar_reference' => 'scalar_reference',
      'my_set' => 'set',
      'my_stringify' => 'stringify',
    },
  );
}

like... look at that. handles_via => 'Scalar' and suddenly your attribute has a whole little friend group of methods. obsessed. πŸ’–


🌸 DESCRIPTION 🌸

This is a library of methods for Sub::HandlesVia. That's it, that's the description, she's concise and she knows it. ✨


πŸ‘‘ DELEGATABLE METHODS πŸ‘‘

okay bestie here come the actual methods, this is the main character section fr fr 🫢

🌈 get()

Gets the current value of the scalar. that's it. simple. iconic. πŸ’…

πŸŽ€ make_getter()

Returns a getter coderef. yes a whole coderef, a little grabby function you can pass around, she's portable 😌

my $object = My::Class->new( attr => 10 );
my $getter = $object->my_make_getter;
$object->_set_attr( 11 );
say $getter->(); ## ==> 11

notice how the getter sees the new value even after _set_attr? because it's reading the live slot, not a stale copy. slay. πŸ”₯

🧚 make_setter()

Returns a setter coderef. same energy but it writes instead of reads πŸ’œ

my $object = My::Class->new( attr => 10 );
my $setter = $object->my_make_setter;
$setter->( 11 );
say $object->attr; ## ==> 11

call it, attribute changes. periodt.

πŸ“ scalar_reference()

Returns a scalar reference to the attribute value's slot within its object.

ngl this one is lowkey feral in the best way, because you get a reference straight into the object's guts, so you can mutate it in place and the object just... knows. πŸ’€

my $object = My::Class->new( attr => 10 );
my $ref = $object->my_scalar_reference;
$$ref++;
say $object->attr; ## ==> 11

see how $$ref++ bumped the actual attribute? main character behavior. πŸ‘‘

⭐ set( $value )

Sets the scalar to a new value. give it $value, it goes in. done. ✨

πŸ’– stringify()

Gets the current value of the scalar, but as a string. same value, stringy lil outfit on it πŸŽ€


😭 BUGS 😭

Please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>.

(no fr, if something's broken, tell Toby, don't just suffer in silence bestie πŸ™ˆ)


πŸ’œ SEE ALSO πŸ’œ

  • Sub::HandlesVia β€” the parent vibe, go read it

🌸 AUTHOR 🌸

Toby Inkster <tobyink@cpan.org>. legend behavior, honestly. πŸ‘‘


This software is copyright (c) 2020, 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.

translation: no promises, no guarantees, you get what you get and it's giving "use at your own risk" 🫢


and that's the whole page, bestie!! this one came from perl v5.42.0, dated 2026-02-11, and the manual page itself is Sub::Ha...::Scalar(3) β€” yes the name got clipped in the header, the man renderer said "we're abbreviating" and honestly? respect. πŸ’…βœ¨

πŸ“¦ where this page comes from