GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
CatalystX::InjectComponent(3) User Contributed Perl Documentation CatalystX::InjectComponent(3)

CatalystX::InjectComponent - Inject components into your Catalyst application

version 0.025

    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
        }
    };

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")

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, ... )
    };

    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'

Inspired by Catalyst::Plugin::AutoCRUD

Robert Krimen <robertkrimen@gmail.com>

This software is copyright (c) 2012 by Robert Krimen.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2012-07-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.