my $name = $p->name;
my $pre_immutable_hook = $p->pre_immutable_hook;
method $name => sub {
- my ($app, $name, $config) = @_;
+ my ($app, $name, $config, $methods) = @_;
my $appclass = blessed($app) || $app;
my $type = $name;
my $meta = Moose->init_meta( for_class => $name );
$meta->superclasses('Catalyst::' . $type);
+
if ($p->has_custom_component_method) {
$meta->add_method(COMPONENT => $p->COMPONENT);
}
+
$app->$pre_immutable_hook($meta) if $p->has_pre_immutable_hook;
+
+ $methods ||= {};
+ foreach my $name (keys %$methods) {
+ $meta->add_method($name => $methods->{$name});
+ }
$meta->make_immutable;
my $instance = $app->setup_component($name);
my $suffix = $model_name;
$suffix =~ s/^.*::Model:://;
- my $controller = $app->_setup_dynamic_controller( $controller_name, {} );
- my $meta = $controller->meta;
- $meta->make_mutable; # Dirty, I should build the class, add the methods, then
- # last of all make it a component. The only reason it works
- # like this is that I wrote the simple thing for the model
- # code, abstracted _just_ enough to make it fly with this
- # dirty hack, then stopped. EVERY TIME YOU DO THIS KITTENS DIE
- my $methods = $model->meta->get_method_map;
- foreach my $method_name (keys %$methods) {
- $controller->meta->add_method(
+ my %controller_methods;
+ my $model_methods = $model->meta->get_method_map;
+ delete $model_methods->{new}; # FIXME..
+ delete $model_methods->{meta};
+ foreach my $method_name (keys %$model_methods) {
# Note need to pass model name, as the method actually comes from
# the underlying model class, not the Catalyst shim class we autogenerated.
- $method_name => $app->generate_reflected_controller_action_method($suffix, $methods->{$method_name})
- );
+ $controller_methods{$method_name} = $app->generate_reflected_controller_action_method($suffix, $model_methods->{$method_name})
}
- $meta->make_immutable;
+
+ $app->_setup_dynamic_controller( $controller_name, {}, \%controller_methods );
}
sub _setup_dynamic_controller_meta {