blib/lib/Net/Partty/Screen.pm

filter: Statementstmt 14.7% 17 / 115 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 16.6% 5 / 30 Podpod 75.0% 18 / 24 totaltotal 16.6% 40 / 241 CC 31 SCAR 39.3
CC
31
Cov
10%
getch
182.0
new
56.0
at
30.0
CRAP 51.1
↑ Summary
1 package Net::Partty::Screen;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Term::Screen';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our $VERSION = '0.01';
7  
8 1 ▶use Net::Partty;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Term::Cap;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
12 0 my($class, %opts) = @_;
13  
14 0 my $self = bless {
15 %opts,
16 IN => '',
17 KEYS => {},
18 ECHO => 1,
19 }, $class;
20  
21 0 ▶ unless ($self->{term}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"term"}) 0 0 0
22 0 my $term = Term::Cap->Tgetent({
23 TERM => 'vt100',
24 OSPEED => 9600,
25 });
26 0 $self->term($term);
27 }
28 0 $self->resize;
29 0 $self->get_fn_keys;
30  
31 0 ▶ $self->{partty} = delete $opts{partty} || Net::Partty->new(%{ $opts{partty_conf} || {} }) unless $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sock"} 0 0 0
Condition0%0/5
delete $opts{'partty'} || 'Net::Partty'->new(%{$opts{'partty_conf'} or {};})
l!l&&r!l&&!r
000
$opts{'partty_conf'} || {}
l!l
00
MC/DC0%0/2
delete $opts{'partty'} || 'Net::Partty'->new(%{$opts{'partty_conf'} or {};})
delete $opts{'partty'} 'Net::Partty'->new(%{$opts{'partty_conf'} or {};})
MC/DC0%0/1
$opts{'partty_conf'} || {}
$opts{'partty_conf'}
Truth table0%0/3
A || B
A= delete $opts{'partty'}B= 'Net::Partty'->new(%{$opts{'partty_conf'} or {};})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $opts{'partty_conf'}
Aresult
11
00
32  
33 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
34 0 eval { require Term::ReadKey; };
35 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
36 0 require Carp;
37 0 Carp::croak $@;
38 }
39  
40 0 $self->at(0, 0);
41 0 Term::ReadKey::ReadMode('raw', \*STDIN);
42 0 $| = 1;
43 }
44  
45 0 $self;
46 }
47  
48 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
49 0 ▶ Term::ReadKey::ReadMode(0, \*STDIN) if shift->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if +(shift())->{"debug"} 0 0 0
50 }
51  
52 0 ▶sub sock { shift->{sock} }
Subroutine sock: not called CC=1 SCAR=6.9
Pod undocumented
53 0 ▶sub partty { shift->{partty} }
Subroutine partty: not called CC=1 SCAR=6.9
Pod undocumented
54 0 ▶sub connect {
Subroutine connect: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my $self = shift;
56 0 $self->{partty}->connect(@_);
57 0 $self->{sock} = $self->partty->sock;
58 0 $self->sock->sb(chr(31), pack('nn', $self->{COLS}, $self->{ROWS}));
59 0 $self->sock->blocking(0);
60 0 $self->at(0, 0);
61 }
62  
63 0 ▶sub esc {
Subroutine esc: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my($self, $fmt, @args) = @_;
65 0 $self->puts(sprintf "%s$fmt", chr(0x1b), @args);
66 }
67  
68 # sub term {}
69 # sub rows {}
70 # sub cols {}
71  
72 0 ▶sub at {
Subroutine at: not called CC=5 SCAR=34.0
Pod documented
73 0 my($self, $rows, $cols) = @_;
74 0 ▶ $rows = 0 if $rows < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rows < 0 0 0 0
75 0 ▶ $cols = 0 if $cols < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cols < 0 0 0 0
76 0 ▶ $rows = $self->{ROWS} - 1 if $rows >= $self->{ROWS};
Branch: 1 branch
BranchTrueFalseTotal
if $rows >= $self->{"ROWS"} 0 0 0
77 0 ▶ $cols = $self->{COLS} - 1 if $cols >= $self->{COLS};
Branch: 1 branch
BranchTrueFalseTotal
if $cols >= $self->{"COLS"} 0 0 0
78 0 $self->esc('[%s;%sH', $rows + 1, $cols + 1);
79 0 $self;
80 }
81  
82 0 ▶sub resize {
Subroutine resize: not called CC=3 SCAR=24.8
Pod documented
83 0 my($self, $rows, $cols) = @_;
84 0 ▶ $self->{ROWS} = $rows || 25;
Condition0%0/2
$rows || 25
l!l
00
MC/DC0%0/1
$rows || 25
$rows
Truth table0%0/2
A
A= $rows
Aresult
11
00
85 0 ▶ $self->{COLS} = $cols || 80;
Condition0%0/2
$cols || 80
l!l
00
MC/DC0%0/1
$cols || 80
$cols
Truth table0%0/2
A
A= $cols
Aresult
11
00
86 0 $self;
87 }
88  
89 0 ▶sub normal { shift->esc('[m') }
Subroutine normal: not called CC=1 SCAR=6.9
Pod documented
90 0 ▶sub bold { shift->esc('[1m') }
Subroutine bold: not called CC=1 SCAR=6.9
Pod documented
91 0 ▶sub reverse { shift->esc('[7m') }
Subroutine reverse: not called CC=1 SCAR=6.9
Pod documented
92 0 ▶sub clrscr { shift->esc('[2J')->at(0, 0) }
Subroutine clrscr: not called CC=1 SCAR=6.9
Pod documented
93 0 ▶sub clreol { shift->esc('[0K') }
Subroutine clreol: not called CC=1 SCAR=6.9
Pod documented
94 0 ▶sub creos { shift->esc('[0J') }
Subroutine creos: not called CC=1 SCAR=6.9
Pod undocumented
95 0 ▶sub il { shift->esc('[L') }
Subroutine il: not called CC=1 SCAR=6.9
Pod documented
96 0 ▶sub dl { shift->esc('[M') }
Subroutine dl: not called CC=1 SCAR=6.9
Pod documented
97  
98 0 ▶sub ic_exists { 0 }
Subroutine ic_exists: not called CC=1 SCAR=6.9
Pod documented
99 0 ▶sub ic { shift }
Subroutine ic: not called CC=1 SCAR=6.9
Pod documented
100 0 ▶sub dc_exists { 0 }
Subroutine dc_exists: not called CC=1 SCAR=6.9
Pod documented
101 0 ▶sub dc { shift }
Subroutine dc: not called CC=1 SCAR=6.9
Pod documented
102  
103 0 ▶sub puts {
Subroutine puts: not called CC=2 SCAR=17.9
Pod documented
104 0 my($self, $data) = @_;
105 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'debug'}) { } 0 0 0
106 0 print $data;
107 } else {
108 0 $self->sock->send($data);
109 0 $self->partty->can_write(100);
110 }
111 0 $self;
112 }
113  
114 0 ▶sub getc {
Subroutine getc: not called CC=2 SCAR=17.9
Pod undocumented
115 0 my $self = shift;
116 0 ▶ return CORE::getc(STDIN) if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
117  
118 0 $self->partty->can_read(100);
119 0 return $self->sock->getc;
120 }
121  
122 0 ▶sub getch {
Subroutine getch: not called CC=13 SCAR=52.0
Pod documented
123 0 my $self = shift;
124 0 my $fn_flag = 0;
125 0 ▶ my $char = $self->{IN} ? chop($self->{IN}) : $self->getc;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'IN'} ? : 0 0 0
126 0 my $partial_fn_str = $char;
127 0 ▶ return unless $char;
Branch: 1 branch
BranchTrueFalseTotal
unless $char 0 0 0
128  
129 0 ▶ while (exists($self->{KEYS}{$partial_fn_str})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"KEYS"}{$partial_fn_str}) 0 0 0
130 0 $fn_flag = 1;
131 0 ▶ if ($self->{KEYS}{$partial_fn_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"KEYS"}{$partial_fn_str}) 0 0 0
132 0 $char = $self->{KEYS}{$partial_fn_str};
133 0 $partial_fn_str = '';
134 0 last;
135 }
136 0 ▶ $partial_fn_str .= $self->{IN} ? chop($self->{IN}) : $self->getc;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'IN'} ? : 0 0 0
137 }
138  
139 0 ▶ if ($fn_flag) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fn_flag) { } 0 0 0
elsif ($self->{'ECHO'} and $char ne "\e") { } 0 0 0
140 0 ▶ if ($partial_fn_str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($partial_fn_str) 0 0 0
141 0 ▶ if ($partial_fn_str eq "\e\e") {
Branch: 1 branch
BranchTrueFalseTotal
if ($partial_fn_str eq "\e\e") { } 0 0 0
142 0 $char = "\e";
143 } else {
144 0 $self->{IN} = CORE::reverse($partial_fn_str) . $self->{IN};
145 0 $char = chop($self->{IN});
146 0 ▶ $self->puts($char) if $self->{ECHO} && $char ne "\e";
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ECHO"} and $char ne "\e" 0 0 0
Condition0%0/3
$self->{"ECHO"} and $char ne "\e"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"ECHO"} and $char ne "\e"
$self->{"ECHO"} $char ne "\e"
Truth table0%0/3
A and B
A= $self->{"ECHO"}B= $char ne "\e"
ABresult
0X0
100
111
147 }
148 }
149 ▶ } elsif ($self->{ECHO} && $char ne "\e") {
Condition0%0/3
$self->{"ECHO"} and $char ne "\e"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"ECHO"} and $char ne "\e"
$self->{"ECHO"} $char ne "\e"
Truth table0%0/3
A and B
A= $self->{"ECHO"}B= $char ne "\e"
ABresult
0X0
100
111
150 0 $self->puts($char);
151 }
152 0 $char;
153 }
154  
155 # sub def_key {}
156  
157 0 ▶sub key_pressed {
Subroutine key_pressed: not called CC=3 SCAR=24.8
Pod documented
158 0 my($self, $wait) = @_;
159 0 my $fds = '';
160 0 my $ready = 0;
161  
162 0 ▶ my $fno = $self->{debug} ? fileno(STDIN) : fileno($self->sock);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'debug'} ? : 0 0 0
163 0 ▶ $wait = 0 unless defined $wait;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wait 0 0 0
164  
165 0 vec($fds, $fno, 1) = 1;
166 0 eval {
167 0 $ready = select($fds, undef, undef, $wait);
168 };
169 0 $ready;
170 }
171  
172 # sub echo {}
173 # sub noecho {}
174  
175 0 ▶sub flush_input {
Subroutine flush_input: not called CC=2 SCAR=17.9
Pod documented
176 0 my $self = shift;
177 0 $self->{IN} = '';
178 0 ▶ while ($self->key_pressed) { $self->getc }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->key_pressed) 0 0 0
179 0 $self;
180 }
181  
182  
183 # sub stuff_input {}
184 # sub get_fn_keys {}
185  
186 1 1;
187 __END__
↑ Summary