| 1 | package Catalyst::Plugin::SimpleCAS; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | our $VERSION = '1.002'; | ||
| 6 | |||
| 7 | use Moose::Role; | ||
| 8 | use namespace::autoclean; | ||
| 9 | |||
| 10 | use CatalystX::InjectComponent; | ||
| 11 | use Catalyst::Controller::SimpleCAS; | ||
| 12 | |||
| 13 | after 'setup_components' => sub { (shift)->inject_simplecas_controller(@_) }; | ||
| 14 | |||
| 15 | sub _simplecas_controller_namespace { | ||
| 16 | my $c = shift; | ||
| 17 | my $cfg = $c->config->{'Plugin::SimpleCAS'} || {}; | ||
| 18 | $cfg->{controller_namespace} || 'SimpleCAS' | ||
| 19 | } | ||
| 20 | |||
| 21 | sub inject_simplecas_controller { | ||
| 22 | my $c = shift; | ||
| 23 | |||
| 24 | # Now inject the new Controllers: | ||
| 25 | CatalystX::InjectComponent->inject( | ||
| 26 | into => $c, | ||
| 27 | component => 'Catalyst::Controller::SimpleCAS', | ||
| 28 | as => join('::','Controller',$c->_simplecas_controller_namespace) | ||
| 29 | ); | ||
| 30 | } | ||
| 31 | |||
| 32 | # Convenience method to be able to get the controller via $c->CAS | ||
| 33 | sub CAS { | ||
| 34 | my $c = shift; | ||
| 35 | $c->controller( $c->_simplecas_controller_namespace ) | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | __END__ |