MooseX...:String(3pm)
π 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 honestlyhas_method_providerβ checks whether it has a method providerhelper_typeβ the helper typeprocess_options_for_providesβ this one runs before its superclass method, so keep that in mind bestiecheck_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 π
π 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. π«Ά
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
- 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