CatalystX::InjectComponent(3pm)

CatalystX::InjectComponent3pm

Inject components into your catalyst application

Usage

    package My::App;
    use Catalyst::Runtime '5.80';
    use Moose;
    BEGIN { extends qw/Catalyst/ }
    ...
    after 'setup_components' => sub {
        my $class = shift;
        CatalystX::InjectComponent->inject( into => $class, component => 'MyModel' );
        if ( $class->config->{ ... ) {
            CatalystX::InjectComponent->inject( into => $class, component => 'MyRootV2', as => 'Controller::Root' );
        }
        else {
            CatalystX::InjectComponent->inject( into => $class, component => 'MyRootV1', as => 'Root' ); # Controller:: will be automatically prefixed
        }
    };

Version

version 0.025

Overview

CatalystX::InjectComponent will inject Controller, Model, and View components into your Catalyst application at setup (run)time. It does this by creating a new package on-the-fly, having that package extend the given component, and then having Catalyst setup the new component (via "->setup_component")

So, how do I use this thing?

You should inject your components when appropriate, typically after "setup_compenents" runs

If you're using the Moose version of Catalyst, then you can use the following technique:

    use Moose;
    BEGIN { extends qw/Catalyst/ }
    after 'setup_components' => sub {
        my $class = shift;
        CatalystX::InjectComponent->inject( into => $class, ... )
    };

Methods

CatalystX::InjectComponent->inject( ... )

    into        The Catalyst package to inject into (e.g. My::App)
    component   The component package to inject
    as          An optional moniker to use as the package name for the derived component

For example:

    ->inject( into => My::App, component => Other::App::Controller::Apple )
        
        The above will create 'My::App::Controller::Other::App::Controller::Apple'
    ->inject( into => My::App, component => Other::App::Controller::Apple, as => Apple )
        The above will create 'My::App::Controller::Apple'

Acknowledgements

Inspired by Catalyst::Plugin::AutoCRUD

Releases

7 releases since Debian 7 (Wheezy); the text changed 3 times.

  1. 7
  2. 8–10
  3. 11
  4. 12–13

Author

Robert Krimen <[email protected]>

From libcatalystx-injectcomponent-perl 0.025-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.