blib/lib/Pinto/Remote/SelfContained/Chrome.pm

filter: Statementstmt 70.8% 51 / 72 Branchbran 35.2% 12 / 34 Conditioncond 16.6% 3 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 72.7% 16 / 22 Podpod 0.0% 0 / 13 totaltotal 48.8% 82 / 168 CC 25 SCAR 18.9
CC
25
Cov
53%
__ANON__
20.7
should_render_progress
12.0
progress_done
8.1
CRAP 6.6
« blib/lib/Pinto/Remote/SelfContained/Util.pm ↑ Summary blib/lib/Pinto/Remote/SelfContained/Action/Install.pm »
1 package
2 Pinto::Remote::SelfContained::Chrome; # hide from PAUSE
3 # ABSTRACT: UI for self-contained remote operations
4  
5 5 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use IO::Handle; # ensure methods are available
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use IO::Interactive qw(is_interactive);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Types::Standard qw(Bool FileHandle Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 our $VERSION = '1.999'; # TRIAL VERSION
16  
17 5 has verbose => (is => 'ro', isa => Int, default => 0);
18 5 has quiet => (is => 'ro', isa => Bool, default => 0);
19  
20 # Not currently overridable:
21 5 ▶sub color { 0 }
Subroutine color: called CC=1 SCAR=0.0
Pod undocumented
22 5 ▶sub palette { [qw(green yellow red)] }
Subroutine palette: called CC=1 SCAR=0.0
Pod undocumented
23  
24 1 ▶has stderr => (is => 'ro', isa => FileHandle, default => sub { \*STDERR });
Subroutine __ANON__: called CC=1 SCAR=0.0
25 1 ▶has stdout => (is => 'ro', isa => FileHandle, default => sub {
Subroutine __ANON__: called CC=5 SCAR=30.3
26 1 ▶ return \*STDOUT unless is_interactive();
Branch: 1 branch
BranchTrueFalseTotal
unless is_interactive() 1 0 1
27  
28 my $pager = $ENV{PINTO_PAGER} // $ENV{PAGER}
29 0 ▶ // return \*STDOUT;
Condition0%0/5
($ENV{"PINTO_PAGER"} // $ENV{"PAGER"}) // (return \*STDOUT)
l!l
00
$ENV{"PINTO_PAGER"} // $ENV{"PAGER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($ENV{"PINTO_PAGER"} // $ENV{"PAGER"}) // (return \*STDOUT)
$ENV{"PINTO_PAGER"} $ENV{"PAGER"}
Truth table0%0/3
A // B
A= $ENV{"PINTO_PAGER"}B= $ENV{"PAGER"}
ABresult
1X1
011
000
30  
31 open my $fh, '|-', $pager, grep defined, $ENV{PINTO_PAGER_OPTIONS}
32 0 ▶ or croak("Can't open pipe to pager $pager: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "|-", $pager, grep(defined($_), $ENV{"PINTO_PAGER_OPTIONS"}) or croak("Can't open pipe to pager ${pager}: $!") 0 0 0
33 0 $fh->autoflush(1);
34  
35 0 return $fh;
36 5 });
37  
38 5 has has_made_progress => (is => 'rw', isa => Bool, default => 0);
39  
40 0 ▶sub diag_levels { qw(error warning notice info) }
Subroutine diag_levels: not called CC=1 SCAR=6.9
Pod undocumented
41  
42 0 ▶sub error { shift->diag(@_) if $_[0]->should_render_diag(0); return }
Subroutine error: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->should_render_diag(0) 0 0 0
43 0 ▶sub warning { shift->diag(@_) if $_[0]->should_render_diag(1); return }
Subroutine warning: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->should_render_diag(1) 0 0 0
44 0 ▶sub notice { shift->diag(@_) if $_[0]->should_render_diag(2); return }
Subroutine notice: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->should_render_diag(2) 0 0 0
45 4 ▶sub info { shift->diag(@_) if $_[0]->should_render_diag(3); return }
Subroutine info: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->should_render_diag(3) 2 2 4
46  
47 3 ▶sub show {
Subroutine show: called CC=4 SCAR=14.6
Pod undocumented
48 3 my ($self, $msg, $opts) = @_;
49  
50 3 ▶ $opts //= {};
Condition50%1/2
$opts //= {}
l!l
03
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
51 3 ▶ $msg .= "\n" if !$opts->{no_newline};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"no_newline"} 3 0 3
52 3 ▶ $self->stdout->print($msg) or croak($!);
Branch: 1 branch
BranchTrueFalseTotal
$self->stdout->print($msg) or croak($!) 3 0 3
53 3 return $self;
54 }
55  
56 4 ▶sub diag {
Subroutine diag: called CC=6 SCAR=19.3
Pod undocumented
57 4 my ($self, $msg, $opts) = @_;
58  
59 4 ▶ $opts //= {};
Condition50%1/2
$opts //= {}
l!l
04
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
60  
61 4 ▶ return if $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $self->quiet 0 4 4
62  
63 4 ▶ $msg = $msg->() if ref $msg eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msg eq "CODE" 0 4 4
64 4 chomp $msg;
65 4 ▶ $msg .= "\n" if !$opts->{no_newline};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"no_newline"} 4 0 4
66  
67 4 ▶ $self->stderr->print($msg) or croak($!);
Branch: 1 branch
BranchTrueFalseTotal
$self->stderr->print($msg) or croak($!) 4 0 4
68 }
69  
70 4 ▶sub should_render_diag {
Subroutine should_render_diag: called CC=3 SCAR=11.4
Pod undocumented
71 4 my ($self, $level) = @_;
72  
73 4 ▶ return 1 if $level == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $level == 0 0 4 4
74 4 ▶ return 0 if $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $self->quiet 0 4 4
75 4 return $level <= $self->verbose + 1;
76 }
77  
78 0 ▶sub show_progress {
Subroutine show_progress: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my ($self) = @_;
80  
81 0 ▶ return if !$self->should_render_progress;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->should_render_progress 0 0 0
82  
83 0 $self->stderr->autoflush; # Make sure pipes are hot
84 0 $self->stderr->print('.');
85 0 $self->has_made_progress(1);
86  
87 0 return 1;
88 }
89  
90 5 ▶sub progress_done {
Subroutine progress_done: called CC=4 SCAR=20.9
Pod undocumented
91 5 my ($self) = @_;
92  
93 5 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_made_progress and $self->should_render_progress 5 0 5
Condition33%1/3
$self->has_made_progress and $self->should_render_progress
!ll&&!rl&&r
500
MC/DC0%0/2
$self->has_made_progress and $self->should_render_progress
$self->has_made_progress $self->should_render_progress
Truth table33%1/3
A and B
A= $self->has_made_progressB= $self->should_render_progress
ABresult
0X0
100
111
94 if !$self->has_made_progress
95 || !$self->should_render_progress;
96  
97 0 ▶ $self->stderr->print("\n") or croak($!);
Branch: 1 branch
BranchTrueFalseTotal
$self->stderr->print("\n") or croak($!) 0 0 0
98 0 return 1;
99 }
100  
101 0 ▶sub should_render_progress {
Subroutine should_render_progress: not called CC=3 SCAR=24.8
Pod undocumented
102 0 my ($self) = @_;
103  
104 0 ▶ return $self->verbose > 0
Condition0%0/6
$self->verbose > 0 && !$self->quiet && !is_interactive()
!ll&&!rl&&r
000
$self->verbose > 0 and not $self->quiet
!ll&&!rl&&r
000
MC/DC0%0/3
$self->verbose > 0 && !$self->quiet && !is_interactive()
$self->verbose > 0 not $self->quiet !is_interactive()
Truth table0%0/4
A and not(B) && not(C)
A= $self->verbose > 0B= not $self->quietC= !is_interactive()
ABCresult
0XX0
10X0
1100
1111
105 && ! $self->quiet
106 && ! is_interactive();
107 }
108  
109 5 1;
110  
111 __END__
« blib/lib/Pinto/Remote/SelfContained/Util.pm ↑ Summary blib/lib/Pinto/Remote/SelfContained/Action/Install.pm »