PowerShell.pm

filter: Statementstmt 55.1% 27 / 49 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.5% 8 / 13 Podpod 100% 4 / 4 totaltotal 50.6% 39 / 77 CC 5 SCAR 16.2
CC
5
Cov
47%
execute
12.0
_init
12.0
new
2.0
CRAP 5.1
↑ Summary PowerShell/Pipeline.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package PowerShell;
5 1 $PowerShell::VERSION = '1.00';
6 # ABSTRACT: Wraps PowerShell commands;
7 # PODNAME: PowerShell
8  
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use POSIX qw(WIFEXITED WEXITSTATUS);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use PowerShell::Pipeline;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 my $logger = Log::Any->get_logger();
17  
18 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
19 0 return bless( {}, shift )->_init(@_);
20 }
21  
22 0 ▶sub command {
Subroutine command: not called CC=1 SCAR=6.9
Pod documented
23 0 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 0 ▶sub execute {
Subroutine execute: not called CC=3 SCAR=24.8
Pod documented
32 0 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 ▶ if ( WIFEXITED( ${^CHILD_ERROR_NATIVE} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (WIFEXITED(${^CHILD_ERROR_NATIVE})) { } 0 0 0
39 0 my $exit_status = WEXITSTATUS( ${^CHILD_ERROR_NATIVE} );
40 0 ▶ if ($exit_status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_status) 0 0 0
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 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
52 0 my ( $self, @rest ) = @_;
53  
54 0 ▶ if ( ref( $rest[0] ) && $rest[0]->isa('PowerShell::Pipeline') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rest[0] and $rest[0]->isa('PowerShell::Pipeline')) { } 0 0 0
Condition0%0/3
ref $rest[0] and $rest[0]->isa("PowerShell::Pipeline")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rest[0] and $rest[0]->isa("PowerShell::Pipeline")
ref $rest[0] $rest[0]->isa("PowerShell::Pipeline")
Truth table0%0/3
A and B
A= ref $rest[0]B= $rest[0]->isa("PowerShell::Pipeline")
ABresult
0X0
100
111
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 0 ▶sub pipe_to {
Subroutine pipe_to: not called CC=1 SCAR=6.9
Pod documented
65 0 my ( $self, @rest ) = @_;
66 0 $self->{pipeline}->add(@rest);
67 0 return $self;
68 }
69  
70 1 1;
71  
72 __END__
↑ Summary PowerShell/Pipeline.pm »