| 1 | package Webservice::Rosary::Stream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Time::HiRes qw/sleep/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = "0.1.7"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=17 SCAR=30.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | delay => defined $opts{delay} ? 0 + $opts{delay} : 0.04, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | speed => defined $opts{speed} ? 0 + $opts{speed} : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | base_speed => defined $opts{speed} ? 0 + $opts{speed} : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | min_speed => defined $opts{min_speed} ? 0 + $opts{min_speed} : 0.25, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | max_speed => defined $opts{max_speed} ? 0 + $opts{max_speed} : 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | speed_step => defined $opts{speed_step} ? 0 + $opts{speed_step} : 1.25, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | controls => exists $opts{controls} ? $opts{controls} : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | paused => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | quit_requested => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | confirm_quit => $opts{confirm_quit}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | on_quit => $opts{on_quit}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | read_key => $opts{read_key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sleep_cb => $opts{sleep_cb} || sub { sleep $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | write_cb => $opts{write_cb} || sub { print STDOUT $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | terminal_active => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition66%4/6
$opts{'sleep_cb'} || sub {
&Webservice::Rosary::Stream::sleep($_[0]);
}
$opts{'write_cb'} || sub {
print STDOUT $_[0];
}
MC/DC0%0/2
$opts{'sleep_cb'} || sub {
&Webservice::Rosary::Stream::sleep($_[0]);
}
$opts{'sleep_cb'}
sub {
&Webservice::Rosary::Stream::sleep($_[0]);
}
MC/DC0%0/2
$opts{'write_cb'} || sub {
print STDOUT $_[0];
}
$opts{'write_cb'}
sub {
print STDOUT $_[0];
}
Truth table66%2/3
A || B
A= $opts{'sleep_cb'}B= sub {
&Webservice::Rosary::Stream::sleep($_[0]);
}
Truth table66%2/3
A || B
A= $opts{'write_cb'}B= sub {
print STDOUT $_[0];
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | owns_reader => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | die "stream delay must be zero or greater\n" if $self->{delay} < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | die "stream speed must be greater than zero\n" if $self->{speed} <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | die "minimum stream speed must be greater than zero\n" if $self->{min_speed} <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | die "maximum stream speed must be at least minimum stream speed\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | if $self->{max_speed} < $self->{min_speed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | die "stream speed step must be greater than one\n" if $self->{speed_step} <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | if ($self->{read_key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | $self->{terminal_active} = $self->{controls} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | $self->_enable_terminal_controls; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub delay { return $_[0]->{delay}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delay: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | sub speed { return $_[0]->{speed}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
speed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | sub paused { return $_[0]->{paused}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paused: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub quit_requested { return $_[0]->{quit_requested}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quit_requested: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 15 | ▶ | sub interactive { return $_[0]->{controls} && $_[0]->{terminal_active}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interactive: called CC=2 SCAR=7.2
Pod
undocumented
Condition66%2/3
$_[0]{'controls'} && $_[0]{'terminal_active'}
MC/DC50%1/2
$_[0]{'controls'} && $_[0]{'terminal_active'}
$_[0]{'controls'}
$_[0]{'terminal_active'}
Truth table66%2/3
A && B
A= $_[0]{'controls'}B= $_[0]{'terminal_active'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub controls_help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
controls_help: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return q{SPACE/p pause/resume, +/- speed, 0 reset, q quit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | sub _enable_terminal_controls { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enable_terminal_controls: called CC=6 SCAR=34.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | return 0 if not $self->{controls}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return 0 if $self->{read_key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return 0 if not -t STDIN or not -t STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-t STDIN and -t STDOUT
MC/DC0%0/2
-t STDIN and -t STDOUT
-t STDIN
-t STDOUT
Truth table0%0/3
A and B
A= -t STDINB= -t STDOUT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | require Term::ReadKey; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | Term::ReadKey::ReadMode(q{cbreak}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return 0 if not $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $self->{read_key} = sub { return Term::ReadKey::ReadKey(-1); }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->{terminal_active} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->{owns_reader} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | sub restore_terminal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restore_terminal: called CC=3 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | ▶ | if ($self->{owns_reader} and $self->{terminal_active}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"owns_reader"} and $self->{"terminal_active"}
MC/DC0%0/2
$self->{"owns_reader"} and $self->{"terminal_active"}
$self->{"owns_reader"}
$self->{"terminal_active"}
Truth table33%1/3
A and B
A= $self->{"owns_reader"}B= $self->{"terminal_active"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | eval { Term::ReadKey::ReadMode(q{restore}); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->{terminal_active} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->{read_key} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->{owns_reader} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub resume_terminal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resume_terminal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return $self->_enable_terminal_controls; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 16 | ▶ | sub handle_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_key: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 16 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 16 | ▶ | return q{} if not defined $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 11 | ▶ | if ($key eq q{ } or lc($key) eq q{p}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq " " or lc $key eq "p"
MC/DC100%2/2
$key eq " " or lc $key eq "p"
$key eq " "
lc $key eq "p"
Truth table100%3/3
A or B
A= $key eq " "B= lc $key eq "p"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | $self->{paused} = not $self->{paused}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | return $self->{paused} ? q{paused} : q{resumed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | ▶ | if ($key eq q{+} or $key eq q{=}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "+" or $key eq "="
MC/DC50%1/2
$key eq "+" or $key eq "="
$key eq "+"
$key eq "="
Truth table66%2/3
A or B
A= $key eq "+"B= $key eq "="
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | $self->{speed} *= $self->{speed_step}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | ▶ | $self->{speed} = $self->{max_speed} if $self->{speed} > $self->{max_speed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | return q{faster}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | ▶ | if ($key eq q{-} or $key eq q{_}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "-" or $key eq "_"
MC/DC50%1/2
$key eq "-" or $key eq "_"
$key eq "-"
$key eq "_"
Truth table66%2/3
A or B
A= $key eq "-"B= $key eq "_"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | $self->{speed} /= $self->{speed_step}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | $self->{speed} = $self->{min_speed} if $self->{speed} < $self->{min_speed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | return q{slower}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | if ($key eq q{0}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | $self->{speed} = $self->{base_speed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | return q{reset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | if (lc($key) eq q{q}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return q{quit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | return q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub _confirm_quit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_confirm_quit: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return 1 if $self->{quit_requested}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # A blocking y/N prompt cannot safely run while the terminal is in cbreak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # mode. Restore it first; if the user declines, resume live controls. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->restore_terminal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $confirmed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ($self->{confirm_quit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $confirmed = $self->{confirm_quit}->() ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | print STDOUT "\nQuit y/N? "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $answer = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | $confirmed = defined($answer) && $answer =~ m/^\s*y(?:es)?\s*$/i ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $answer and $answer =~ /^\s*y(?:es)?\s*$/i
MC/DC0%0/2
defined $answer and $answer =~ /^\s*y(?:es)?\s*$/i
defined $answer
$answer =~ /^\s*y(?:es)?\s*$/i
Truth table0%0/3
A and B
A= defined $answerB= $answer =~ /^\s*y(?:es)?\s*$/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $self->{quit_requested} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->{paused} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $self->{on_quit}->() if $self->{on_quit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $self->resume_terminal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 14 | ▶ | sub _poll_control { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_poll_control: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 14 | ▶ | return q{} if not $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | my $key = $self->{read_key}->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | my $action = $self->handle_key($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 8 | ▶ | $self->_confirm_quit if $action eq q{quit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 8 | return $action; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 12 | ▶ | sub _wait_while_paused { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wait_while_paused: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 12 | ▶ | while ($self->{paused} and not $self->{quit_requested}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"paused"} and not $self->{"quit_requested"}
MC/DC50%1/2
$self->{"paused"} and not $self->{"quit_requested"}
$self->{"paused"}
not $self->{"quit_requested"}
Truth table66%2/3
A and not(B)
A= $self->{"paused"}B= not $self->{"quit_requested"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | $self->{sleep_cb}->(0.05); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | $self->_poll_control; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 5 | ▶ | sub _sleep_with_controls { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sleep_with_controls: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 5 | my ($self, $seconds) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 5 | ▶ | return if not defined $seconds or $seconds <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $seconds or $seconds <= 0
MC/DC50%1/2
not defined $seconds or $seconds <= 0
not defined $seconds
$seconds <= 0
Truth table66%2/3
not(A) or B
A= not defined $secondsB= $seconds <= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | my $remaining = $seconds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | while ($remaining > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 7 | $self->_poll_control; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 7 | ▶ | return q{quit} if $self->{quit_requested}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | $self->_wait_while_paused; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | ▶ | return q{quit} if $self->{quit_requested}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 7 | ▶ | my $slice = $remaining > 0.025 ? 0.025 : $remaining; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 7 | $self->{sleep_cb}->($slice); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 7 | $remaining -= $slice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | ▶ | sub stream { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stream: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | ▶ | return if not defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | foreach my $char (split //, $text) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | $self->_poll_control; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | ▶ | return q{quit} if $self->{quit_requested}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 5 | $self->_wait_while_paused; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | ▶ | return q{quit} if $self->{quit_requested}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | $self->{write_cb}->($char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | my $delay = $self->{delay} / $self->{speed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 5 | my $status = $self->_sleep_with_controls($delay); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | ▶ | return q{quit} if defined $status and $status eq q{quit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $status and $status eq "quit"
MC/DC0%0/2
defined $status and $status eq "quit"
defined $status
$status eq "quit"
Truth table33%1/3
A and B
A= defined $statusB= $status eq "quit"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | return q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub wait { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my ($self, $seconds) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return $self->_sleep_with_controls($seconds); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 6 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 6 | $self->restore_terminal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||