foo
[gitmo/Moose.git] / lib / Moose / Cookbook / WTF.pod
CommitLineData
e67a0fca 1
2=pod
3
4=head1 NAME
5
6Moose::Cookbook::WTF - For when things go wrong with Moose
7
8=head1 COMMON PROBLEMS
9
10=head2 Constructors
11
12=head2 Accessors
13
14=head3 I created an attribute, where are my accessors?
15
16Accessors are B<not> created implicitly, you B<must> ask Moose
17to create them for you. My guess is that you have this:
18
19 has 'foo' => (isa => 'Bar');
20
21when what you really want to say is:
22
23 has 'foo' => (isa => 'Bar', is => 'rw');
24
25The reason this is so, is because it is a perfectly valid use
26case to I<not> have an accessor. The simplest one is that you
27want to write your own. If Moose created on automatically, then
28because of the order in which classes are constructed, Moose
29would overwrite your custom accessor. You wouldn't want that
30would you?
31
32=head2 Method Modfiers
33
34=head3 How come I can't change C<@_> in a C<before> modifier?
35
36The C<before> modifier simply is called I<before> the main method.
37Its return values are simply ignored, and are B<not> passed onto
38the main method body.
39
40There are a number of reasons for this, but those arguments are
41too lengthy for this document. Instead, I suggest using an C<around>
42modifier instead. Here is some sample code:
43
44 around 'foo' => sub {
45 my $next = shift;
46 my ($self, @args) = @_;
47 # do something silly here to @args
48 $next->($self, reverse(@args));
49 };
50
51=head3 How come I can't see return values in an C<after> modifier?
52
53As with the C<before> modifier, the C<after> modifier is simply
54called I<after> the main method. It is passed the original contents
55of C<@_> and B<not> the return values of the main method.
56
57Again, the arguments are too lengthy as to why this has to be. And
58as with C<before> I recommend using an C<around> modifier instead.
59Here is some sample code:
60
61 around 'foo' => sub {
62 my $next = shift;
63 my ($self, @args) = @_;
64 my @rv = $next->($self, @args);
65 # do something silly with the return values
66 return reverse @rv;
67 };
68
69=head1 AUTHOR
70
71Stevan Little E<lt>stevan@iinteractive.comE<gt>
72
73=head1 COPYRIGHT AND LICENSE
74
75Copyright 2006 by Infinity Interactive, Inc.
76
77L<http://www.iinteractive.com>
78
79This library is free software; you can redistribute it and/or modify
80it under the same terms as Perl itself.
81
82=cut