1 package CatalystX::DynamicComponent;
2 use MooseX::Role::Parameterized;
3 use namespace::autoclean;
5 our $VERSION = 0.000001;
12 parameter 'pre_immutable_hook' => (
14 predicate => 'has_pre_immutable_hook',
17 parameter 'COMPONENT' => (
19 predicate => 'has_custom_component_method',
25 my $pre_immutable_hook = $p->pre_immutable_hook;
27 my ($app, $name, $config, $methods) = @_;
29 my $appclass = blessed($app) || $app;
31 $type =~ s/^${appclass}:://; # FIXME - I think there is shit in C::Utils to do this.
34 my $meta = Moose->init_meta( for_class => $name );
35 $meta->superclasses('Catalyst::' . $type);
37 if ($p->has_custom_component_method) {
38 $meta->add_method(COMPONENT => $p->COMPONENT);
41 $app->$pre_immutable_hook($meta) if $p->has_pre_immutable_hook;
44 foreach my $name (keys %$methods) {
45 $meta->add_method($name => $methods->{$name});
47 $meta->make_immutable;
49 my $instance = $app->setup_component($name);
50 $app->components->{ $name } = $instance;