use Exporter qw(import);
our @EXPORT = qw(get_callback get_models);
-my $current_action;
+use constant PRIV => '__getmodelshelperpriv';
+
my %registered_handlers = ( callback => [], get_models => [] );
sub register_get_models_handlers {
$only = [ $only ] if !ref $only;
my %hook_params = @{ $only } ? ( only => $only ) : ();
- $class->run_before(sub { $current_action = $_[1]; }, %hook_params);
+ $class->run_before(sub { $_[0]->{PRIV()} = { current_action => $_[1] }; }, %hook_params);
map { push @{ $registered_handlers{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %registered_handlers;
}
sub get_callback {
my ($self, %override_params) = @_;
- my %default_params = _run_handlers($self, 'callback', action => $current_action);
+ my %default_params = _run_handlers($self, 'callback', action => ($self->{PRIV()} || {})->{current_action});
return $self->url_for(%default_params, %override_params);
}
use Exporter qw(import);
our @EXPORT = qw(make_paginated get_paginate_spec get_current_paginate_params _save_current_paginate_params _get_models_handler_for_paginated _callback_handler_for_paginated);
-my ($controller_paginate_spec, $current_page, $current_per_page);
+use constant PRIV => '__paginatedhelper_priv';
+
+my $controller_paginate_spec;
sub make_paginated {
my ($class, %specs) = @_;
my $spec = $self->get_paginate_spec;
- $params{page} = $current_page unless defined $params{page};
- $params{per_page} = $current_per_page unless defined $params{per_page};
+ my $priv = $self->{PRIV()} || {};
+ $params{page} = $priv->{page} unless defined $params{page};
+ $params{per_page} = $priv->{per_page} unless defined $params{per_page};
my %paginate_params = (
page => ($params{page} * 1) || 1,
my ($self) = @_;
my $paginate_spec = $self->get_paginate_spec;
- $current_page = $::form->{ $paginate_spec->{FORM_PARAMS}->[0] } || 1;
- $current_per_page = $::form->{ $paginate_spec->{FORM_PARAMS}->[1] } * 1;
+ $self->{PRIV()} = {
+ page => $::form->{ $paginate_spec->{FORM_PARAMS}->[0] } || 1,
+ per_page => $::form->{ $paginate_spec->{FORM_PARAMS}->[1] } * 1,
+ };
- # $::lxdebug->message(0, "saving current paginate params to $current_page / $current_per_page");
+ # $::lxdebug->message(0, "saving current paginate params to " . $self->{PRIV()}->{page} . ' / ' . $self->{PRIV()}->{per_page});
}
sub _callback_handler_for_paginated {
my ($self, %params) = @_;
+ my $priv = $self->{PRIV()} || {};
- if ($current_page) {
+ if ($priv->{page}) {
my $paginate_spec = $self->get_paginate_spec;
- $params{ $paginate_spec->{FORM_PARAMS}->[0] } = $current_page;
- $params{ $paginate_spec->{FORM_PARAMS}->[1] } = $current_per_page if $current_per_page;
+ $params{ $paginate_spec->{FORM_PARAMS}->[0] } = $priv->{page};
+ $params{ $paginate_spec->{FORM_PARAMS}->[1] } = $priv->{per_page} if $priv->{per_page};
}
# $::lxdebug->dump(0, "CB handler for paginated; params nach modif:", \%params);
use Exporter qw(import);
our @EXPORT = qw(make_sorted get_sort_spec get_current_sort_params _save_current_sort_params _get_models_handler_for_sorted _callback_handler_for_sorted);
-my ($controller_sort_spec, $current_sort_by, $current_sort_dir);
+use constant PRIV => '__sortedhelperpriv';
+
+my $controller_sort_spec;
sub make_sorted {
my ($class, %specs) = @_;
my $sort_spec = $self->get_sort_spec;
if (!$params{sort_by}) {
- $params{sort_by} = $current_sort_by;
- $params{sort_dir} = $current_sort_dir;
+ my $priv = $self->{PRIV()} || {};
+ $params{sort_by} = $priv->{by};
+ $params{sort_dir} = $priv->{dir};
}
my $by = $params{sort_by} || $sort_spec->{DEFAULT_BY};
#
sub _save_current_sort_params {
- my ($self) = @_;
+ my ($self) = @_;
- my $sort_spec = $self->get_sort_spec;
- $current_sort_by = $::form->{ $sort_spec->{FORM_PARAMS}->[0] };
- $current_sort_dir = !!$::form->{ $sort_spec->{FORM_PARAMS}->[1] } * 1;
+ my $sort_spec = $self->get_sort_spec;
+ $self->{PRIV()} = {
+ by => $::form->{ $sort_spec->{FORM_PARAMS}->[0] },
+ dir => !!$::form->{ $sort_spec->{FORM_PARAMS}->[1] } * 1,
+ };
- # $::lxdebug->message(0, "saving current sort params to $current_sort_by / $current_sort_dir");
+ # $::lxdebug->message(0, "saving current sort params to " . $self->{PRIV()}->{by} . ' / ' . $self->{PRIV()}->{dir});
}
sub _callback_handler_for_sorted {
my ($self, %params) = @_;
- if ($current_sort_by) {
+ my $priv = $self->{PRIV()} || {};
+ if ($priv->{by}) {
my $sort_spec = $self->get_sort_spec;
- $params{ $sort_spec->{FORM_PARAMS}->[0] } = $current_sort_by;
- $params{ $sort_spec->{FORM_PARAMS}->[1] } = $current_sort_dir;
+ $params{ $sort_spec->{FORM_PARAMS}->[0] } = $priv->{by};
+ $params{ $sort_spec->{FORM_PARAMS}->[1] } = $priv->{dir};
}
# $::lxdebug->dump(0, "CB handler for sorted; params nach modif:", \%params);