Git/Annex/BatchCommand.pm

filter: Statementstmt 40.8% 20 / 49 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 6 / 12 Podpod 100% 3 / 3 totaltotal 38.6% 29 / 75 CC 6 SCAR 20.3
CC
6
Cov
34%
new
20.0
say
12.0
restart
2.0
CRAP 7.6
« App/annex_to_annex_dropunused.pm ↑ Summary
1 package Git::Annex::BatchCommand;
2 # ABSTRACT: Perl interface to git-annex --batch commands
3 #
4 # Copyright (C) 2020 Sean Whitton <spwhitton@spwhitton.name>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or (at
9 # your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 12 $Git::Annex::BatchCommand::VERSION = '0.008';
19  
20 12 ▶use 5.028;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 12 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 12 ▶use IPC::Open2;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28  
29 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
30 0 my (undef, $annex, $cmd, @params) = @_;
31 0 ▶ croak "not enough arguments to Git::Annex::BatchCommand constructor"
Branch: 1 branch
BranchTrueFalseTotal
unless $annex and $cmd 0 0 0
Condition0%0/3
$annex and $cmd
!ll&&!rl&&r
000
MC/DC0%0/2
$annex and $cmd
$annex $cmd
Truth table0%0/3
A and B
A= $annexB= $cmd
ABresult
0X0
100
111
32 unless $annex and $cmd;
33  
34 # normalise supplied arguments a little
35 0 ▶ unshift @params, "--batch" unless grep /\A--batch\z/, @params;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /\A--batch\z/u, @params 0 0 0
36  
37 0 my $self = bless { _annex => $annex, _cmd => [$cmd, @params] }
38 => "Git::Annex::BatchCommand";
39 0 $self->_spawn;
40 0 return $self;
41 }
42  
43  
44 0 ▶sub say {
Subroutine say: not called CC=3 SCAR=24.8
Pod documented
45 0 my ($self, @input) = @_;
46 0 my @output;
47 0 for (@input) {
48 0 chomp;
49 0 say { $self->{_in} } $_;
50 0 chomp(my $out = readline $self->{_out});
51 0 push @output, $out;
52 }
53 0 ▶ return wantarray ? @output : $output[$#output];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
54 }
55  
56  
57 12 *ask = \&say;
58  
59  
60 0 ▶sub restart {
Subroutine restart: not called CC=1 SCAR=6.9
Pod documented
61 0 my $self = shift;
62 0 $self->_despawn;
63 0 $self->_spawn;
64 }
65  
66 0 ▶sub _spawn {
Subroutine _spawn: not called CC=1 SCAR=6.9
67 0 my $self = shift;
68 0 my ($out, $in);
69 $self->{_pid} = open2 $out, $in, "git",
70 "-C", $self->{_annex}->toplevel,
71 0 "annex", @{ $self->{_cmd} };
72 0 ($self->{_out}, $self->{_in}) = ($out, $in);
73 }
74  
75 0 ▶sub _despawn {
Subroutine _despawn: not called CC=1 SCAR=6.9
76 0 my $self = shift;
77 0 close $self->{_in};
78 0 close $self->{_out};
79 # reap the child per IPC::Open2 docs
80 0 waitpid $self->{_pid}, 0;
81 }
82  
83 0 ▶sub DESTROY { local($., $@, $!, $^E, $?); shift->_despawn }
Subroutine DESTROY: not called CC=1 SCAR=6.9
84  
85 12 1;
86  
87 __END__
« App/annex_to_annex_dropunused.pm ↑ Summary