ditto
André Walker [Sat, 20 Aug 2011 23:25:50 +0000 (20:25 -0300)]
lib/Catalyst/IOC.pm

index 7072aef..bf17609 100644 (file)
@@ -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<Bread::Board::service>.
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm