Commit | Line | Data |
e67a0fca |
1 | |
2 | =pod |
3 | |
4 | =head1 NAME |
5 | |
6 | Moose::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 | |
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 |
17 | right tool for you. |
18 | |
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. |
22 | |
23 | =head3 Why are my objects taking so long to construct? |
24 | |
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. |
30 | |
e67a0fca |
31 | =head2 Constructors |
32 | |
33 | =head2 Accessors |
34 | |
35 | =head3 I created an attribute, where are my accessors? |
36 | |
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: |
39 | |
40 | has 'foo' => (isa => 'Bar'); |
41 | |
42 | when what you really want to say is: |
43 | |
44 | has 'foo' => (isa => 'Bar', is => 'rw'); |
45 | |
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 |
51 | would you? |
52 | |
53 | =head2 Method Modfiers |
54 | |
55 | =head3 How come I can't change C<@_> in a C<before> modifier? |
56 | |
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 |
59 | the main method body. |
60 | |
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: |
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 | |
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. |
77 | |
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: |
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 | |
92 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
93 | |
94 | =head1 COPYRIGHT AND LICENSE |
95 | |
b77fdbed |
96 | Copyright 2006, 2007 by Infinity Interactive, Inc. |
e67a0fca |
97 | |
98 | L<http://www.iinteractive.com> |
99 | |
100 | This library is free software; you can redistribute it and/or modify |
101 | it under the same terms as Perl itself. |
102 | |
103 | =cut |