6 Moose::Cookbook::WTF - For when things go wrong with Moose
12 =head3 Why is my code taking so long to load?
14 Moose has a fairly heavy compile time burden, which it
15 inherits from Class::MOP. If load/compile time is a
16 concern for your application, Moose may not be the
19 Although, you should note that we are exploring the
20 use of L<Module::Compile> to try and reduce this problem,
21 but nothing is ready yet.
23 =head3 Why are my objects taking so long to construct?
25 Moose uses a lot of introspection when constructing an
26 instance, and introspection can be slow. However, this
27 is a temporary problem, and is already solved in
28 Class::MOP by making classes immutable. However immutable
29 support in Moose is not ready yet, but will be soon.
35 =head3 I created an attribute, where are my accessors?
37 Accessors are B<not> created implicitly, you B<must> ask Moose
38 to create them for you. My guess is that you have this:
40 has 'foo' => (isa => 'Bar');
42 when what you really want to say is:
44 has 'foo' => (isa => 'Bar', is => 'rw');
46 The reason this is so, is because it is a perfectly valid use
47 case to I<not> have an accessor. The simplest one is that you
48 want to write your own. If Moose created on automatically, then
49 because of the order in which classes are constructed, Moose
50 would overwrite your custom accessor. You wouldn't want that
53 =head2 Method Modfiers
55 =head3 How come I can't change C<@_> in a C<before> modifier?
57 The C<before> modifier simply is called I<before> the main method.
58 Its return values are simply ignored, and are B<not> passed onto
61 There are a number of reasons for this, but those arguments are
62 too lengthy for this document. Instead, I suggest using an C<around>
63 modifier instead. Here is some sample code:
67 my ($self, @args) = @_;
68 # do something silly here to @args
69 $next->($self, reverse(@args));
72 =head3 How come I can't see return values in an C<after> modifier?
74 As with the C<before> modifier, the C<after> modifier is simply
75 called I<after> the main method. It is passed the original contents
76 of C<@_> and B<not> the return values of the main method.
78 Again, the arguments are too lengthy as to why this has to be. And
79 as with C<before> I recommend using an C<around> modifier instead.
80 Here is some sample code:
84 my ($self, @args) = @_;
85 my @rv = $next->($self, @args);
86 # do something silly with the return values
92 Stevan Little E<lt>stevan@iinteractive.comE<gt>
94 =head1 COPYRIGHT AND LICENSE
96 Copyright 2006 by Infinity Interactive, Inc.
98 L<http://www.iinteractive.com>
100 This library is free software; you can redistribute it and/or modify
101 it under the same terms as Perl itself.