Moose::Meta::Attribute::Native::Trait::String(3pm)

Moose::Meta::Attribute::Native::Trait::String3pm

Helper trait for str attributes

Usage

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

Version

version 2.4001

Overview

This trait provides native delegation methods for strings.

Default type

If you don't provide an "isa" value for your attribute, it will default to "Str".

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

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 (not the value passed to "default").

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.

Releases

9 releases since Debian 6.0 (Squeeze); the text changed 8 times.

  1. 6.0
  2. 7
  3. 8
  4. 9
  5. 10
  6. 11
  7. 12
  8. 13
  9. Arch