1 package CatalystX::DynamicComponent::ModelsFromConfig;
3 use namespace::autoclean;
11 # Note method reaming - allows user to modify my setup_dynamic_component without being
12 # forced to do it globally.
13 with 'CatalystX::DynamicComponent' => {
14 name => '_setup_dynamic_model',
17 my ($component_class_name, $app, $args) = @_;
19 my $class = $args->{class};
20 Class::MOP::load_class($class);
27 after 'setup_components' => sub { shift->_setup_dynamic_models(@_); };
29 sub _setup_dynamic_models {
32 my $model_prefix = 'Model::';
34 my $config = $app->config || {};
35 my $myconfig = $config->{'CatalystX::DynamicComponent::ModelsFromConfig'} || {};
37 foreach my $model_name ( grep { /^$model_prefix/ } keys %$config ) {
38 if (my $inc = $myconfig->{include}) {
39 next unless $model_name =~ /$inc/;
41 if (my $exc = $myconfig->{exclude}) {
42 next if $model_name =~ /$exc/;
45 $app->_setup_dynamic_model( $model_name, $config->{$model_name} );
55 CatalystX::DynamicComponent::ModelsFromConfig - Generate simple L<Catalyst::Model::Adaptor> like models purely from application config.
61 use namespace::autoclean;
63 +CatalystX::DynamicComponent::ModelsFromConfig
67 'CatalystX::DynamicComponent::ModelsFromConfig' => {
68 include => '(One|Two|Three)^',
72 class => 'SomeClass', # Name of class to load and construct
73 other => 'config', # Constructor passed other parameters
76 class => 'SomeOtherClass',
80 'Model::TwentyThree' => { # Ignored, as excluded
91 L<Catalyst>, L<MooseX::MethodAttributes>, L<CatalystX::DynamicComponent>.
95 Probably plenty, test suite certainly isn't comprehensive.. Patches welcome.
99 Tomas Doran (t0m) <bobtfish@bobtfish.net>
103 This code is copyright (c) 2009 Tomas Doran. This code is licensed on the same terms as perl