File Coverage

blib/lib/IPC/ShellCmd/Sudo.pm
Criterion Covered Total %
statement 9 18 50.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 3 4 75.0
pod 0 1 0.0
total 12 30 40.0


line stmt bran cond sub pod time code
1             package IPC::ShellCmd::Sudo;
2              
3 1     1   1093 use strict;
  1         1  
  1         39  
4 1     1   6 use Carp qw(croak);
  1         3  
  1         60  
5 1     1   5 use base qw(IPC::ShellCmd::ShBase);
  1         3  
  1         263  
6              
7             =head1 NAME
8              
9             IPC::ShellCmd::Sudo - Chain sudo-ing to a different user before running the command
10              
11             =head1 SYNOPSIS
12              
13             $cmd_obj->chain_prog(
14             IPC::ShellCmd::Sudo->new(
15             User => 'cpanbuild',
16             SetHome => 1,
17             )
18             );
19              
20              
21             =head1 DESCRIPTION
22              
23             =head2 IPC::ShellCmd::Sudo->B([I<$opt> => I<$val>, ...])
24              
25             The only external method for this is the constructor. This sets up the
26             various arguments that are going to be used to generate the command-line.
27              
28             Other methods on this are used by L, but it should only ever be
29             used inside of the B method on a L object.
30              
31             =over 4
32              
33             =item B
34              
35             Specifies the username to sudo to
36              
37             =item B
38              
39             If true, this will cause sudo to set up $ENV{HOME} for the new user,
40             otherwise it will be that of the current user.
41              
42             =back
43              
44             =cut
45              
46             sub chain {
47 0     0 0   my $self = shift;
48 0           my $cmd = shift;
49 0           my $args = shift;
50              
51 0           my $cmd_string = $self->generate_sh_cmd($cmd, $args);
52              
53 0           my @sudo_args = ('sudo');
54              
55 0 0         push (@sudo_args, "-u", $self->{args}->{User})
56             if(defined $self->{args}->{User});
57              
58 0 0 0       push (@sudo_args, "-H")
59             if(defined $self->{args}->{SetHome} && $self->{args}->{SetHome});
60              
61 0           push (@sudo_args, "sh", "-c", $cmd_string);
62              
63 0           return @sudo_args;
64             }
65              
66             =head1 BUGS
67              
68             I don't know of any, but that doesn't mean they're not there.
69              
70             =head1 AUTHORS
71              
72             See L for authors.
73              
74             =head1 LICENSE
75              
76             See L for the license.
77              
78             =cut
79              
80             1;