| 1 | package App::DrivePlayer::Player; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # mpv-based audio player using JSON IPC socket for control. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Streams audio directly from Google Drive using Bearer auth headers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use App::DrivePlayer::Setup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use File::Temp qw( tempfile ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use IO::Socket::UNIX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use JSON::MaybeXS qw( encode_json decode_json ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Time::HiRes qw( time sleep ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | Readonly my $DRIVE_FILE_URL => 'https://www.googleapis.com/drive/v3/files/%s?alt=media'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my $log = do { eval { require Log::Log4perl; Log::Log4perl->get_logger(__PACKAGE__) } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | Readonly my $IPC_TIMEOUT => 0.5; # seconds to wait for mpv response | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | Readonly my $TOKEN_MAX_AGE => 3300; # refresh bearer token after 55 minutes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | has auth => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | isa => HasMethods['headers'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | has on_track_end => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => CodeRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | has on_position => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | isa => CodeRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | has on_state_change => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | isa => CodeRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Private mutable state — use plain attributes with is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 20 | ▶ | has _mpv_pid => ( is => 'rw', default => sub { undef } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 20 | ▶ | has _socket => ( is => 'rw', default => sub { undef } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 20 | ▶ | has _socket_path => ( is => 'rw', default => sub { undef } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | has _state => ( is => 'rw', isa => Str, default => 'stop' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 20 | ▶ | has _current_track => ( is => 'rw', default => sub { undef } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 20 | ▶ | has _token => ( is => 'rw', default => sub { undef } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | has _token_time => ( is => 'rw', isa => Num, default => 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | has _req_id => ( is => 'rw', isa => Int, default => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | has _pending_buf => ( is => 'rw', isa => Str, default => '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # ---- Public API ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my ($self, $track) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | $self->_ensure_mpv(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | $self->_current_track($track); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | my $url = sprintf($DRIVE_FILE_URL, $track->{drive_id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my $token = $self->_bearer_token(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $self->_send_command(['loadfile', $url, 'replace', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | { 'http-header-fields' => "Authorization: $token" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | $self->_set_state('play'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub pause_resume { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pause_resume: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | return if $self->_state eq 'stop'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $self->_send_command(['cycle', 'pause']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | $self->_set_state($self->_state eq 'play' ? 'pause' : 'play'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | return if $self->_state eq 'stop'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $self->_send_command(['stop']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $self->_set_state('stop'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub seek { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seek: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my ($self, $seconds) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | return if $self->_state eq 'stop'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | $self->_send_command(['seek', $seconds, 'absolute']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub set_volume { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_volume: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my ($self, $pct) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | $self->_send_command(['set_property', 'volume', $pct]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 12 | ▶ | sub state { $_[0]->_state } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
state: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | sub current_track { $_[0]->_current_track } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_track: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Called by GUI timer to poll position / detect track end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub poll { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
poll: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return if $self->_state eq 'stop'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return unless $self->_socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $self->_drain_events(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $pos_resp = $self->_send_command_sync(['get_property', 'time-pos']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $dur_resp = $self->_send_command_sync(['get_property', 'duration']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($pos_resp && defined $pos_resp->{data} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$pos_resp and defined $pos_resp->{"data"} and $dur_resp and defined $dur_resp->{"data"}
$pos_resp and defined $pos_resp->{"data"} and $dur_resp
$pos_resp and defined $pos_resp->{"data"}
MC/DC0%0/4
$pos_resp and defined $pos_resp->{"data"} and $dur_resp and defined $dur_resp->{"data"}
$pos_resp
defined $pos_resp->{"data"}
$dur_resp
defined $dur_resp->{"data"}
Truth table0%0/5
A and B and C and D
A= $pos_respB= defined $pos_resp->{"data"}C= $dur_respD= defined $dur_resp->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $dur_resp && defined $dur_resp->{data}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | $self->on_position->($pos_resp->{data}, $dur_resp->{data}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if $self->has_on_position; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub quit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quit: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($self->_mpv_pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | eval { $self->_send_command(['quit']) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->_close_socket(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Give mpv a moment to exit cleanly, then force-kill if still running. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $deadline = time() + 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | while (time() < $deadline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | last unless kill(0, $self->_mpv_pid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | sleep 0.1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | kill 'KILL', $self->_mpv_pid if kill(0, $self->_mpv_pid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | waitpid($self->_mpv_pid, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->_mpv_pid(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $self->_close_socket(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->_set_state('stop'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # ---- Private helpers ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | ▶ | sub _bearer_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bearer_token: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | ▶ | if (!$self->_token || (time() - $self->_token_time) > $TOKEN_MAX_AGE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->_token or &App::DrivePlayer::Player::time() - $self->_token_time > $TOKEN_MAX_AGE
MC/DC100%2/2
not $self->_token or &App::DrivePlayer::Player::time() - $self->_token_time > $TOKEN_MAX_AGE
not $self->_token
&App::DrivePlayer::Player::time() - $self->_token_time > $TOKEN_MAX_AGE
Truth table100%3/3
not(A) or B
A= not $self->_tokenB= &App::DrivePlayer::Player::time() - $self->_token_time > $TOKEN_MAX_AGE
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | delete $self->auth->{headers}; # clear cached token to force refresh | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 6 | my %h = @{ $self->auth->headers() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | $self->_token($h{Authorization}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | $self->_token_time(time()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | return $self->_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub _ensure_mpv { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ensure_mpv: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ($self->_mpv_pid && kill(0, $self->_mpv_pid)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_mpv_pid and kill 0, $self->_mpv_pid
MC/DC0%0/2
$self->_mpv_pid and kill 0, $self->_mpv_pid
$self->_mpv_pid
kill 0, $self->_mpv_pid
Truth table0%0/3
A and B
A= $self->_mpv_pidB= kill 0, $self->_mpv_pid
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return; # still alive | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $self->_close_socket(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my (undef, $socket_path) = tempfile("mpv-ipc-XXXXXX", TMPDIR => 1, OPEN => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $self->_socket_path($socket_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $pid = fork() // die "fork failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
fork // die("fork failed: $!")
MC/DC0%0/1
fork // die("fork failed: $!")
fork
Truth table0%0/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | exec( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 'mpv', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | '--idle=yes', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | '--no-video', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | '--no-terminal', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | '--really-quiet', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | "--input-ipc-server=$socket_path", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | '--gapless-audio=weak', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # Network buffering — reduces stuttering on slow/variable connections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | '--cache=yes', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | '--demuxer-max-bytes=32MiB', # read-ahead buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | '--demuxer-max-back-bytes=8MiB', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | '--cache-pause=yes', # pause & fill rather than stutter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | '--cache-pause-wait=3', # seconds of buffer before unpausing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | '--network-timeout=30', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ) or die "exec mpv failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->_mpv_pid($pid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $deadline = time() + 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | until (-S $socket_path || time() > $deadline) { sleep 0.1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-S $socket_path or &App::DrivePlayer::Player::time() > $deadline
MC/DC0%0/2
-S $socket_path or &App::DrivePlayer::Player::time() > $deadline
-S $socket_path
&App::DrivePlayer::Player::time() > $deadline
Truth table0%0/3
A or B
A= -S $socket_pathB= &App::DrivePlayer::Player::time() > $deadline
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | die "mpv IPC socket never appeared" unless -S $socket_path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $self->_open_socket(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub _open_socket { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_socket: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my $sock = IO::Socket::UNIX->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | Type => SOCK_STREAM, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | Peer => $self->_socket_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ) or die "Cannot connect to mpv socket: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $sock->blocking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $self->_socket($sock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub _close_socket { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close_socket: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ($self->_socket) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | eval { $self->_socket->close() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $self->_socket(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ($self->_socket_path && -e $self->_socket_path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_socket_path and -e $self->_socket_path
MC/DC0%0/2
$self->_socket_path and -e $self->_socket_path
$self->_socket_path
-e $self->_socket_path
Truth table0%0/3
A and B
A= $self->_socket_pathB= -e $self->_socket_path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | unlink $self->_socket_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $self->_socket_path(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | ▶ | sub _send_command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_command: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 6 | my ($self, $cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 6 | ▶ | return unless $self->_socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | eval { $self->_socket->print(encode_json({ command => $cmd }) . "\n") }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 5 | ▶ | $log->warn("IPC send failed: $@") if $@ && $log; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ and $log
MC/DC0%0/2
$@ and $log
$@
$log
Truth table33%1/3
A and B
A= $@B= $log
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | sub _send_command_sync { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_command_sync: called CC=8 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | my ($self, $cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | ▶ | return unless $self->_socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $id = $self->_req_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $self->_req_id($id + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | eval { $self->_socket->print(encode_json({ command => $cmd, request_id => $id }) . "\n") }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $log->warn("IPC send_sync failed: $@") if $log; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $deadline = time() + $IPC_TIMEOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | while (time() < $deadline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # First, see if a matching response is already buffered (e.g. read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # in by an earlier _drain_events / _send_command_sync call). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $resp = $self->_consume_buffered_response($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | return $resp if $resp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $chunk = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $self->_socket->recv($chunk, 65536); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if (defined $chunk && length $chunk) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $chunk and length $chunk
MC/DC0%0/2
defined $chunk and length $chunk
defined $chunk
length $chunk
Truth table0%0/3
A and B
A= defined $chunkB= length $chunk
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->_pending_buf($self->_pending_buf . $chunk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | sleep 0.02; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub _drain_events { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_drain_events: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | return unless $self->_socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $chunk = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $self->_socket->recv($chunk, 65536); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | $self->_pending_buf($self->_pending_buf . $chunk) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $chunk and length $chunk
MC/DC0%0/2
defined $chunk and length $chunk
defined $chunk
length $chunk
Truth table0%0/3
A and B
A= defined $chunkB= length $chunk
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | if defined $chunk && length $chunk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $self->_consume_buffered_response(undef); # process events, discard any | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # stray request responses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # Walk through complete lines in _pending_buf, dispatching events and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # returning the first response whose request_id matches $want_id (undef = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # don't match any; just process events). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub _consume_buffered_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_consume_buffered_response: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my ($self, $want_id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $buf = $self->_pending_buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $matched; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | while ($buf =~ s/^([^\n]+)\n//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $obj = eval { decode_json($1) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | next if !$obj || $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $obj or $@
MC/DC0%0/2
not $obj or $@
not $obj
$@
Truth table0%0/3
not(A) or B
A= not $objB= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ($obj->{event}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $self->_handle_event($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if (defined $want_id && defined $obj->{request_id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $want_id and defined $obj->{"request_id"} and $obj->{"request_id"} == $want_id
defined $want_id and defined $obj->{"request_id"}
MC/DC0%0/3
defined $want_id and defined $obj->{"request_id"} and $obj->{"request_id"} == $want_id
defined $want_id
defined $obj->{"request_id"}
$obj->{"request_id"} == $want_id
Truth table0%0/4
A and B and C
A= defined $want_idB= defined $obj->{"request_id"}C= $obj->{"request_id"} == $want_id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | && $obj->{request_id} == $want_id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $matched = $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $self->_pending_buf($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return $matched; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | ▶ | sub _handle_event { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_event: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 3 | my ($self, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | ▶ | my $event = $obj->{event} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | if ($event eq 'end-file') { $self->_handle_end_file($obj) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | elsif ($event eq 'pause') { $self->_set_state('pause') } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | elsif ($event eq 'unpause') { $self->_set_state('play') } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 4 | ▶ | sub _handle_end_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_end_file: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | my ($self, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 4 | ▶ | my $reason = $obj->{reason} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->{"reason"} // ""
MC/DC0%0/1
$obj->{"reason"} // ""
$obj->{"reason"}
Truth table50%1/2
A
A= $obj->{"reason"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # Only 'eof' (track played to the end) and 'error' (stream died: network | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # glitch, 4xx/5xx from Drive, token expiry mid-stream) should advance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # 'stop' fires for user-initiated stop AND for loadfile-replace pre-empting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # the current track, so advancing on it causes skips/double-advances. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # 'quit' / 'redirect' are housekeeping and should never advance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | ▶ | return unless $reason eq 'eof' || $reason eq 'error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$reason eq "eof" or $reason eq "error"
MC/DC100%2/2
$reason eq "eof" or $reason eq "error"
$reason eq "eof"
$reason eq "error"
Truth table100%3/3
A or B
A= $reason eq "eof"B= $reason eq "error"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | $self->_set_state('stop'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | ▶ | $self->on_track_end->() if $self->has_on_track_end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 19 | ▶ | sub _set_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_state: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 19 | my ($self, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 19 | ▶ | return if $self->_state eq $state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 18 | $self->_state($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 18 | ▶ | $self->on_state_change->($state) if $self->has_on_state_change; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||