diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-01-27 13:01:50 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-01-27 13:03:19 -0700 |
commit | ec71172cbb11466f442a8f0b811c14ff59cd7782 (patch) | |
tree | e5f2a959fb916d2b6561071e10996e611daf2385 /perl5 | |
parent | d873a7f42d0a50404cc973079275591ccd5cd028 (diff) | |
download | dotfiles-ec71172cbb11466f442a8f0b811c14ff59cd7782.tar.gz |
refactor as_me
Diffstat (limited to 'perl5')
-rw-r--r-- | perl5/Local/Rex/Util.pm | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/perl5/Local/Rex/Util.pm b/perl5/Local/Rex/Util.pm index 003707c1..db81c8d8 100644 --- a/perl5/Local/Rex/Util.pm +++ b/perl5/Local/Rex/Util.pm @@ -7,12 +7,17 @@ use parent 'Exporter'; use Rex -feature => ['1.4']; -our @EXPORT = qw( as_me ); +our @EXPORT = qw( as as_me ); + +sub as ($&) { + can_run "sudo" or die "wanted to execute as $_[0] but no sudo on PATH!"; + sudo { user => $_[0], command => $_[1]}; +} sub as_me (&) { + sub as ($&); my $me = get("me") || "spwhitton"; - can_run "sudo" or die "wanted to execute as $me but no sudo on PATH!"; - sudo { user => $me, command => $_[0] }; + as $me, \&{$_[0]}; } 1; |