-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
67 lines (45 loc) · 1.31 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
MooseX::ChainedAccessors
Chained accessors on write operations for Moose.
INSTALLATION
To install this module, run the following commands:
perl ./Makefile.PL
make test
make install
USAGE
package MyClass;
use Moose;
has 'chained_attr' =>
(
traits => ['Chained'],
is => 'rw',
isa => 'Str',
);
sub my_method
{
my $self = shift;
print 'hello, ' . $self->chained_attr;
}
1;
MyClass->new->chained_attr('world')->my_method(); # hello, world!
Chained accessors also work with explicit 'reader/writer' accessors.
package MyClass;
use Moose;
has 'attr' =>
(
traits => ['Chained'],
is => 'rw',
isa => 'Str',
reader => 'get_attr',
writer => 'set_sttr',
);
sub my_method
{
my $self = shift;
print $self->get_attr;
}
1l
MyClass->new->set_attr('hello, world')->my_method(); # hello, world
Hopefully it's obvious why read operations can't be chained.
DOCUMENTATION
See http://search.cpan.org/dist/Moose/lib/Moose/Cookbook/Meta/Recipe3.pod for documentation on using traits.
And also http://www.dmclaughlin.com/2009/05/15/chained-accessors-in-moose/ for the release post.