Cataly...ponent(3pm)

πŸ“¦
version 0.025 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble

πŸ’– Cataly...ponent(3pm) β€” CatalystX::InjectComponent πŸ’–

okay bestie, welcome to a page from User Contributed Perl Documentation ✨ the title got squished to Cataly...ponent(3pm) by the terminal, but it's really CatalystX::InjectComponent and it's here to help πŸ’…


🌸 NAME 🌸

CatalystX::InjectComponent β€” inject components into your Catalyst application 🫢


⭐ VERSION ⭐

version 0.025 β€” yes, the number is literally that, don't @ me πŸ’–


✨ SYNOPSIS ✨

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

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does this thing even do? CatalystX::InjectComponent will inject Controller, Model, and View components into your Catalyst application at setup (run)time. the way it pulls this off is iconic honestly: it creates a brand-new package on-the-fly, makes that package extend the component you gave it, and then lets Catalyst set up the new component (via ->setup_component) πŸ‘‘

πŸŽ€ So, how do I use this thing? πŸŽ€

you should inject your components when it's appropriate, typically after setup_compenents runs 🫑

if you're running the Moose version of Catalyst, then this technique right here is the move:

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, bestie, watch this:

->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 β€” the blueprint, the blueprint πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

Robert Krimen <robertkrimen@gmail.com> β€” the mastermind, periodt ✨


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. 🫢


ok that's the whole page, no skips, no shortcuts πŸ’―

and a lil sign-off for the record: this was rendered by perl v5.34.0 and dated 2022-06-09 β€” iconic, timeless, we love her πŸŽ€πŸ’œβœ¨

πŸ“¦ where this page comes from