« 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
| |||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | my $pager = $ENV{PINTO_PAGER} // $ENV{PAGER} | ||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | // return \*STDOUT; | ||||||||||||||||||||||||||||||||
|
Condition0%0/5
($ENV{"PINTO_PAGER"} // $ENV{"PAGER"}) // (return \*STDOUT)
$ENV{"PINTO_PAGER"} // $ENV{"PAGER"}
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"}
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | $msg .= "\n" if !$opts->{no_newline}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | $self->stdout->print($msg) or croak($!); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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 //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | return if $self->quiet; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | $msg = $msg->() if ref $msg eq 'CODE'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 4 | chomp $msg; | |||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | $msg .= "\n" if !$opts->{no_newline}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | $self->stderr->print($msg) or croak($!); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | return 0 if $self->quiet; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->has_made_progress and $self->should_render_progress
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
| |||||||||||||||||||||||||||||||||||
| 94 | if !$self->has_made_progress | ||||||||||||||||||||||||||||||||||
| 95 | || !$self->should_render_progress; | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $self->stderr->print("\n") or croak($!); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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()
$self->verbose > 0 and not $self->quiet
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()
| |||||||||||||||||||||||||||||||||||
| 105 | && ! $self->quiet | ||||||||||||||||||||||||||||||||||
| 106 | && ! is_interactive(); | ||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 5 | 1; | |||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||||||||