$config ||= {};
my $appclass = blessed($app) || $app;
+
my $type = $name;
- $type =~ s/^${appclass}:://; # FIXME - I think there is shit in C::Utils to do this.
$type =~ s/::.*$//;
+ $name = $appclass . '::' . $name;
my $meta = Moose->init_meta( for_class => $name );
my @superclasses = @{ $get_resolved_config->('superclasses', $p, $config) };
push(@superclasses, 'Catalyst::' . $type) unless @superclasses;
$meta->superclasses(@superclasses);
-
+
my $methods = $get_resolved_config->('methods', $p, $config);
foreach my $name (keys %$methods) {
$meta->add_method($name => $methods->{$name});
if (my @roles = @{ $get_resolved_config->('roles', $p, $config) }) {
Moose::Util::apply_all_roles( $name, @roles);
}
-
+
if ($p->has_pre_immutable_hook) {
if (!ref($pre_immutable_hook)) {
$app->$pre_immutable_hook($meta, $config);
my $class = blessed($app) || $app;
my $controller_name = $model_name;
- $controller_name =~ s/::Model::/::Controller::/;
+ $controller_name =~ s/^.*::Model::/Controller::/;
my $suffix = $model_name;
$suffix =~ s/^.*::Model:://;
$controller_methods{$method_name} = $app->generate_reflected_controller_action_method($suffix, $model_methods->{$method_name})
}
- my $config_name = $controller_name;
- $config_name =~ s/^[^:]+:://;
-
# Shallow copy so we don't stuff method refs in config
- my $config = { %{$app->config->{$config_name}||{}} };
-
+ my $config = { %{$app->config->{$controller_name}||{}} };
+
$config->{methods} = \%controller_methods;
$app->_setup_dynamic_controller( $controller_name, $config );
}
my $app_meta = generate_testapp({ name => 'dynamic_component_method' });
my $app = $app_meta->name;
ok $app->can('dynamic_component_method'), 'dynamic component method added';
- $app->dynamic_component_method( $app . "::Model::Foo", {} );
+ $app->dynamic_component_method( "Model::Foo", {} );
my $foo = $app->model('Foo');
ok $foo, 'Have added Foo component';
isa_ok($foo, 'Catalyst::Component');
});
my $app = $app_meta->name;
ok $app->can('dynamic_component_method'), 'dynamic component method added';
- $app->dynamic_component_method( $app . "::Model::Foo", {} );
+ $app->dynamic_component_method( "Model::Foo", {} );
my $foo = $app->model('Foo');
ok $foo, 'Have added Foo component';
isa_ok($foo, 'TestClass', 'COMPONENT method returned totally different class');
%generator_config,
});
my $app = $app_meta->name;
- $app->dynamic_component_method( $app . "::Model::Foo", $extra_config );
+ $app->dynamic_component_method( "Model::Foo", $extra_config );
my $model = $app->model('Foo');
isa_ok($model, 'My::Model', 'Correct superclass');
ok(!$model->isa('My::Other::Superclass'),
ok $model->can('_some_method_from_role'), 'Has had role applied';
ok !My::Model->can('_some_method_from_role'), 'Role applied at right place';
-
+
ok $model->can('_some_method_from_other_role'),
'Role application merges by default';
methods_resolve_strategy => 'replace',
});
my $app = $app_meta->name;
- $app->dynamic_component_method( $app . "::Model::Foo", $extra_config );
+ $app->dynamic_component_method( "Model::Foo", $extra_config );
my $model = $app->model('Foo');
isa_ok($model, 'My::Model', 'Correct superclass');
isa_ok($model, 'My::Other::Superclass',
ok $model->can('_some_method_from_role'), 'Has had role applied';
ok !My::Model->can('_some_method_from_role'), 'Role applied at right place';
-
+
ok !$model->can('_some_method_from_other_role'),
'Role application replaces when configured';
});
my $app = $app_meta->name;
- $app->dynamic_component_method( $app . "::Model::Foo", {} );
+ $app->dynamic_component_method( "Model::Foo", {} );
my $model = $app->model('Foo');
ok $model->can('my_other_injected_method'),
});
my $app = $app_meta->name;
- $app->dynamic_component_method( $app . "::Model::Foo", { superclasses => [], roles => [], methods => {} } );
+ $app->dynamic_component_method( "Model::Foo", { superclasses => [], roles => [], methods => {} } );
my $model = $app->model('Foo');
ok !$model->can('my_other_injected_method'),