MooseX...String(3pm)
π 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 β¨
metamethod_providerhas_method_providerhelper_typeprocess_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--, sodecis not available. πappend$stringβ appends a string, like.=.prepend$stringβ prepends a string.replace$pattern$replacementβ performs a regexp substitution (sin perlop). There is no way to provide thegflag, but code references will be accepted for the replacement, which causes the regex to be modified with a singlee. And/smxican be applied using theqroperator. π§match$patternβ likereplacebut without the replacement. Provided mostly for completeness. πchopβ it'schopin perlfunc.chompβ it'schompin perlfunc.clearβ sets the string to the empty string, and not the value passed todefault. 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. π
π COPYRIGHT AND LICENSE π
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
- debian bookworm: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-attributehelpers-perl 0.25-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms