| 1 | use MooseX::Declare; | ||
| 2 | |||
| 3 | class CatalystX::Declare::Keyword::Application | ||
| 4 | extends MooseX::Declare::Syntax::Keyword::Class { | ||
| 5 | |||
| 6 | use aliased 'CatalystX::Declare::Context::AppSetup'; | ||
| 7 | |||
| 8 | |||
| 9 | override auto_make_immutable { 0 } | ||
| 10 | |||
| 11 | around context_traits { $self->$orig, AppSetup } | ||
| 12 | |||
| 13 | override add_with_option_customizations (Object $ctx, Str $package, ArrayRef $plugins, HashRef $options) { | ||
| 14 | |||
| 15 | $ctx->add_setup_code_parts($package, $plugins) | ||
| 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 | } | ||
| 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 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | =head1 NAME | ||
| 34 | |||
| 35 | CatalystX::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 | |||
| 55 | This module provides a keyword handler for the C<application> keyword. It is an | ||
| 56 | extension of L<MooseX::Declare/class>. The role application mechanism behind | ||
| 57 | the C<with> specification is hijacked and the arguments are passed to | ||
| 58 | Catalyst's C<setup> method. This hijacking is proably going away someday since | ||
| 59 | in the future plugins will be actual roles. | ||
| 60 | |||
| 61 | You don't have to call the C<setup> method yourself, this will be done by the | ||
| 62 | handler after the body has been run. | ||
| 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 | |||
| 78 | A modified method that returns C<0> to signal to L<MooseX::Declare> that it | ||
| 79 | should not make this class immutable. Currently, making application classes | ||
| 80 | immutable isn't supported yet, therefore C<is mutable> is currently a no-op. | ||
| 81 | This will likely change as soon as application classes can be made immutable, | ||
| 82 | |||
| 83 | =head2 context_traits | ||
| 84 | |||
| 85 | List[ClassName] Object->context_traits () | ||
| 86 | |||
| 87 | This extends the remaining context traits with | ||
| 88 | L<CatalystX::Declare::Context::AppSetup> to manage calls to | ||
| 89 | L<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 | |||
| 100 | This will prepare L<Catalyst/MyApp-E<gt>setup> to be called with the list of | ||
| 101 | plugins that were specified as roles. | ||
| 102 | |||
| 103 | =head2 add_namespace_customizations | ||
| 104 | |||
| 105 | Object->add_namespace_customizations (Object $ctx, Str $package) | ||
| 106 | |||
| 107 | This will prepare L<Catalyst> as a parent and import L<CLASS> into the | ||
| 108 | application'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 | |||
| 114 | After all customizations have been done, this modifier will push a call to | ||
| 115 | L<Catalyst/MyApp-E<gt>setup> if this wasn't already done by the plugin | ||
| 116 | specifications. | ||
| 117 | |||
| 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 | |||
| 132 | See L<CatalystX::Declare/AUTHOR> for author information. | ||
| 133 | |||
| 134 | =head1 LICENSE | ||
| 135 | |||
| 136 | This program is free software; you can redistribute it and/or modify it under | ||
| 137 | the same terms as perl itself. | ||
| 138 | |||
| 139 | =cut |