summaryrefslogtreecommitdiffstats
path: root/Bugzilla.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-08-20 16:59:29 +0200
committerGitHub <noreply@github.com>2018-08-20 16:59:29 +0200
commitfab4ef6a045e4fa2b31778d4dbf752448f2f0567 (patch)
tree0427d4e58a99867b941b6196208bc6dbe8f1ba39 /Bugzilla.pm
parent72f78546d35342dcf556322cd702bc32e9ed2811 (diff)
downloadbugzilla-fab4ef6a045e4fa2b31778d4dbf752448f2f0567.tar.gz
bugzilla-fab4ef6a045e4fa2b31778d4dbf752448f2f0567.tar.xz
Bug 1482145 - add a scope_guard option to set_user()
Diffstat (limited to 'Bugzilla.pm')
-rw-r--r--Bugzilla.pm17
1 files changed, 15 insertions, 2 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm
index f26819d93..4d5e559d9 100644
--- a/Bugzilla.pm
+++ b/Bugzilla.pm
@@ -46,6 +46,7 @@ use File::Basename;
use File::Spec::Functions;
use Safe;
use JSON::XS qw(decode_json);
+use Scope::Guard;
use parent qw(Bugzilla::CPAN);
@@ -275,8 +276,20 @@ sub user {
}
sub set_user {
- my (undef, $user) = @_;
- request_cache->{user} = $user;
+ my (undef, $new_user, %option) = @_;
+
+ if ($option{scope_guard}) {
+ my $old_user = request_cache->{user};
+ request_cache->{user} = $new_user;
+ return Scope::Guard->new(
+ sub {
+ request_cache->{user} = $old_user;
+ }
+ )
+ }
+ else {
+ request_cache->{user} = $new_user;
+ }
}
sub sudoer {