MooseX...String(3pm)

πŸ“¦
version 0.25 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

MooseX::AttributeHelpers::String β€” it's the string attribute type, bestie. ✨ And yeah, the page itself is filed under MooseX...String(3pm) in the User Contributed Perl Documentation, iykyk. 🫢


πŸŽ€ VERSION πŸŽ€

version 0.25 β€” that's it, that's the whole vibe. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

package MyHomePage;
use Moose;
use MooseX::AttributeHelpers;

has 'text' => (
    metaclass => 'String',
    is        => 'rw',
    isa       => 'Str',
    default   => sub { '' },
    provides  => {
        append => "add_text",
        replace => "replace_text",
    }
);

my $page = MyHomePage->new();
$page->add_text("foo"); # same as $page->text($page->text . "foo");

So like, notice how the provides hash is where you name your own lil methods? That's the whole trick. 🌸 And then:

$page->add_text("foo"); # same as $page->text($page->text . "foo");

is doing exactly the same thing as $page->text($page->text . "foo"). Same energy, way cuter. 😌


🌈 DESCRIPTION 🌈

This module gives you a simple string attribute that you can throw mutating string operations at way more easily β€” no need to make an lvalue attribute metaclass, and no need for temporary variables. Additional methods are provided for completion too. Obsessed. πŸ’–

Okay so here's the part that lowkey slays: if your attribute definition does not include any of is, isa, default or provides, but it does use the "String" metaclass, then this module applies the defaults exactly like in the "SYNOPSIS" above. Which means you can write a very basic counter definition like this and it just works:

has 'foo' => (metaclass => 'String');
$obj->append_foo;

✨ METHODS ✨

  • meta
  • method_provider
  • has_method_provider
  • helper_type
  • process_options_for_provides β€” run before its superclass method.
  • check_provides_values β€” run after its superclass method.

πŸ‘‘ PROVIDED METHODS πŸ‘‘

🚨 IMPORTANT SIS: all of these methods do in place modification of the value stored in the attribute. Like, the value is changed. No takebacks. πŸ’€
  • inc β€” increments the value stored in this slot using the magical string autoincrement operator. But heads up: Perl doesn't provide analogous behavior in --, so dec is not available. 😭
  • append $string β€” appends a string, like .=.
  • prepend $string β€” prepends a string.
  • replace $pattern $replacement β€” performs a regexp substitution (s in perlop). There is no way to provide the g flag, but code references will be accepted for the replacement, which causes the regex to be modified with a single e. And /smxi can be applied using the qr operator. 🧚
  • match $pattern β€” like replace but without the replacement. Provided mostly for completeness. πŸŽ€
  • chop β€” it's chop in perlfunc.
  • chomp β€” it's chomp in perlfunc.
  • clear β€” sets the string to the empty string, and not the value passed to default. Don't get it twisted. πŸ’…

πŸ’œ SUPPORT πŸ’œ

Bugs may be submitted through the RT bug tracker β€” https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers β€” or by email at bug-MooseX-AttributeHelpers@rt.cpan.org. πŸ›

There's also a mailing list for users of this distribution, at http://lists.perl.org/list/moose.html.

And there's an irc channel for users of this distribution too β€” #moose on irc.perl.org (irc://irc.perl.org/#moose). Come hang out fr fr. 🫢


⭐ AUTHOR ⭐

Stevan Little <stevan@iinteractive.com> β€” king behavior, honestly. πŸ‘‘


This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 🌈


okay that's the whole page bestie, go forth and mutate some strings πŸ’… This was MooseX...String(3pm) as shipped with perl v5.34.0, dated 2022-06-15. Stay iconic, and remember: no cap, only append. βœ¨πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from