VCI/VCS/Bzr.pm

filter: Statementstmt 27.2% 27 / 99 Branchbran 4.7% 2 / 42 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 53.8% 7 / 13 Podpod 33.3% 1 / 3 totaltotal 18.6% 37 / 198 CC 31 SCAR 47.2
CC
31
Cov
17%
__ANON__
182.0
x_do
182.0
_build_x_bzr
12.0
CRAP 111.8
↑ Summary VCI/Abstract/Directory.pm »
1 package VCI::VCS::Bzr;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 our $VERSION = '0.7.1';
4  
5 2 ▶use VCI::Util qw(taint_fail);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use MooseX::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use IPC::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Scalar::Util qw(tainted);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 extends 'VCI';
12  
13 # The path to the bzr binary.
14 has 'x_bzr' => (is => 'ro', isa => 'Str',
15 0 ▶ default => sub { shift->_build_x_bzr });
Subroutine __ANON__: not called CC=1 SCAR=1.2
16  
17 0 ▶sub BUILD {
Subroutine BUILD: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my $self = shift;
19 taint_fail("The x_bzr argument '$self->{x_bzr}' is tainted")
20 0 ▶ if tainted($self->{x_bzr});
Branch: 1 branch
BranchTrueFalseTotal
if &tainted($self->{"x_bzr"}) 0 0 0
21 }
22  
23 0 ▶sub diff_class {
Subroutine diff_class: not called CC=1 SCAR=6.9
Pod undocumented
24 0 require VCI::Abstract::Diff;
25 0 return 'VCI::Abstract::Diff';
26 }
27  
28 0 ▶sub _build_x_bzr {
Subroutine _build_x_bzr: not called CC=3 SCAR=24.8
29 0 ▶ my $cmd = IPC::Cmd::can_run('bzr')
Condition0%0/2
IPC::Cmd::can_run('bzr') || confess(q[Could not find 'bzr' in your path])
l!l
00
MC/DC0%0/1
IPC::Cmd::can_run('bzr') || confess(q[Could not find 'bzr' in your path])
IPC::Cmd::can_run('bzr')
Truth table0%0/2
A
A= IPC::Cmd::can_run('bzr')
Aresult
11
00
30 || confess("Could not find 'bzr' in your path");
31 0 ▶ taint_fail("We found '$cmd' for bzr, but that string is tainted."
Branch: 1 branch
BranchTrueFalseTotal
if &tainted($cmd) 0 0 0
32 . ' This probably means $ENV{PATH} is tainted')
33 if tainted($cmd);
34 0 return $cmd;
35 }
36  
37 1 ▶sub missing_requirements {
Subroutine missing_requirements: called CC=2 SCAR=7.0
Pod documented
38 1 my $bzr = IPC::Cmd::can_run('bzr');
39 1 ▶ my %have = (
Branch: 1 branch
BranchTrueFalseTotal
$bzr ? : 0 1 1
40 bzr => $bzr ? 1 : 0,
41 bzrtools => _check_bzr_plugin($bzr, 'bzrtools'),
42 'bzr-xmloutput' => _check_bzr_plugin($bzr, 'xmloutput'),
43 );
44 1 return (grep { !$have{$_} } keys %have);
45 }
46  
47 2 ▶sub _check_bzr_plugin {
Subroutine _check_bzr_plugin: called CC=3 SCAR=16.5
48 2 my ($bzr, $plugin) = @_;
49 2 ▶ return 0 if !$bzr;
Branch: 1 branch
BranchTrueFalseTotal
unless $bzr 2 0 2
50 0 my $plugins = `$bzr plugins`;
51 0 ▶ return ($plugins =~ /^\Q$plugin\E/m) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$plugins =~ /^\Q$plugin\E/m ? : 0 0 0
52 }
53  
54 method 'x_do' => named (
55 args => { isa => 'ArrayRef', required => 1 },
56 errors_undef => { isa => 'ArrayRef', default => [] },
57 errors_ignore => { isa => 'ArrayRef', default => [] },
58 errors_undef_regex => { isa => 'RegexpRef' },
59 errors_ignore_regex => { isa => 'RegexpRef' },
60 0 ▶) => sub {
Subroutine x_do: not called CC=13 SCAR=52.0
Subroutine __ANON__: not called CC=13 SCAR=52.0
61 0 my ($self, $params) = @_;
62 0 my $args = $params->{args};
63
64 0 my $full_command = $self->x_bzr . ' ' . join(' ', @$args);
65 0 ▶ if ($self->debug) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->debug) 0 0 0
if ($self->debug) 0 0 0
66 0 print STDERR "Command: $full_command\n";
67 }
68
69 0 my ($success, $error_msg, $all, $stdout, $stderr) =
70 IPC::Cmd::run(command => [$self->x_bzr, @$args]);
71
72 0 ▶ print STDERR "Error Message: $error_msg\n"
Branch: 2 branches
BranchTrueFalseTotal
if defined $error_msg and $self->debug > 1 0 0 0
if defined $error_msg and $self->debug > 1 0 0 0
Condition0%0/6
defined $error_msg and $self->debug > 1
!ll&&!rl&&r
000
defined $error_msg and $self->debug > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $error_msg and $self->debug > 1
defined $error_msg $self->debug > 1
MC/DC0%0/2
defined $error_msg and $self->debug > 1
defined $error_msg $self->debug > 1
Truth table0%0/3
A and B
A= defined $error_msgB= $self->debug > 1
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $error_msgB= $self->debug > 1
ABresult
0X0
100
111
73 if (defined $error_msg and $self->debug > 1);
74
75 0 ▶ if (!$success) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($success) 0 0 0
unless ($success) 0 0 0
76 0 my $err_string = join('', @$stderr);
77 0 my $error_code;
78 0 ▶ if ($error_msg =~ /exited with value (\d+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($error_msg =~ /exited with value (\d+)/) { } 0 0 0
if ($error_msg =~ /exited with value (\d+)/) { } 0 0 0
79 0 $error_code = $1;
80 }
81 else {
82 # A value that will never be in errors_ignore.
83 0 $error_code = -1;
84 }
85 0 ▶ if (!grep {$_ == $error_code} @{$params->{errors_ignore}}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (grep {$_ == $error_code;} @{$$params{"errors_ignore"};}) 0 0 0
unless (grep {$_ == $error_code;} @{$$params{"errors_ignore"};}) 0 0 0
86 0 my $re = $params->{errors_undef_regex};
87 0 ▶ if (grep {$_ == $error_code} @{$params->{errors_undef}}
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_ == $error_code;} @{$params->{"errors_undef"};} || defined $re && $err_string =~ /$re/) 0 0 0
if (grep {$_ == $error_code;} @{$params->{"errors_undef"};} || defined $re && $err_string =~ /$re/) 0 0 0
Condition0%0/12
@{$params->{'errors_undef'};} || defined $re && $err_string =~ /$re/
l!l&&r!l&&!r
000
defined $re and $err_string =~ /$re/
!ll&&!rl&&r
000
@{$params->{'errors_undef'};} || defined $re && $err_string =~ /$re/
l!l&&r!l&&!r
000
defined $re and $err_string =~ /$re/
!ll&&!rl&&r
000
MC/DC0%0/3
@{$params->{'errors_undef'};} || defined $re && $err_string =~ /$re/
@{$params->{'errors_undef'};} defined $re $err_string =~ /$re/
MC/DC0%0/3
@{$params->{'errors_undef'};} || defined $re && $err_string =~ /$re/
@{$params->{'errors_undef'};} defined $re $err_string =~ /$re/
Truth table0%0/4
A || B and C
A= @{$params->{'errors_undef'};}B= defined $reC= $err_string =~ /$re/
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/4
A || B and C
A= @{$params->{'errors_undef'};}B= defined $reC= $err_string =~ /$re/
ABCresult
1XX1
0111
00X0
0100
88 || (defined $re && $err_string =~ $re))
89 {
90 0 return undef;
91 }
92
93 0 my $ignore_re = $params->{errors_ignore_regex};
94 0 ▶ unless (defined $ignore_re && $err_string =~ $ignore_re) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $ignore_re and $err_string =~ /$ignore_re/) 0 0 0
unless (defined $ignore_re and $err_string =~ /$ignore_re/) 0 0 0
Condition0%0/6
defined $ignore_re and $err_string =~ /$ignore_re/
!ll&&!rl&&r
000
defined $ignore_re and $err_string =~ /$ignore_re/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ignore_re and $err_string =~ /$ignore_re/
defined $ignore_re $err_string =~ /$ignore_re/
MC/DC0%0/2
defined $ignore_re and $err_string =~ /$ignore_re/
defined $ignore_re $err_string =~ /$ignore_re/
Truth table0%0/3
A and B
A= defined $ignore_reB= $err_string =~ /$ignore_re/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $ignore_reB= $err_string =~ /$ignore_re/
ABresult
0X0
100
111
95 0 my $error_output = join('', @$stderr);
96 0 chomp($error_output);
97 0 confess("$full_command failed: $error_output");
98 }
99 }
100 }
101
102 0 my $output_string = join('', @$stdout);
103 0 chomp($output_string);
104 0 ▶ if ($self->debug > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->debug > 1) 0 0 0
if ($self->debug > 1) 0 0 0
105 0 print STDERR "Results:\n" . join('', @$all);
106 }
107 0 return $output_string;
108 1 };
109  
110 1 __PACKAGE__->meta->make_immutable;
111  
112 1 1;
113  
114 __END__
↑ Summary VCI/Abstract/Directory.pm »