6 Moose::Cookbook::WTF - For when things go wrong with Moose
14 =head3 I created an attribute, where are my accessors?
16 Accessors are B<not> created implicitly, you B<must> ask Moose
17 to create them for you. My guess is that you have this:
19 has 'foo' => (isa => 'Bar');
21 when what you really want to say is:
23 has 'foo' => (isa => 'Bar', is => 'rw');
25 The reason this is so, is because it is a perfectly valid use
26 case to I<not> have an accessor. The simplest one is that you
27 want to write your own. If Moose created on automatically, then
28 because of the order in which classes are constructed, Moose
29 would overwrite your custom accessor. You wouldn't want that
32 =head2 Method Modfiers
34 =head3 How come I can't change C<@_> in a C<before> modifier?
36 The C<before> modifier simply is called I<before> the main method.
37 Its return values are simply ignored, and are B<not> passed onto
40 There are a number of reasons for this, but those arguments are
41 too lengthy for this document. Instead, I suggest using an C<around>
42 modifier instead. Here is some sample code:
46 my ($self, @args) = @_;
47 # do something silly here to @args
48 $next->($self, reverse(@args));
51 =head3 How come I can't see return values in an C<after> modifier?
53 As with the C<before> modifier, the C<after> modifier is simply
54 called I<after> the main method. It is passed the original contents
55 of C<@_> and B<not> the return values of the main method.
57 Again, the arguments are too lengthy as to why this has to be. And
58 as with C<before> I recommend using an C<around> modifier instead.
59 Here is some sample code:
63 my ($self, @args) = @_;
64 my @rv = $next->($self, @args);
65 # do something silly with the return values
71 Stevan Little E<lt>stevan@iinteractive.comE<gt>
73 =head1 COPYRIGHT AND LICENSE
75 Copyright 2006 by Infinity Interactive, Inc.
77 L<http://www.iinteractive.com>
79 This library is free software; you can redistribute it and/or modify
80 it under the same terms as Perl itself.