merging the immutable branch into trunk
[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
2a0f3bd3 10=head2 Speed
11
12=head3 Why is my code taking so long to load?
13
14Moose has a fairly heavy compile time burden, which it
15inherits from Class::MOP. If load/compile time is a
16concern for your application, Moose may not be the
17right tool for you.
18
19Although, you should note that we are exploring the
20use of L<Module::Compile> to try and reduce this problem,
21but nothing is ready yet.
22
23=head3 Why are my objects taking so long to construct?
24
25Moose uses a lot of introspection when constructing an
26instance, and introspection can be slow. However, this
27is a temporary problem, and is already solved in
28Class::MOP by making classes immutable. However immutable
29support in Moose is not ready yet, but will be soon.
30
e67a0fca 31=head2 Constructors
32
33=head2 Accessors
34
35=head3 I created an attribute, where are my accessors?
36
37Accessors are B<not> created implicitly, you B<must> ask Moose
38to create them for you. My guess is that you have this:
39
40 has 'foo' => (isa => 'Bar');
41
42when what you really want to say is:
43
44 has 'foo' => (isa => 'Bar', is => 'rw');
45
46The reason this is so, is because it is a perfectly valid use
47case to I<not> have an accessor. The simplest one is that you
48want to write your own. If Moose created on automatically, then
49because of the order in which classes are constructed, Moose
50would overwrite your custom accessor. You wouldn't want that
51would you?
52
53=head2 Method Modfiers
54
55=head3 How come I can't change C<@_> in a C<before> modifier?
56
57The C<before> modifier simply is called I<before> the main method.
58Its return values are simply ignored, and are B<not> passed onto
59the main method body.
60
61There are a number of reasons for this, but those arguments are
62too lengthy for this document. Instead, I suggest using an C<around>
63modifier instead. Here is some sample code:
64
65 around 'foo' => sub {
66 my $next = shift;
67 my ($self, @args) = @_;
68 # do something silly here to @args
69 $next->($self, reverse(@args));
70 };
71
72=head3 How come I can't see return values in an C<after> modifier?
73
74As with the C<before> modifier, the C<after> modifier is simply
75called I<after> the main method. It is passed the original contents
76of C<@_> and B<not> the return values of the main method.
77
78Again, the arguments are too lengthy as to why this has to be. And
79as with C<before> I recommend using an C<around> modifier instead.
80Here is some sample code:
81
82 around 'foo' => sub {
83 my $next = shift;
84 my ($self, @args) = @_;
85 my @rv = $next->($self, @args);
86 # do something silly with the return values
87 return reverse @rv;
88 };
89
90=head1 AUTHOR
91
92Stevan Little E<lt>stevan@iinteractive.comE<gt>
93
94=head1 COPYRIGHT AND LICENSE
95
96Copyright 2006 by Infinity Interactive, Inc.
97
98L<http://www.iinteractive.com>
99
100This library is free software; you can redistribute it and/or modify
101it under the same terms as Perl itself.
102
103=cut