fixed bug where setup wasn't called without plugins
[catagits/CatalystX-Declare.git] / lib / CatalystX / Declare / Keyword / Application.pm
CommitLineData
856ac9a7 1use MooseX::Declare;
2
3class CatalystX::Declare::Keyword::Application
4 extends MooseX::Declare::Syntax::Keyword::Class {
5
4f00d8db 6 use aliased 'CatalystX::Declare::Context::AppSetup';
7
856ac9a7 8
9 override auto_make_immutable { 0 }
10
4f00d8db 11 around context_traits { $self->$orig, AppSetup }
12
856ac9a7 13 override add_with_option_customizations (Object $ctx, Str $package, ArrayRef $plugins, HashRef $options) {
14
4f00d8db 15 $ctx->add_setup_code_parts($package, $plugins)
856ac9a7 16 }
17
18 before add_namespace_customizations (Object $ctx, Str $package) {
19
20 $ctx->add_preamble_code_parts(
21 'use CLASS',
22 'use parent q{Catalyst}',
23 );
24 }
4f00d8db 25
26 after add_optional_customizations (Object $ctx, Str $package) {
27
28 $ctx->add_setup_code_parts($package)
29 unless $ctx->setup_was_called;
30 }
856ac9a7 31}
32
33=head1 NAME
34
35CatalystX::Declare::Keyword::Application - Declare Catalyst Application Classes
36
37=head1 SYNOPSIS
38
39 use CatalystX::Declare;
40
41 application MyApp::Web
42 with Static::Simple
43 with ConfigLoader {
44
45 $CLASS->config(name => 'My App');
46
47 method debug_timestamp {
48 $self->log->debug('Timestamp: ' . time)
49 if $self->debug;
50 }
51 }
52
53=head1 DESCRIPTION
54
55This module provides a keyword handler for the C<application> keyword. It is an
56extension of L<MooseX::Declare/class>. The role application mechanism behind
57the C<with> specification is hijacked and the arguments are passed to
58Catalyst's C<setup> method. This hijacking is proably going away someday since
59in the future plugins will be actual roles.
60
61You don't have to call the C<setup> method yourself, this will be done by the
744e2821 62handler after the body has been run.
856ac9a7 63
64=head1 SUPERCLASSES
65
66=over
67
68=item L<MooseX::Declare::Syntax::Keyword::Class>
69
70=back
71
72=head1 METHODS
73
74=head2 auto_make_immutable
75
76 Bool Object->auto_make_immutable ()
77
78A modified method that returns C<0> to signal to L<MooseX::Declare> that it
79should not make this class immutable. Currently, making application classes
80immutable isn't supported yet, therefore C<is mutable> is currently a no-op.
81This will likely change as soon as application classes can be made immutable,
82
4f00d8db 83=head2 context_traits
84
85 List[ClassName] Object->context_traits ()
86
87This extends the remaining context traits with
88L<CatalystX::Declare::Context::AppSetup> to manage calls to
89L<Catalyst/MyApp-E<gt>setup>.
90
91=head2 add_with_option_customizations
92
93 Object->add_with_option_customizations (
94 Object $ctx,
95 Str $package,
96 ArrayRef $plugins,
97 HashRef $options
98 )
99
100This will prepare L<Catalyst/MyApp-E<gt>setup> to be called with the list of
101plugins that were specified as roles.
102
103=head2 add_namespace_customizations
104
105 Object->add_namespace_customizations (Object $ctx, Str $package)
106
107This will prepare L<Catalyst> as a parent and import L<CLASS> into the
108application's namespace before the other customizations are run.
109
110=head2 add_optional_customizations
111
112 Object->add_optional_customizations (Object $ctx, Str $package)
113
114After all customizations have been done, this modifier will push a call to
115L<Catalyst/MyApp-E<gt>setup> if this wasn't already done by the plugin
116specifications.
117
856ac9a7 118=head1 SEE ALSO
119
120=over
121
122=item L<CatalystX::Declare>
123
124=item L<MooseX::Declare/class>
125
126=item L<MooseX::Declare::Syntax::Keyword::Class>
127
128=back
129
130=head1 AUTHOR
131
132See L<CatalystX::Declare/AUTHOR> for author information.
133
134=head1 LICENSE
135
136This program is free software; you can redistribute it and/or modify it under
137the same terms as perl itself.
138
139=cut