1MouseX::NativeTraits::SUtsre(r3)Contributed Perl DocumenMtoautsieoXn::NativeTraits::Str(3)
2
3
4

NAME

6       MouseX::NativeTraits::Str - Helper trait for Str attributes
7

SYNOPSIS

9         package MyHomePage;
10         use Mouse;
11
12         has 'text' => (
13             traits    => ['String'],
14             is        => 'rw',
15             isa       => 'Str',
16             default   => q{},
17             handles   => {
18                 add_text     => 'append',
19                 replace_text => 'replace',
20             },
21         );
22
23         my $page = MyHomePage->new();
24         $page->add_text("foo"); # same as $page->text($page->text . "foo");
25

DESCRIPTION

27       This module provides a simple string attribute, to which mutating
28       string operations can be applied more easily (no need to make an lvalue
29       attribute metaclass or use temporary variables). Additional methods are
30       provided for completion.
31

PROVIDED METHODS

33       These methods are implemented in
34       MouseX::NativeTraits::MethodProvider::Str. It is important to note that
35       all those methods do in place modification of the value stored in the
36       attribute.
37
38       inc Increments the value stored in this slot using the magical string
39           autoincrement operator. Note that Perl doesn't provide analogous
40           behavior in "--", so "dec" is not available.
41
42       append($string)
43           Append a string, like ".=".
44
45       prepend($string)
46           Prepend a string.
47
48       replace($pattern, $replacement)
49           Performs a regexp substitution ("s" in perlop).  A code references
50           will be accepted for the replacement, causing the regexp to be
51           modified with a single "e". "/smxi" can be applied using the "qr"
52           operator.
53
54       replace($pattern, $replacement)
55           Performs a regexp substitution ("s" in perlop) with the "g" flag.
56           A code references will be accepted for the replacement, causing the
57           regexp to be modified with a single "e". "/smxi" can be applied
58           using the "qr" operator.
59
60       match($pattern)
61           Like "replace" but without the replacement. Provided mostly for
62           completeness.
63
64       chop
65           "chop" in perlfunc
66
67       chomp
68           "chomp" in perlfunc
69
70       clear
71           Sets the string to the empty string (not the value passed to
72           "default").
73
74       length
75           "length" in perlfunc
76
77       substr
78           "substr" in perlfunc. We go to some lengths to match the different
79           functionality based on "substr"'s arity.
80

METHODS

82       meta
83       method_provider_class
84       helper_type
85

SEE ALSO

87       MouseX::NativeTraits
88
89
90
91perl v5.28.0                      2012-11-26      MouseX::NativeTraits::Str(3)
Impressum