+sub disable_plugin {
+ my ($self, $plugin) = @_;
+ die 'cannot change internal state after finalize was called' if $self->finalized;
+ die 'unsupported plugin' unless $self->can($plugin) && $self->$plugin && $self->$plugin->isa('SL::Controller::Helper::GetModels::Base');
+
+ $self->$plugin->disabled(1);
+}
+
+sub enable_plugin {
+ my ($self, $plugin) = @_;
+ die 'cannot change internal state after finalize was called' if $self->finalized;
+ die 'unsupported plugin' unless $self->can($plugin) && $self->$plugin && $self->$plugin->isa('SL::Controller::Helper::GetModels::Base');
+ $self->$plugin->disabled(0);
+}
+
+sub is_enabled_plugin {
+ my ($self, $plugin) = @_;
+ die 'unsupported plugin' unless $self->can($plugin) && $self->$plugin && $self->$plugin->isa('SL::Controller::Helper::GetModels::Base');
+ $self->$plugin->is_enabled;
+}
+
+# TODO: get better delegation
+sub set_report_generator_sort_options {
+ my ($self, %params) = @_;
+ $self->finalize;
+
+ $self->sorted->set_report_generator_sort_options(%params);
+}
+
+sub get_paginate_args {
+ my ($self) = @_;
+ my %params = $self->finalize;
+
+ $self->paginated->get_current_paginate_params(%params);
+}
+
+sub get_sort_spec {
+ my ($self) = @_;
+
+ $self->sorted->specs;
+}
+
+sub get_current_sort_params {
+ my ($self) = @_;
+
+ $self->sorted->read_params;
+}
+
+sub init {
+ my ($self, %params) = @_;
+
+ my $model = delete $params{model};
+ if (!$model && $params{controller} && ref $params{controller}) {
+ $model = ref $params{controller};
+ $model =~ s/.*:://;
+ die 'Need a valid model' unless $model;
+ }
+ $self->model($model);
+
+ my @plugins;
+ for my $plugin (qw(filtered sorted paginated)) {
+ next if exists($params{$plugin}) && !$params{$plugin};
+
+ my $spec = delete $params{$plugin} // {};
+ my $plugin_class = "SL::Controller::Helper::GetModels::" . ucfirst $plugin;
+ push @plugins, $self->$plugin($plugin_class->new(%$spec, get_models => $self));
+ }
+ $self->plugins(@plugins);
+
+ $self->SUPER::init(%params);
+
+ $_->read_params for $self->plugins;
+
+ weaken $self->controller if $self->controller;
+}
+
+sub finalize {
+ my ($self, %params) = @_;
+
+ return %{ $self->final_params } if $self->finalized;