Skip to content

Commit

Permalink
Fix error when $Data::Dumper::Terse is set
Browse files Browse the repository at this point in the history
  • Loading branch information
DrHyde committed Jan 17, 2024
1 parent de9c46d commit 2efc430
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
65535 2024--1-17

- Fix error when $Data::Dumper::Terse is set, see
https://github.com/DrHyde/perl-modules-Unix-Sudo/issues/19

4.567.89 2021-08-06

- recommend Taint::Runtime instead of the 'tainting' module, which
Expand Down
5 changes: 3 additions & 2 deletions lib/Unix/Sudo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Unix::Sudo;
use strict;
use warnings;

our $VERSION = '4.567.89';
our $VERSION = '65535';

require Exporter;
our @ISA = qw(Exporter);
Expand Down Expand Up @@ -209,6 +209,7 @@ sub sudo(&) {
foreach my $variable (keys %{$context}) {
local $Data::Dumper::Deparse = 1;
local $Data::Dumper::Indent = 0;
local $Data::Dumper::Terse = 0;

my $value = $context->{$variable};

Expand Down Expand Up @@ -237,7 +238,7 @@ sub sudo(&) {
$code .= $deparse->coderef2text(shift);

if($ENV{UNIX_SUDO_SPILLGUTS}) { warn $code }

my $rv = system(
"sudo", "-p", "Unix::Sudo needs your password: ",
Probe::Perl->find_perl_interpreter(),
Expand Down
4 changes: 4 additions & 0 deletions t/pass-variables-in.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ sudosanity::checks && do {
};

is(sudo { $code->() }, 11, "Can read variables from the parent context");

$Data::Dumper::Terse = 1;
is(sudo { $code->() }, 11, 'Works when $Data::Dumper::Terse is set');

};

done_testing();

0 comments on commit 2efc430

Please sign in to comment.