use Moose::Role;
use namespace::clean -except => 'meta';
-with 'CatalystX::DynamicComponent';
+with 'CatalystX::DynamicComponent'
+ => { alias => { _setup_dynamic_component => '_setup_dynamic_controller' } };
requires 'setup_components';
my @model_names = grep { /::Model::/ } keys %{ $app->components };
foreach my $model_name (@model_names) {
- $app->_setup_dynamic_controller( $model_name, $app->components->{$model_name} );
+ $app->_reflect_model_to_controller( $model_name, $app->components->{$model_name} );
}
}
-sub _setup_dynamic_controller {
- my ($app, $model_name, $model_component) = @_;
- warn($model_name);
+sub _reflect_model_to_controller {
+ my ( $app, $model_name, $model ) = @_;
+
+ my $controller_name = $model_name;
+ $controller_name =~ s/::Model::/::Controller::/;
+
+ $app->_setup_dynamic_controller( $controller_name );
}
1;
setup_component
/;
+# Note method reaming - allows user to modify my setup_dynamic_component without being
+# forced to do it globally.
+with 'CatalystX::DynamicComponent'
+ => { alias => { _setup_dynamic_component => '_setup_dynamic_model' } };
+
after 'setup_components' => sub { shift->_setup_dynamic_models(@_); };
sub _setup_dynamic_models {
}
}
-sub _setup_dynamic_model {
- my ($app, $name, $config) = @_;
-
- my $meta = Moose->init_meta( for_class => $name );
- $meta->superclasses('Catalyst::Model');
-
- $meta->add_method(
-
- COMPONENT
- => sub {
- my ($model_class_name, $app, $args) = @_;
-
- my $class = delete $args->{class};
- Class::MOP::load_class($class);
-
- $class->new($args);
- });
-
- $meta->make_immutable;
-
- my $instance = $app->setup_component($name);
- $app->components->{ $name } = $instance;
-}
-
1;
extends 'Catalyst';
+# Ordering important. :)
with qw/
+ CatalystX::DynamicComponent
CatalystX::ModelsFromConfig
+ CatalystX::ModelToControllerReflector
/;
our $VERSION = '0.01';