[Catalyst-commits] r12810 - in Catalyst-Runtime/5.80/trunk: lib lib/Catalyst t/aggregate t/lib/TestApp/Model

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Thu Feb 4 05:50:06 GMT 2010


Author: rafl
Date: 2010-02-04 05:50:05 +0000 (Thu, 04 Feb 2010)
New Revision: 12810

Added:
   Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_component_generating.t
   Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Model/Generating.pm
Modified:
   Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Component.pm
Log:
Merge branch 'expand_modules'

* expand_modules:
  Allow models and components to specify the names of any components they generate
  Branching to allow components to specify any modules they may have created

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Component.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Component.pm	2010-02-04 04:15:27 UTC (rev 12809)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Component.pm	2010-02-04 05:50:05 UTC (rev 12810)
@@ -5,6 +5,7 @@
 use Class::MOP::Object;
 use Catalyst::Utils;
 use Class::C3::Adopt::NEXT;
+use Devel::InnerPackage ();
 use MRO::Compat;
 use mro 'c3';
 use Scalar::Util 'blessed';
@@ -147,6 +148,11 @@
           . " did not override Catalyst::Component::process" );
 }
 
+sub expand_modules {
+    my ($class, $component) = @_;
+    return Devel::InnerPackage::list_packages( $component );
+}
+
 __PACKAGE__->meta->make_immutable;
 
 1;
@@ -205,6 +211,13 @@
 Merges two hashes together recursively, giving right-hand precedence.
 Alias for the method in L<Catalyst::Utils>.
 
+=head2 $c->expand_modules( $setup_component_config )
+
+Return a list of extra components that this component has created. By default,
+it just looks for a list of inner packages of this component
+
+=cut
+
 =head1 OPTIONAL METHODS
 
 =head2 ACCEPT_CONTEXT($c, @args)

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2010-02-04 04:15:27 UTC (rev 12809)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2010-02-04 05:50:05 UTC (rev 12810)
@@ -2239,8 +2239,11 @@
     }
 
     for my $component (@comps) {
-        $class->components->{ $component } = $class->setup_component($component);
-        for my $component ($class->expand_component_module( $component, $config )) {
+        my $instance = $class->components->{ $component } = $class->setup_component($component);
+        my @expanded_components = $instance->can('expand_modules')
+            ? $instance->expand_modules( $component, $config )
+            : $class->expand_component_module( $component, $config );
+        for my $component (@expanded_components) {
             next if $comps{$component};
             $class->_controller_init_base_classes($component); # Also cover inner packages
             $class->components->{ $component } = $class->setup_component($component);

Added: Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_component_generating.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_component_generating.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_component_generating.t	2010-02-04 05:50:05 UTC (rev 12810)
@@ -0,0 +1,10 @@
+use Test::More tests => 3;
+use strict;
+use warnings;
+
+use lib 't/lib';
+use TestApp;
+
+ok(TestApp->model('Generating'), 'knows about generating model');
+ok(TestApp->model('Generated'), 'knows about the generated model');
+is(TestApp->model('Generated')->foo, 'foo', 'can operate on generated model');

Added: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Model/Generating.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Model/Generating.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Model/Generating.pm	2010-02-04 05:50:05 UTC (rev 12810)
@@ -0,0 +1,22 @@
+package TestApp::Model::Generating;
+use Moose;
+extends 'Catalyst::Model';
+
+sub BUILD {
+    Class::MOP::Class->create(
+        'TestApp::Model::Generated' => (
+            methods => {
+                foo => sub { 'foo' }
+            }
+        )
+    );
+}
+
+sub expand_modules {
+    return ('TestApp::Model::Generated');
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;




More information about the Catalyst-commits mailing list