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::VirtualComponents(3) User Contributed Perl Documentation CatalystX::VirtualComponents(3)

CatalystX::VirtualComponents - Setup Virtual Catalyst Components Based On A Parent Application Class

    # in your base app...
    package MyApp;
    use Catalyst;

    # in another app...
    package MyApp::Extended;
    use Moose;
    use Catalyst qw(+CatalystX::VirtualComponents);
    
    extends 'MyApp';

WARNING: YMMV with this module.

This module provides a way to reuse controllers, models, and views from another Catalyst application.

Suppose you have a Catalyst application with the following components:

    # Application MyApp::Base
    MyApp::Base::Controller::Root
    MyApp::Base::Model::DBIC
    MyApp::Base::View::TT

And then in MyApp::Extended, you wanted to reuse these components -- except you want to customize the Root controller, and you want to add another model (say, Model::XML::Feed).

In your new app, you can skip creating MyApp::Extended::Model::DBIC and MyApp::Extended::View::TT -- CatalystX::VirtualComponents will take care of these.

Just provide the customized Root controller and the new model:

    package MyApp::Extended::Controller::Root;
    use Moose;

    BEGIN { extends 'MyApp::Base::Controller::Root' }

    sub new_action :Path('new_action') {
        ....
    }

(We will skip XML::Feed, as it's just a regular model)

Then, in MyApp::Extended

    packge MyApp::Extended;
    use Moose;
    use Catalyst;

    extends 'MyApp::Base';

Note that MyApp::Extended inherits from MyApp::Base. Naturally, if you are inheriting from an application, you'd probably want to inherit all of its controllers and such. To do this, specify CatalystX::VirtualComponents in the Catalyst plugin list for MyApp::Extended:

    __PACKAGE__->setup( qw(
        ... # your regular Catalyst plugins
        +CatalystX::VirtualComponent
    ) );

When setup() is run, CatalystX::VirtualComponent will intercept the component setup code and will automatically create virtual subclasses for components that exist in MyApp::Base, but not in MyApp::Extended. In the above case, MyApp::Extended::View::TT and MyApp::Extended::Model::DBIC will be created.

MyApp::Extended::Controller::Root takes precedence over the base class, so only the local component will be loaded. MyApp::Extended::Model::XML::Feed only exists in the MyApp::Extended namespace, so it just works like a normal Catalyst model.

If you don't want to subclass, or use a more fine-grained control on which namespaces to look for base components, specify the namespaces in a config element:

    __PACKAGE__->config(
        VirtualComponents => {
            inherit => [
                'NamespaceA',
                'NamespaceB'
            ]
        }
    );

Simply add CatalystX::VirtualComponents in the plugin list:

    package MyApp::Extended::Builder;
    use Moose;

    extends 'CatalystX::AppBuilder';

    override _build_plugins {
        my $plugins = super();
        push @$plugins, '+CatalystX::VirtualComponents';
        return $plugins;
    };

    1;

Finds the list of components for Catalyst app $class.

Overrides Catalyst's setup_components() method.

Documentation. Samples. Tests.

Daisuke Maki "<daisuke@endeworks.jp>"

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

See http://www.perl.com/perl/misc/Artistic.html

2009-10-14 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.