MooseX...:String(3pm)

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

πŸ’– MooseX::AttributeHelpers::Trait::String β€” bestie edition πŸ’–

User Contributed Perl Documentation Β· the 3pm manual, but make it cute


✨ NAME ✨

MooseX::AttributeHelpers::Trait::String β€” it's giving simple string attribute πŸŽ€


🌸 VERSION 🌸

version 0.25 (yes bestie, that's the one)


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so this is literally how you use it, no cap:

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");

πŸ’… DESCRIPTION πŸ’…

So basically this module hands you a simple string attribute, and the whole point is that mutating string operations become so much easier to apply. No more making an lvalue attribute metaclass, no more juggling temporary variables β€” we're not doing that anymore, periodt. βœ‹ And there's extra methods provided for completion, because we're thorough like that. 🫢

Here's the tea though: if your attribute definition doesn't include any of is, isa, default or provides, but does use the "String" metaclass, then this module just applies the defaults, exactly like in the SYNOPSIS up there. Which means you can do a very basic counter definition like this:

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

Look at that. effortless. ⭐


πŸ”₯ METHODS πŸ”₯

  • meta β€” the meta, as one does πŸ’
  • method_provider β€” provides the methods, iconic behaviour honestly
  • has_method_provider β€” checks whether it has a method provider
  • helper_type β€” the helper type
  • process_options_for_provides β€” this one runs before its superclass method, so keep that in mind bestie
  • check_provides_values β€” and this one runs after its superclass method πŸ‘‘

πŸ‘‘ PROVIDED METHODS πŸ‘‘

⚠️ okay super important, don't skip this: all of these methods do in place modification of the value stored in the attribute. Like, they're changing the actual thing, not handing you a copy. Noted? Noted. πŸ’€
  • inc β€” increments the value stored in this slot using the magical string autoincrement operator ✨ But heads up: Perl doesn't provide analogeous behavior in "--", so "dec" is not available. Sorry bestie, it's just not a thing. 😭
  • append $string β€” appends a string, like .= πŸ“
  • prepend $string β€” prepends a string, the other direction, we love range πŸ’œ
  • replace $pattern $replacement β€” performs a regexp substitution ("s" in perlop). There's no way to provide the "g" flag, which is lowkey tragic, but code references will be accepted for the replacement, and that causes the regex to be modified with a single "e". You can apply "/smxi" using the "qr" operator. iykyk 🌈
  • match $pattern β€” like replace but without the replacement. It's provided mostly for completeness, and honestly? valid. ⭐
  • "chop" β€” "chop" in perlfunc πŸ’…
  • "chomp" β€” "chomp" in perlfunc πŸ’…
  • "clear" β€” sets the string to the empty string. And no, not the value passed to "default" β€” the actual empty string, don't get it twisted. πŸ™ˆ

🧚 SUPPORT 🧚

Got bugs? First of all, same, but for this you can submit them through the RT bug tracker at <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> β€” or you can email bug-MooseX-AttributeHelpers@rt.cpan.org <mailto:bug-MooseX-AttributeHelpers@rt.cpan.org>. πŸ›

There's also a mailing list for users of this distribution, over 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, the vibes are immaculate. πŸ’¬


🌈 AUTHOR 🌈

Stevan Little <stevan@iinteractive.com> β€” the main character who wrote this fr fr πŸ‘‘


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


and that's the whole page bestie β€” this was perl v5.34.0, dated 2022-06-15, and the manual was MooseX...:String(3pm) all along. slay, go write some string attributes. πŸ’–βœ¨

πŸ“¦ where this page comes from