use constant PRIV => '__getmodelshelperpriv';
-my %registered_handlers = ( callback => [], get_models => [] );
+my $registered_handlers = {};
sub register_get_models_handlers {
my ($class, %additional_handlers) = @_;
$class->run_before(sub { $_[0]->{PRIV()} = { current_action => $_[1] }; }, %hook_params);
- map { push @{ $registered_handlers{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %registered_handlers;
+ my $handlers = _registered_handlers($class);
+ map { push @{ $handlers->{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %$handlers;
}
sub get_models_url_params {
);
};
- push @{ $registered_handlers{callback} }, $callback;
+ push @{ _registered_handlers($class)->{callback} }, $callback;
}
sub get_callback {
sub _run_handlers {
my ($self, $handler_type, %params) = @_;
- foreach my $sub (@{ $registered_handlers{$handler_type} }) {
+ foreach my $sub (@{ _registered_handlers(ref $self)->{$handler_type} }) {
if (ref $sub eq 'CODE') {
%params = $sub->($self, %params);
} elsif ($self->can($sub)) {
return %params;
}
+sub _registered_handlers {
+ $registered_handlers->{$_[0]} //= { callback => [], get_models => [] }
+}
+
1;
__END__