| 1 | package CatalystX::ASP::Role; | ||
| 2 | |||
| 3 | 1 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | CatalystX::ASP::Role - Catalyst Role to plug-in the ASP View | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | package MyApp; | ||
| 12 | |||
| 13 | use Moose; | ||
| 14 | use Catalyst; | ||
| 15 | extends 'Catalyst'; | ||
| 16 | |||
| 17 | with 'CatalystX::ASP::Role'; | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | Compose this role in your main application class. This will inject the ASP View | ||
| 22 | as View component in your app called 'ASP', accessible via | ||
| 23 | C<< $c->view('ASP') >>. It will also add a C<DispatchType> which will direct all | ||
| 24 | requests with C<.asp> extension to the View. | ||
| 25 | |||
| 26 | =head1 METHODS | ||
| 27 | |||
| 28 | =over | ||
| 29 | |||
| 30 | =item before 'setup_components' | ||
| 31 | |||
| 32 | Inject C<CatalystX::ASP::View> component as a View for your app | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | # Inject our View | ||
| 37 | 1 | ▶ | before 'setup_components' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 38 | 1 | my $class = shift; | |
| 39 | |||
| 40 | 1 | $class->inject_components( | |
| 41 | 'View::ASP' => { | ||
| 42 | from_component => 'CatalystX::ASP::View', | ||
| 43 | } | ||
| 44 | ); | ||
| 45 | |||
| 46 | 1 | }; | |
| 47 | |||
| 48 | # Load ASP object and Global objects during setup | ||
| 49 | 1 | ▶ | after 'setup_components' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 50 | 1 | my $class = shift; | |
| 51 | |||
| 52 | my $asp = CatalystX::ASP->new( | ||
| 53 | 1 | %{ $class->config->{'CatalystX::ASP'} }, | |
| 54 | c => $class, | ||
| 55 | _setup_finished => 0, | ||
| 56 | ); | ||
| 57 | 1 | $class->view( 'ASP' )->asp( $asp ); | |
| 58 | 1 | }; | |
| 59 | |||
| 60 | # Keep own copy of setup_finished | ||
| 61 | 1 | ▶ | before 'setup_finalize' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 62 | 1 | my ( $class ) = @_; | |
| 63 | |||
| 64 | 1 | my $asp = $class->view( 'ASP' )->asp; | |
| 65 | 1 | $asp->cleanup; | |
| 66 | 1 | $asp->_setup_finished( 1 ); | |
| 67 | 1 | }; | |
| 68 | |||
| 69 | =item after 'setup_dispatcher' | ||
| 70 | |||
| 71 | Load C<CatalystX::ASP::Dispatcher> as a C<DispatchType> for your app | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | # Register our DispatchType | ||
| 76 | 1 | ▶ | after 'setup_dispatcher' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 77 | 1 | my $c = shift; | |
| 78 | |||
| 79 | # Add our dispatcher | ||
| 80 | 1 | push @{ $c->dispatcher->preload_dispatch_types }, '+CatalystX::ASP::Dispatcher'; | |
| 81 | 1 | }; | |
| 82 | |||
| 83 | 1 | ▶ | no Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 84 | |||
| 85 | 1 | 1; | |
| 86 | |||
| 87 | =back | ||
| 88 | |||
| 89 | =head1 SEE ALSO | ||
| 90 | |||
| 91 | =over | ||
| 92 | |||
| 93 | =item * L<CatalystX::ASP::View> | ||
| 94 | |||
| 95 | =item * L<CatalystX::ASP::Dispatcher> | ||
| 96 | |||
| 97 | =back | ||