The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CatalystX::Controller::Sugar::Plugin - Prepare a plugin, not a real controller

DESCRIPTION

This module prepare actions to be plugged in "somewhere" in another controller. This is done, by using the "inject()" method.

SYNOPSIS

 #= first... ==============================
 package My::Plugin;
 use CatalystX::Controller::Sugar::Plugin;
 # Same as L<CatalystX::Controller::Sugar>.
 1;

 #= then... ===============================
 package MyApp::Controller::Foo;
 My::Plugin->inject;
 1;

 #= or... =================================
 package MyApp;
 My::Plugin->inject("MyApp::Controller::Foo");
 1;

See "EXTENDED SYNOPSIS" for how to include attributes.

EXPORTED FUNCTIONS

chain

Same as CatalystX::Controller::Sugar::chain(), but will only prepare the action to be injected in some other controller.

private

Same as CatalystX::Controller::Sugar::private(), but will only prepare the action to be injected in some other controller.

METHODS

inject

 $controller_obj = $class->inject;
 $controller_obj = $class->inject($target);

Will inject the prepared actions into $target namespace or caller's namespace by default. This will also inject attributes from the plugin package, but will not override any existing attributes with the same name.

Also the $target controller will be spawned, unless it already exists in the component list.

init_meta

See Moose::Exporter.

EXTENDED SYNOPSIS

 package My::Plugin;
 use Moose; # IMPORT "has"
 use CatalystX::Controller::Sugar::Plugin;

 has foo => (
    is => 'rw',
    isa => 'Str',
    lazy => 1, # <-- IMPORTANT
    default => 'foo value'
 );

 chain '' => sub {
 };

 #...

 1;

Attributes with default values has to be lazy. (Not quite sure why though...) All attributes defined in a plugin package, will also be injected into the caller controller. They are cloned and not shared among the controller, if it is injected into multiple controllers.

BUGS

Please report any bugs or feature requests to bug-catalystx-controller-sugar at rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Copyright 2007 Jan Henning Thorsen, all rights reserved.

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

AUTHOR

Jan Henning Thorsen, <jhthorsen at cpan.org>