line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
12478
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package PowerShell; |
5
|
|
|
|
|
|
|
$PowerShell::VERSION = '1.00'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Wraps PowerShell commands; |
7
|
|
|
|
|
|
|
# PODNAME: PowerShell |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
10
|
1
|
|
|
1
|
|
464
|
use Encode; |
|
1
|
|
|
|
|
6270
|
|
|
1
|
|
|
|
|
56
|
|
11
|
1
|
|
|
1
|
|
5
|
use Log::Any; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
6
|
|
12
|
1
|
|
|
1
|
|
449
|
use MIME::Base64; |
|
1
|
|
|
|
|
440
|
|
|
1
|
|
|
|
|
50
|
|
13
|
1
|
|
|
1
|
|
4
|
use POSIX qw(WIFEXITED WEXITSTATUS); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
14
|
1
|
|
|
1
|
|
46
|
use PowerShell::Pipeline; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
264
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
1
|
|
return bless( {}, shift )->_init(@_); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub command { |
23
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $encoded_command = |
26
|
0
|
|
|
|
|
|
MIME::Base64::encode_base64( Encode::encode( 'UTF-16LE', $self->{pipeline}->command() ), |
27
|
|
|
|
|
|
|
'' ); |
28
|
0
|
|
|
|
|
|
return "powershell -EncodedCommand $encoded_command"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub execute { |
32
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $powershell_command = $self->command(); |
35
|
0
|
|
|
|
|
|
$logger->debugf( 'running [%s]', $powershell_command ); |
36
|
0
|
|
|
|
|
|
my $result = `$powershell_command 2> /dev/null`; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if ( WIFEXITED( ${^CHILD_ERROR_NATIVE} ) ) { |
39
|
0
|
|
|
|
|
|
my $exit_status = WEXITSTATUS( ${^CHILD_ERROR_NATIVE} ); |
40
|
0
|
0
|
|
|
|
|
if ($exit_status) { |
41
|
0
|
|
|
|
|
|
croak("[$powershell_command] failed: $exit_status"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
0
|
|
|
|
|
|
croak("[$powershell_command] exited abnormally"); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $result; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _init { |
52
|
0
|
|
|
0
|
|
|
my ( $self, @rest ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
0
|
|
|
|
if ( ref( $rest[0] ) && $rest[0]->isa('PowerShell::Pipeline') ) { |
55
|
0
|
|
|
|
|
|
$self->{pipeline} = $rest[0]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
|
$self->{pipeline} = PowerShell::Pipeline->new()->add(@rest); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub pipe_to { |
65
|
0
|
|
|
0
|
1
|
|
my ( $self, @rest ) = @_; |
66
|
0
|
|
|
|
|
|
$self->{pipeline}->add(@rest); |
67
|
0
|
|
|
|
|
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |