line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::TtyRec::Player; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
105940
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
78
|
|
4
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
137
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
36507
|
use Time::HiRes qw(sleep); |
|
2
|
|
|
|
|
4967
|
|
|
2
|
|
|
|
|
12
|
|
8
|
2
|
|
|
2
|
|
1814
|
use Term::TtyRec; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
766
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
2
|
|
|
2
|
1
|
306
|
my($proto, $io, $attr) = @_; |
12
|
2
|
|
33
|
|
|
18
|
my $class = ref $proto || $proto; |
13
|
2
|
50
|
|
|
|
7
|
my %attr = ( speed => 1, nowait => undef, %{$attr || {}} ); # default |
|
2
|
|
|
|
|
27
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
50
|
|
|
|
42
|
unless ($io->can('read')) { |
16
|
0
|
|
|
|
|
0
|
require Carp; |
17
|
0
|
|
|
|
|
0
|
Carp::croak('Usage: Term::TtyRec::Player->new($io)'); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
19
|
bless { ttyrec => Term::TtyRec->new($io), %attr }, $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub play { |
24
|
5
|
|
|
5
|
1
|
4467
|
my $self = shift; |
25
|
5
|
|
|
|
|
75
|
local $| = 1; |
26
|
|
|
|
|
|
|
|
27
|
5
|
|
|
|
|
10
|
my $prev; |
28
|
5
|
|
|
|
|
26
|
while (my($sec, $text) = $self->ttyrec->read_next) { |
29
|
14
|
100
|
|
|
|
77
|
my $wait = ($sec - $prev) / $self->speed if defined $prev; |
30
|
14
|
100
|
66
|
|
|
57
|
unless ($self->nowait or ! $prev) { |
31
|
13
|
|
|
|
|
1513693
|
sleep $wait; |
32
|
|
|
|
|
|
|
} |
33
|
14
|
|
|
|
|
369
|
print $text; |
34
|
14
|
|
|
|
|
1563
|
$prev = $sec; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub skip_all { |
39
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
40
|
1
|
|
|
|
|
6
|
1 while $self->ttyrec->read_next; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub peek { |
44
|
1
|
|
|
1
|
1
|
3905
|
my $self = shift; |
45
|
1
|
|
|
|
|
5
|
$self->skip_all; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
1
|
while (1) { |
48
|
4
|
|
|
|
|
30
|
$self->play; |
49
|
4
|
|
|
|
|
1000058
|
sleep 0.25; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
### accessor |
54
|
|
|
|
|
|
|
for my $attr (qw(ttyrec speed nowait)) { |
55
|
2
|
|
|
2
|
|
15
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
295
|
|
56
|
|
|
|
|
|
|
*{__PACKAGE__. "::$attr"} = sub { |
57
|
61
|
|
|
61
|
|
90
|
my $self = shift; |
58
|
61
|
50
|
|
|
|
186
|
$self->{$attr} = shift if @_; |
59
|
61
|
|
|
|
|
530
|
$self->{$attr}; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |