| 1 | package Game::Terminal::Kit::Test::Screen; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 7 | ▶ | use 5.014; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 7 | ▶ | use Exporter 'import'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 7 | ▶ | use Game::Terminal::Kit::Keys; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 7 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 7 | our $VERSION = '0.02'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 7 | our @EXPORT_OK = qw/keysource capture typed kit within/; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 28 | ▶ | sub keysource { | ||||||||||||||||||
|
Subroutine
keysource: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 16 | 28 | my ($bytes) = @_; | |||||||||||||||||||
| 17 | 28 | ▶ | my @chars = split //, defined $bytes ? $bytes : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | 28 | ▶ | return sub { return shift @chars }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 28 | ▶ | sub capture { | ||||||||||||||||||
|
Subroutine
capture: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 22 | 28 | my $text = ''; | |||||||||||||||||||
| 23 | 28 | ▶ | open my $out, '>', \$text or die "cannot open the screen: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 28 | return ($out, \$text); | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 28 | ▶ | sub typed { | ||||||||||||||||||
|
Subroutine
typed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 28 | 28 | my (@lines) = @_; | |||||||||||||||||||
| 29 | 28 | ▶ | my $script = join '', map { m/\n\z/ ? $_ : "$_\n" } @lines; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 28 | ▶ | open my $in, '<', \$script or die "cannot read the script: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 28 | return $in; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 27 | ▶ | sub kit { | ||||||||||||||||||
|
Subroutine
kit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 35 | 27 | my (%option) = @_; | |||||||||||||||||||
| 36 | 27 | my $bytes = delete $option{keys}; | |||||||||||||||||||
| 37 | 27 | my $lines = delete $option{typed}; | |||||||||||||||||||
| 38 | 27 | my ($out, $text) = capture(); | |||||||||||||||||||
| 39 | my $keys = Game::Terminal::Kit::Keys->new( | ||||||||||||||||||||
| 40 | 27 | ▶ | in => typed(@{ $lines || [] }), | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$lines || []
MC/DC100%1/1
$lines || []
$lines
Truth table100%2/2
A
A= $lines
| |||||||||||||||||||||
| 41 | (defined $bytes ? (keysource => keysource($bytes)) : ()), | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | 27 | my $screen = Game::Terminal::Kit::Screen->new( | |||||||||||||||||||
| 44 | out => $out, | ||||||||||||||||||||
| 45 | interactive => 0, | ||||||||||||||||||||
| 46 | colour => 0, | ||||||||||||||||||||
| 47 | ascii => 1, | ||||||||||||||||||||
| 48 | %option, | ||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||
| 50 | 27 | return ($keys, $screen, $text); | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 8 | ▶ | sub within { | ||||||||||||||||||
|
Subroutine
within: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 54 | 8 | my ($seconds, $body) = @_; | |||||||||||||||||||
| 55 | 8 | my $late = "it did not end in $seconds seconds\n"; | |||||||||||||||||||
| 56 | 8 | my @result; | |||||||||||||||||||
| 57 | 8 | my $lived = eval { | |||||||||||||||||||
| 58 | 8 | ▶ | local $SIG{ALRM} = sub { die $late }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 59 | 8 | alarm $seconds; | |||||||||||||||||||
| 60 | 8 | @result = $body->(); | |||||||||||||||||||
| 61 | 6 | alarm 0; | |||||||||||||||||||
| 62 | 6 | 1; | |||||||||||||||||||
| 63 | }; | ||||||||||||||||||||
| 64 | 8 | my $died = $@; | |||||||||||||||||||
| 65 | 8 | eval { alarm 0 }; | |||||||||||||||||||
| 66 | 8 | ▶ | return wantarray ? @result : $result[0] if $lived; | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 67 | 2 | ▶ | die $died unless $died eq $late; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 1 | require Test::Builder; | |||||||||||||||||||
| 69 | 1 | Test::Builder->new->ok(0, "ended within $seconds seconds"); | |||||||||||||||||||
| 70 | 1 | return; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 7 | 1; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||