package CatalystX::DynamicComponent::ModelToControllerReflector;
use Moose::Role;
use Moose::Util qw/does_role/;
-use List::MoreUtils qw/uniq/;
-use Moose::Autobox;
+use MooseX::Types::Moose qw/Str/;
+use Moose::Util::TypeConstraints;
use namespace::autoclean;
my $mangle_attributes_on_generated_methods = sub {
}
}
+my $interface = 'CatalystX::DynamicComponent::ModelToControllerReflector::Strategy';
+role_type $interface;
+
sub _reflect_model_to_controller {
my ( $app, $model_name, $model ) = @_;
my %controller_methods;
# FIXME - Abstract this strategy crap out.
+
+ my $strategy = $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'}{'reflection_strategy'} || 'InterfaceRoles';
+ $strategy = "CatalystX::DynamicComponent::ModelToControllerReflector::Strategy::$strategy";
+ Class::MOP::load_class($strategy);
+ $strategy->new;
+
my $model_methods = $model->meta->get_method_map;
- my $interface_roles = [ uniq( map { exists $_->{interface_roles} ? $_->{interface_roles}->flatten : () } $app->config->{$model_name}, $app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'} ) ];
-
- for my $interface_role (@$interface_roles) {
- for my $required_method ($interface_role->meta->get_required_method_list) {
- # Note need to pass model name, as the method actually comes from
- # the underlying model class, not the Catalyst shim class we autogenerated.
- $controller_methods{$required_method} =
- $app->generate_reflected_controller_action_method($suffix, $model_methods->{$required_method})
- }
+ foreach my $method_name ( $strategy->get_reflected_method_list($app, $model->meta) ) {
+ # Note need to pass model name, as the method actually comes from
+ # the underlying model class, not the Catalyst shim class we autogenerated.
+ $controller_methods{$method_name} =
+ $app->generate_reflected_controller_action_method($suffix, $model_methods->{$method_name})
}
# Shallow copy so we don't stuff method refs in config