NAME

Catalyst::Component::DelayedInstance - Moose Role for components which setup

SYNOPSIS

package MyApp::Model::Foo;

use Moose;
extends 'Catalyst::Model';
with 'Catalyst::Component::DelayedInstance';

sub build_per_application_instance {
  my ($class, $app, $config) = @_;

  $config->{bar} = $app->model("Baz");
  return $class->new($config);
}    

DESCRIPTION

Sometimes you want an application scoped component that nevertheless needs other application components as part of its setup. In the past this was not reliable since Application scoped components are setup in linear order. You could not call $app->model in a COMPONENT method and expect 'Foo' to be there. This role defers creating the application scoped instance until after your application is fully setup. This means you can now assume your other application scoped components (components that do COMPONENT but not ACCEPT_CONTEXT) are available as dependencies.

Please note this means that your instance is not created until the first time its called in a request. As a result any errors with configuration will not show up until later in runtime. So there is a larger burden on your testing to make sure your application startup and runtime is accurate. Also note that even though your instance creation is deferred to request time, the request context is NOT given, but the application is (this means that you cannot depend on components that do ACCEPT_CONTEXT, since you don't have one...).

ATTRIBUTES

METHODS

ACCEPT_CONTEXT

AUTOLOAD

SEE ALSO

Catalyst::Component,

AUTHORS

See Catalyst.

COPYRIGHT

See Catalyst.