| 1 |
NAME |
| 2 |
CatalystX::InjectComponent - Inject components into your Catalyst |
| 3 |
application |
| 4 |
|
| 5 |
VERSION |
| 6 |
version 0.025 |
| 7 |
|
| 8 |
SYNOPSIS |
| 9 |
package My::App; |
| 10 |
|
| 11 |
use Catalyst::Runtime '5.80'; |
| 12 |
|
| 13 |
use Moose; |
| 14 |
BEGIN { extends qw/Catalyst/ } |
| 15 |
|
| 16 |
... |
| 17 |
|
| 18 |
after 'setup_components' => sub { |
| 19 |
my $class = shift; |
| 20 |
CatalystX::InjectComponent->inject( into => $class, component => 'MyModel' ); |
| 21 |
if ( $class->config->{ ... ) { |
| 22 |
CatalystX::InjectComponent->inject( into => $class, component => 'MyRootV2', as => 'Controller::Root' ); |
| 23 |
} |
| 24 |
else { |
| 25 |
CatalystX::InjectComponent->inject( into => $class, component => 'MyRootV1', as => 'Root' ); # Controller:: will be automatically prefixed |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
DESCRIPTION |
| 30 |
CatalystX::InjectComponent will inject Controller, Model, and View |
| 31 |
components into your Catalyst application at setup (run)time. It does |
| 32 |
this by creating a new package on-the-fly, having that package extend |
| 33 |
the given component, and then having Catalyst setup the new component |
| 34 |
(via "->setup_component") |
| 35 |
|
| 36 |
So, how do I use this thing? |
| 37 |
You should inject your components when appropriate, typically after |
| 38 |
"setup_compenents" runs |
| 39 |
|
| 40 |
If you're using the Moose version of Catalyst, then you can use the |
| 41 |
following technique: |
| 42 |
|
| 43 |
use Moose; |
| 44 |
BEGIN { extends qw/Catalyst/ } |
| 45 |
|
| 46 |
after 'setup_components' => sub { |
| 47 |
my $class = shift; |
| 48 |
|
| 49 |
CatalystX::InjectComponent->inject( into => $class, ... ) |
| 50 |
}; |
| 51 |
|
| 52 |
METHODS |
| 53 |
CatalystX::InjectComponent->inject( ... ) |
| 54 |
into The Catalyst package to inject into (e.g. My::App) |
| 55 |
component The component package to inject |
| 56 |
as An optional moniker to use as the package name for the derived component |
| 57 |
|
| 58 |
For example: |
| 59 |
|
| 60 |
->inject( into => My::App, component => Other::App::Controller::Apple ) |
| 61 |
|
| 62 |
The above will create 'My::App::Controller::Other::App::Controller::Apple' |
| 63 |
|
| 64 |
->inject( into => My::App, component => Other::App::Controller::Apple, as => Apple ) |
| 65 |
|
| 66 |
The above will create 'My::App::Controller::Apple' |
| 67 |
|
| 68 |
ACKNOWLEDGEMENTS |
| 69 |
Inspired by Catalyst::Plugin::AutoCRUD |
| 70 |
|
| 71 |
AUTHOR |
| 72 |
Robert Krimen <[email protected]> |
| 73 |
|
| 74 |
COPYRIGHT AND LICENSE |
| 75 |
This software is copyright (c) 2012 by Robert Krimen. |
| 76 |
|
| 77 |
This is free software; you can redistribute it and/or modify it under |
| 78 |
the same terms as the Perl 5 programming language system itself. |
| 79 |
|