From: André Walker Date: Sat, 20 Aug 2011 23:25:50 +0000 (-0300) Subject: ditto X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9226f3048ef76856baf853b519fea82fbc1276db;hp=61915b481c0c5776f2be5f2e17adaed22a95548e;p=catagits%2FCatalyst-Runtime.git ditto --- diff --git a/lib/Catalyst/IOC.pm b/lib/Catalyst/IOC.pm index 7072aef..bf17609 100644 --- a/lib/Catalyst/IOC.pm +++ b/lib/Catalyst/IOC.pm @@ -10,12 +10,16 @@ use Sub::Exporter -setup => { depends_on component model + view + controller container /], groups => { default => [qw/ depends_on component model + view + controller container /]}, }; @@ -82,54 +86,70 @@ Catalyst::IOC - IOC for Catalyst, based on Bread::Board =head1 SYNOPSIS package MyApp::Container; + use Moose; use Catalyst::IOC; - - sub BUILD { - my $self = shift; - - container $self => as { - container model => as { - - # default component - component Foo => (); - - # model Bar needs model Foo to be built before - # and Bar's constructor gets Foo as a parameter - component Bar => ( dependencies => [ - depends_on('/model/Foo'), - ]); - - # Baz is rebuilt once per HTTP request - component Baz => ( lifecycle => 'Request' ); - - # built only once per application life time - component Quux => ( lifecycle => 'Singleton' ); - - # built once per app life time and uses an external model, - # outside the default directory - # no need for wrappers or Catalyst::Model::Adaptor - component Fnar => ( - lifecycle => 'Singleton', - class => 'My::External::Class', - ); - }; - } + extends 'Catalyst::IOC::Container'; + + container { + model { + # default component + component Foo => (); + + # model Bar needs model Foo to be built before + # and Bar's constructor gets Foo as a parameter + component Bar => ( dependencies => [ + depends_on('/model/Foo'), + ]); + + # Baz is rebuilt once per HTTP request + component Baz => ( lifecycle => 'Request' ); + + # built only once per application life time + component Quux => ( lifecycle => 'Singleton' ); + + # built once per app life time and uses an external model, + # outside the default directory + # no need for wrappers or Catalyst::Model::Adaptor + component Fnar => ( + lifecycle => 'Singleton', + class => 'My::External::Class', + ); + }; + view { + component HTML => (); + }; + controller { + component Root => (); + }; } =head1 DESCRIPTION +Catalyst::IOC provides "sugar" methods to extend the behavior of the default +Catalyst container. + =head1 METHODS =head2 container +Sets up the root container to be customised. + =head2 model +Sets up the model container to be customised. + =head2 view +Sets up the view container to be customised. + =head2 controller +Sets up the controller container to be customised. + =head2 component +Adds a component to the subcontainer. Works like L. + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm