[Catalyst-commits] r12721 - in
Catalyst-Runtime/5.80/branches/expand_modules: lib
lib/Catalyst t/aggregate t/lib/TestApp/Model
aCiD2 at dev.catalyst.perl.org
aCiD2 at dev.catalyst.perl.org
Sun Jan 24 17:33:27 GMT 2010
Author: aCiD2
Date: 2010-01-24 17:33:27 +0000 (Sun, 24 Jan 2010)
New Revision: 12721
Added:
Catalyst-Runtime/5.80/branches/expand_modules/t/aggregate/unit_core_component_generating.t
Catalyst-Runtime/5.80/branches/expand_modules/t/lib/TestApp/Model/Generating.pm
Modified:
Catalyst-Runtime/5.80/branches/expand_modules/lib/Catalyst.pm
Catalyst-Runtime/5.80/branches/expand_modules/lib/Catalyst/Component.pm
Log:
Allow models and components to specify the names of any components they generate
Modified: Catalyst-Runtime/5.80/branches/expand_modules/lib/Catalyst/Component.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/expand_modules/lib/Catalyst/Component.pm 2010-01-24 17:29:03 UTC (rev 12720)
+++ Catalyst-Runtime/5.80/branches/expand_modules/lib/Catalyst/Component.pm 2010-01-24 17:33:27 UTC (rev 12721)
@@ -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';
@@ -149,6 +150,11 @@
. " did not override Catalyst::Component::process" );
}
+sub expand_modules {
+ my ($class, $component) = @_;
+ return Devel::InnerPackage::list_packages( $component );
+}
+
__PACKAGE__->meta->make_immutable;
1;
@@ -207,6 +213,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/branches/expand_modules/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/expand_modules/lib/Catalyst.pm 2010-01-24 17:29:03 UTC (rev 12720)
+++ Catalyst-Runtime/5.80/branches/expand_modules/lib/Catalyst.pm 2010-01-24 17:33:27 UTC (rev 12721)
@@ -2224,8 +2224,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/branches/expand_modules/t/aggregate/unit_core_component_generating.t
===================================================================
--- Catalyst-Runtime/5.80/branches/expand_modules/t/aggregate/unit_core_component_generating.t (rev 0)
+++ Catalyst-Runtime/5.80/branches/expand_modules/t/aggregate/unit_core_component_generating.t 2010-01-24 17:33:27 UTC (rev 12721)
@@ -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/branches/expand_modules/t/lib/TestApp/Model/Generating.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/expand_modules/t/lib/TestApp/Model/Generating.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/expand_modules/t/lib/TestApp/Model/Generating.pm 2010-01-24 17:33:27 UTC (rev 12721)
@@ -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