Moose::...::String(3)
β¨ Moose::...::String(3) β¨
okay bestie, welcome to the Moose::Meta::Attribute::Native::Trait::String page π this is the helper trait for Str attributes, and it's genuinely one of the most useful little traits in the whole Moose ecosystem. it's part of the User Contributed Perl Documentation, and ngl, it's giving "tiny file, huge slay". πΈ
π VERSION
version 2.4000 β that's the one you're reading right now, no cap.
π¦ SYNOPSIS
here's the vibe, fr fr. you slap the String trait on an attribute and suddenly you get free methods that delegate right into the string:
package MyHomePage;
use Moose;
has 'text' => (
traits => ['String'],
is => 'rw',
isa => 'Str',
default => q{},
handles => {
add_text => 'append',
replace_text => 'replace',
},
);
my $page = MyHomePage->new();
$page->add_text("foo"); # same as $page->text($page->text . "foo");
see how add_text is just append in a cute little outfit? and replace_text is replace? that's the whole trick. handles maps your chosen method name to the trait's provided method, and boom β main character attribute. π
π DESCRIPTION
This trait provides native delegation methods for strings. that's it, that's the pitch β but it's a great pitch. π«Ά
π DEFAULT TYPE
If you don't provide an isa value for your attribute, it will default to Str. so you can be lazy and it'll still be correct. iconic behaviour, honestly.
π₯ PROVIDED METHODS
inc
Increments the value stored in this slot using the magical string autoincrement operator. note that Perl doesn't provide analogous behavior in --, so dec is not available β sorry babes, the decrement just isn't a thing here. This method returns the new value.
This method does not accept any arguments.
append($string)
Appends to the string, like .=, and returns the new value.
This method requires a single argument.
prepend($string)
Prepends to the string and returns the new value. front-loading the content, we love to see it. β¨
This method requires a single argument.
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, causing the regex to be modified with a single e. /smxi can be applied using the qr operator. This method returns the new value.
This method requires two arguments.
match($pattern)
Runs the regex against the string and returns the matching value(s).
This method requires a single argument.
chop
Just like chop in perlfunc. This method returns the chopped character.
This method does not accept any arguments.
chomp
Just like chomp in perlfunc. This method returns the number of characters removed.
This method does not accept any arguments.
clear
Sets the string to the empty string β and yes, that's the empty string, not the value passed to default. so don't come crying to me when your default doesn't come back. π
This method does not have a defined return value.
This method does not accept any arguments.
length
Just like length in perlfunc, returns the length of the string.
substr
This acts just like substr in perlfunc. When called as a writer, it returns the substring that was replaced, just like the Perl builtin.
This method requires at least one argument, and accepts no more than three.
π BUGS
See BUGS in Moose for details on reporting bugs. (go tell the Moose folks, they're nice, i promise.)
π AUTHORS
- Stevan Little <stevan@cpan.org>
- Dave Rolsky <autarch@urth.org>
- Jesse Luehrs <doy@cpan.org>
- Shawn M Moore <sartak@cpan.org>
- ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman) <nothingmuch@woobling.org>
- Karen Etheridge <ether@cpan.org>
- Florian Ragwitz <rafl@debian.org>
- Hans Dieter Pearcey <hdp@cpan.org>
- Chris Prather <chris@prather.org>
- Matt S Trout <mstrout@cpan.org>
a whole ensemble cast. absolutely ate. π§
β COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by 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.42.0, dated 2025-07-25, from Moose::...::String(3). now go forth and append things. periodt. ππΈπ¦π
π«Ά
π¦ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms