From: t0m Date: Sun, 7 Jun 2009 22:02:40 +0000 (+0100) Subject: Do not munge config X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84d8e4e1c7c3b67669a0ac8dac75b5a2f927dfeb;hp=f38d3061acf7d7abf266fecf958b9a138b7e7224;p=catagits%2FCatalystX-DynamicComponent.git Do not munge config --- diff --git a/lib/CatalystX/DynamicComponent/ModelToControllerReflector.pm b/lib/CatalystX/DynamicComponent/ModelToControllerReflector.pm index 4fade17..01883b5 100644 --- a/lib/CatalystX/DynamicComponent/ModelToControllerReflector.pm +++ b/lib/CatalystX/DynamicComponent/ModelToControllerReflector.pm @@ -51,7 +51,9 @@ sub _reflect_model_to_controller { my %controller_methods; # FIXME - Abstract this strategy crap out. - my $strategy = $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'}{'reflection_strategy'} || 'InterfaceRoles'; + my $config = exists $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'} + ? $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'} : {}; + my $strategy = exists $config->{reflection_strategy} ? $config->{reflection_strategy} : 'InterfaceRoles'; $strategy = "CatalystX::DynamicComponent::ModelToControllerReflector::Strategy::$strategy"; Class::MOP::load_class($strategy); $strategy->new; @@ -65,10 +67,10 @@ sub _reflect_model_to_controller { } # Shallow copy so we don't stuff method refs in config - my $config = { %{$app->config->{$controller_name}||{}} }; + my $controller_config = { %{$app->config->{$controller_name}||{}} }; - $config->{methods} = \%controller_methods; - $app->_setup_dynamic_controller( $controller_name, $config ); + $controller_config->{methods} = \%controller_methods; + $app->_setup_dynamic_controller( $controller_name, $controller_config ); } sub generate_reflected_controller_action_method { diff --git a/lib/CatalystX/DynamicComponent/ModelToControllerReflector/Strategy/InterfaceRoles.pm b/lib/CatalystX/DynamicComponent/ModelToControllerReflector/Strategy/InterfaceRoles.pm index 5beb1ae..ff1965f 100644 --- a/lib/CatalystX/DynamicComponent/ModelToControllerReflector/Strategy/InterfaceRoles.pm +++ b/lib/CatalystX/DynamicComponent/ModelToControllerReflector/Strategy/InterfaceRoles.pm @@ -10,7 +10,10 @@ with 'CatalystX::DynamicComponent::ModelToControllerReflector::Strategy'; sub get_reflected_method_list {; my ($self, $app, $model_meta) = @_; my $model_name = $model_meta->name; - my $interface_roles = [ uniq( map { exists $_->{interface_roles} ? $_->{interface_roles}->flatten : () } $app->config->{$model_name}, $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'} ) ]; + my $model_config = exists $app->config->{$model_name} ? $app->config->{$model_name} : {}; + my $my_config = exists $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'} + ? $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'} : {}; + my $interface_roles = [ uniq( map { (defined $_ && exists $_->{interface_roles}) ? $_->{interface_roles}->flatten : () } $model_config, $my_config ) ]; map { $_->meta->get_required_method_list } @$interface_roles; } diff --git a/t/06_dynamicmodel_interface.t b/t/06_dynamicmodel_interface.t index d67c0d8..6b0461e 100644 --- a/t/06_dynamicmodel_interface.t +++ b/t/06_dynamicmodel_interface.t @@ -3,19 +3,22 @@ use warnings; use FindBin qw/$Bin/; use lib "$Bin/lib"; +use Data::Dumper; use Test::More tests => 2; BEGIN { use_ok('ModelsFromConfigInterfaceApp'); } my $config = ModelsFromConfigInterfaceApp->config; -delete $config->{'CatalystX::DynamicComponent::ModelToControllerReflector'}; -is_deeply($config, { +my $expected = { name => 'ModelsFromConfigInterfaceApp', 'Model::One' => { class => 'SomeModelClass', interface_roles => [qw/ SomeModelClassInterface /], }, -}, 'Config is not munged'); +}; + +is_deeply($config, $expected, 'Config is not munged') + or warn Dumper([$config, $expected]);