Console/Dump.pm

filter: Statementstmt 79.0% 68 / 86 Branchbran 57.6% 15 / 26 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 12 / 20 Podpod 85.7% 12 / 14 totaltotal 71.5% 108 / 151 CC 15 SCAR 11.6
CC
15
Cov
73%
refresh
6.3
addstr
6.3
init
3.0
CRAP 3.2
« Utils.pm ↑ Summary Console/Curses.pm »
1 package Games::Roguelike::Console::Dump;
2
3 =head1 NAME
4
5 Games::Roguelike::Console::Dump - fake console that dumps to file, for testing
6
7 =head1 SYNOPSIS
8
9 use Games::Roguelike::Console::Dump;
10
11 $con = Games::Roguelike::Console::Dump->new(keys=>'qY', file=>'/dev/null');
12
13 =head1 DESCRIPTION
14
15 Fake console that dumps screens to file, used for testing game scripts without needing "curses" support.
16
17 Notably, the new function takes a keystroke string and a file as arguments.
18
19 Inherits from Games::Roguelike::Console. See Games::Roguelike::Console for list of methods.
20
21 =head1 SEE ALSO
22
23 L<Games::Roguelike::Console>
24
25 =cut
26
27 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use Carp qw(cluck croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use Games::Roguelike::Utils qw(:DEFAULT);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use base 'Games::Roguelike::Console';
Subroutine BEGIN: called CC=1 SCAR=0.0
32
33 5 our $VERSION = '0.4.' . [qw$Revision: 233 $]->[1];
34
35 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
36 3 my $pkg = shift;
37 3 ▶ croak "usage: Games::Roguelike::Console::Dump->new()" unless $pkg;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg 0 3 3
38
39 3 my $self = bless {}, $pkg;
40 3 $self->init(@_);
41 3 return $self;
42 }
43
44 5 my $STD;
45 3 ▶sub init {
Subroutine init: called CC=3 SCAR=11.1
Pod undocumented
46 3 my $self = shift;
47
48 3 my %opt = @_;
49
50 3 ▶ if ($opt{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"file"}) 3 0 3
51 3 $self->{file} = $opt{file};
52 3 $opt{out} = new IO::File;
53 3 open($opt{out}, ">" . $opt{file});
54 }
55
56 $self->{out} = *STDOUT{IO}
57 3 ▶ unless $self->{out} = $opt{out};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"out"} = $opt{"out"} 0 3 3
58
59 3 $self->{out}->autoflush(1);
60
61 3 $self->{buf} = [];
62 3 $self->{cbuf} = $opt{keys};
63 }
64
65 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.1
66 2 my $self = shift;
67 2 ▶ if ($self->{out}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"out"}) 2 0 2
68 2 close $self->{out};
69 }
70 }
71
72
73 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $self = shift;
75 0 my $out = $self->{out};
76 0 print $out ("******************\n"); #clear the screen
77 }
78
79 0 ▶sub redraw {
Subroutine redraw: not called CC=1 SCAR=0.0
Pod documented
80 }
81
82 0 ▶sub attron {
Subroutine attron: not called CC=1 SCAR=0.0
Pod documented
83 }
84
85 0 ▶sub attroff {
Subroutine attroff: not called CC=1 SCAR=0.0
Pod documented
86 }
87
88 2163 ▶sub addstr {
Subroutine addstr: called CC=5 SCAR=18.3
Pod documented
89 2163 my $self = shift;
90 2163 my $str = pop @_;
91 2163 ▶ if (@_== 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 0 2163 2163
elsif (@_ == 2) { } 2163 0 2163
92 0 ▶ for (my $i = 0; $i < length($str); ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $str) 0 0 0
93 0 $self->{buf}->[$self->{cy}][$self->{cx}+$i] = substr($str,$i,1);
94 }
95 0 $self->{cx} += length($str);
96 } elsif (@_==2) {
97 2163 my ($y, $x) = @_;
98 2163 ▶ for (my $i = 0; $i < length($str); ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $str) 2163 2163 4326
99 2163 $self->{buf}->[$y][$x+$i] = substr($str,$i,1);
100 }
101 2163 $self->{cy}=$y;
102 2163 $self->{cx}=$x+length($str);
103 }
104 }
105
106 0 ▶sub tagstr {
Subroutine tagstr: not called CC=1 SCAR=6.9
Pod documented
107 0 my $self = shift;
108 0 my $str = pop @_;
109 0 $str =~ s/<[^>]+>//g;
110 0 $self->addstr(@_, $str);
111 }
112
113
114 3 ▶sub refresh {
Subroutine refresh: called CC=6 SCAR=18.4
Pod documented
115 3 my $self = shift;
116 3 my $out = $self->{out};
117
118 3 my $cc = 0;
119
120 3 ▶ for (my $y = 0; $y <= @{$self->{buf}}; ++$y) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y <= @{$self->{"buf"};}) 60 3 63
121 60 ▶ next if !$self->{buf}->[$y];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"buf"}[$y] 6 54 60
122 0 ▶ next if $self->{cur}->[$y] && (join('',@{$self->{buf}->[$y]}) eq join('',@{$self->{cur}->[$y]}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cur"}[$y] and join("", @{$self->{"buf"}[$y];}) eq join("", @{$self->{"cur"}[$y];}) 0 54 54
Condition33%1/3
$self->{"cur"}[$y] and join("", @{$self->{"buf"}[$y];}) eq join("", @{$self->{"cur"}[$y];})
!ll&&!rl&&r
5400
MC/DC0%0/2
$self->{"cur"}[$y] and join("", @{$self->{"buf"}[$y];}) eq join("", @{$self->{"cur"}[$y];})
$self->{"cur"}[$y] join("", @{$self->{"buf"}[$y];}) eq join("", @{$self->{"cur"}[$y];})
Truth table33%1/3
A and B
A= $self->{"cur"}[$y]B= join("", @{$self->{"buf"}[$y];}) eq join("", @{$self->{"cur"}[$y];})
ABresult
0X0
100
111
123 54 print $out sprintf("%03d|", $y), @{$self->{buf}->[$y]}, "\n";
124 54 @{$self->{cur}->[$y]} = @{$self->{buf}->[$y]};
125 54 ++$cc;
126 }
127
128 3 ++$self->{refrc};
129
130 3 ▶ return unless $cc > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $cc > 0 0 3 3
131
132 3 print $out "\n<*" . $self->{refrc} . ">\n";
133 }
134
135 0 ▶sub move {
Subroutine move: not called CC=1 SCAR=6.9
Pod documented
136 0 my $self = shift;
137 0 my ($y, $x) = @_;
138 0 $self->{cy}=$y;
139 0 $self->{cx}=$x;
140 }
141
142 0 ▶sub cursor {
Subroutine cursor: not called CC=1 SCAR=0.0
Pod documented
143 }
144
145 2163 ▶sub addch {
Subroutine addch: called CC=1 SCAR=0.0
Pod documented
146 2163 my $self = shift;
147 2163 $self->addstr(@_);
148 }
149
150 3 ▶sub getch {
Subroutine getch: called CC=2 SCAR=7.0
Pod documented
151 3 my $self = shift;
152
153 3 my $c;
154 3 ▶ if ($self->{cbuf}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cbuf"}) 3 0 3
155 3 $c = substr($self->{cbuf},0,1);
156 3 $self->{cbuf} = substr($self->{cbuf},1);
157 }
158
159 3 return $c;
160 }
161
162 0 ▶sub nbgetch {
Subroutine nbgetch: not called CC=1 SCAR=6.9
Pod documented
163 0 my $self = shift;
164 0 return $self->getch();
165 }
166
167 5 1;
« Utils.pm ↑ Summary Console/Curses.pm »