summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Hook.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2017-04-01 16:45:25 +0200
committerDylan William Hardison <dylan@hardison.net>2017-04-10 17:40:13 +0200
commitecbdca8c3f06dd420db6a960c8808615dae6848a (patch)
tree14fc2b6ae0adbafa8df2e4982b22fe41f0b36d22 /Bugzilla/Hook.pm
parent7d6ee3486e6a76ed0c96341d184c20ae09de2019 (diff)
downloadbugzilla-ecbdca8c3f06dd420db6a960c8808615dae6848a.tar.gz
bugzilla-ecbdca8c3f06dd420db6a960c8808615dae6848a.tar.xz
Bug 1352913 - Extensions must register for template_before_process()
We can skip a lot of method calls if extensions must declare what templates they act on.
Diffstat (limited to 'Bugzilla/Hook.pm')
-rw-r--r--Bugzilla/Hook.pm44
1 files changed, 29 insertions, 15 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm
index 00bd316ab..e28c01a40 100644
--- a/Bugzilla/Hook.pm
+++ b/Bugzilla/Hook.pm
@@ -11,18 +11,42 @@ use 5.10.1;
use strict;
use warnings;
+use Scalar::Util qw(blessed);
+
sub process {
- my ($name, $args) = @_;
+ my ($name, $args, $extensions) = @_;
+
+ $extensions //= Bugzilla->extensions;
+
+ my $hook_stack = Bugzilla->request_cache->{hook_stack} ||= [];
+ push @$hook_stack, $name;
+
+ foreach my $extension (@$extensions) {
+ if (my $hook = $extension->can($name)) {
+ $hook->($extension, $args);
+ }
+ }
- _entering($name);
+ pop @$hook_stack;
+}
+
+sub collect_wants {
+ my ($name) = @_;
+ my %result;
foreach my $extension (@{ Bugzilla->extensions }) {
- if ($extension->can($name)) {
- $extension->$name($args);
+ my $hook = $extension->can($name);
+ if ($hook) {
+ my $wants = $hook->($extension);
+ foreach my $want (keys %$wants) {
+ if ($wants->{$want}) {
+ $result{ $want }{ blessed $extension } = 1;
+ }
+ }
}
}
- _leaving($name);
+ return \%result;
}
sub in {
@@ -31,16 +55,6 @@ sub in {
return $hook_name eq $currently_in ? 1 : 0;
}
-sub _entering {
- my ($hook_name) = @_;
- my $hook_stack = Bugzilla->request_cache->{hook_stack} ||= [];
- push(@$hook_stack, $hook_name);
-}
-
-sub _leaving {
- pop @{ Bugzilla->request_cache->{hook_stack} };
-}
-
1;
__END__