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 4446f93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
65535 2024-01-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
7 changes: 4 additions & 3 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 @@ -181,7 +181,7 @@ L<git://github.com/DrHyde/perl-modules-Unix-Sudo.git>
=head1 AUTHOR, COPYRIGHT and LICENCE
Copyright 2021 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
Copyright 2024 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
This software is free-as-in-speech software, and may be used, distributed, and
modified under the terms of either the GNU General Public Licence version 2 or
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 4446f93

Please sign in to comment.