blib/lib/IO/LCDproc.pm

filter: Statementstmt 20.0% 25 / 125 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 30.4% 7 / 23 Podpod n/a totaltotal 15.2% 32 / 210 CC 26 SCAR 32.9
CC
26
Cov
14%
new
72.0
set
56.0
new
30.0
CRAP 26.9
↑ Summary
1 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 1 our $VERSION = '0.037';
4 package IO::LCDproc;
5  
6 ###############################################################################
7 package IO::LCDproc::Client;
8 1 @IO::LCDproc::Client::ISA = qw(IO::LCDproc);
9  
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
15 0 my $proto = shift;
16 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
17 0 my %params = @_;
18 0 ▶ croak "No name for Client: $!" unless($params{name});
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 0 0 0
19 0 my $self = {};
20 0 $self->{name} = $params{name};
21 0 ▶ $self->{host} = $params{host} || "localhost";
Condition0%0/2
$params{'host'} || 'localhost'
l!l
00
MC/DC0%0/1
$params{'host'} || 'localhost'
$params{'host'}
Truth table0%0/2
A
A= $params{'host'}
Aresult
11
00
22 0 ▶ $self->{port} = $params{port} || "13666";
Condition0%0/2
$params{'port'} || '13666'
l!l
00
MC/DC0%0/1
$params{'port'} || '13666'
$params{'port'}
Truth table0%0/2
A
A= $params{'port'}
Aresult
11
00
23 0 $self->{cmd} = "client_set name {$self->{name}}\n";
24 0 $self->{screen} = undef;
25 0 bless ($self, $class);
26 0 return $self;
27 }
28  
29 0 ▶sub add {
Subroutine add: not called CC=1 SCAR=6.9
30 0 my $self = shift;
31 0 $self->{screen} = shift;
32 0 $self->{screen}{client} = $self;
33 0 $self->{screen}{set} = "screen_set $self->{screen}{name} name {$self->{screen}{name}}\n";
34 0 $self->{screen}{set}.= "screen_set $self->{screen}{name} heartbeat $self->{screen}{heartbeat}\n";
35 }
36  
37 0 ▶sub connect {
Subroutine connect: not called CC=2 SCAR=17.9
38 0 my $self = shift;
39 0 ▶ $self->{lcd} = IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->{"lcd"} = "IO::Socket::INET"->new("Proto", "tcp", "PeerAddr", qq[$self->{"host"}], "PeerPort", qq[$self->{"port"}]) or croak("Cannot connect to LCDproc port: $!") 0 0 0
40 Proto => "tcp", PeerAddr => "$self->{host}", PeerPort => "$self->{port}"
41 ) or croak "Cannot connect to LCDproc port: $!";
42 0 $self->{lcd}->autoflush();
43 0 sleep 1;
44 }
45  
46 0 ▶sub initialize {
Subroutine initialize: not called CC=3 SCAR=24.8
47 0 my $self = shift;
48 0 my $fh = $self->{lcd};
49 0 my $msgs;
50 0 print $fh "hello\n";
51 0 $msgs = <$fh>;
52 0 ▶ if($msgs =~ /lcd.+wid\s+(\d+)\s+hgt\s+(\d+)\s+cellwid\s+(\d+)\s+cellhgt\s+(\d+)/){
Branch: 1 branch
BranchTrueFalseTotal
if ($msgs =~ /lcd.+wid\s+(\d+)\s+hgt\s+(\d+)\s+cellwid\s+(\d+)\s+cellhgt\s+(\d+)/) { } 0 0 0
53 0 $self->{width} = $1;
54 0 $self->{height} = $2;
55 0 $self->{cellwidth} = $3;
56 0 $self->{cellheight} = $4;
57 } else {
58 0 croak "No stats reported...: $!";
59 }
60 0 fcntl( $fh, F_SETFL, O_NONBLOCK );
61  
62 0 print $fh $self->{cmd};
63 0 print $fh $self->{screen}{cmd};
64 0 print $fh $self->{screen}{set};
65 0 foreach(@{$self->{screen}{widgets}}){
66 0 print $fh $_->{cmd};
67 }
68 }
69  
70 0 ▶sub answer {
Subroutine answer: not called CC=1 SCAR=6.9
71 0 my $self = shift;
72 0 my $fh = $self->{lcd};
73 0 my $answ;
74 0 $answ = <$fh>;
75  
76 0 return $answ;
77 }
78  
79 0 ▶sub flushAnswers {
Subroutine flushAnswers: not called CC=2 SCAR=17.9
80 0 my $self = shift;
81 0 ▶ while ($self->answer()) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->answer) 0 0 0
82 }
83  
84  
85 ###############################################################################
86 package IO::LCDproc::Screen;
87 1 @IO::LCDproc::Screen::ISA = qw(IO::LCDproc);
88  
89 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
92 0 my $proto = shift;
93 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
94 0 my %params = @_;
95 0 ▶ croak "No name for Screen: $!" unless($params{name});
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 0 0 0
96 0 my $self = {};
97 0 $self->{name} = $params{name};
98 0 ▶ $self->{heartbeat} = $params{heartbeat} || "on";
Condition0%0/2
$params{'heartbeat'} || 'on'
l!l
00
MC/DC0%0/1
$params{'heartbeat'} || 'on'
$params{'heartbeat'}
Truth table0%0/2
A
A= $params{'heartbeat'}
Aresult
11
00
99 0 $self->{cmd} = "screen_add $self->{name}\n";
100 0 $self->{widgets} = undef;
101 0 bless ($self, $class);
102 0 return $self;
103 }
104  
105 0 ▶sub add {
Subroutine add: not called CC=2 SCAR=17.9
106 0 my $self = shift;
107 0 foreach (@_){
108 0 push @{$self->{widgets}}, $_;
109 0 $_->{screen}=$self;
110 0 $_->{cmd} = "widget_add $_->{screen}{name} $_->{name} $_->{type}\n";
111 }
112 }
113  
114 0 ▶sub set_prio {
Subroutine set_prio: not called CC=1 SCAR=6.9
115 0 my $self = shift;
116 0 my $prio = shift;
117 0 my $fh = $self->{client}->{lcd};
118 0 print $fh "screen_set $self->{name} -priority $prio\n";
119 }
120  
121 ###############################################################################
122 package IO::LCDproc::Widget;
123 1 @IO::LCDproc::Client::ISA = qw(IO::LCDproc);
124  
125 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 1 ▶use overload '++' => \&xIncrement;
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
129 0 my $proto = shift;
130 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
131 0 my %params = @_;
132 0 ▶ croak "No name for Widget: $!" unless($params{name});
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 0 0 0
133 0 my $self = {};
134 0 $self->{name} = $params{name};
135 0 ▶ $self->{align} = $params{align} || "left";
Condition0%0/2
$params{'align'} || 'left'
l!l
00
MC/DC0%0/1
$params{'align'} || 'left'
$params{'align'}
Truth table0%0/2
A
A= $params{'align'}
Aresult
11
00
136 0 ▶ $self->{type} = $params{type} || "string";
Condition0%0/2
$params{'type'} || 'string'
l!l
00
MC/DC0%0/1
$params{'type'} || 'string'
$params{'type'}
Truth table0%0/2
A
A= $params{'type'}
Aresult
11
00
137 0 ▶ $self->{xPos} = $params{xPos} || "";
Condition0%0/2
$params{'xPos'} || ''
l!l
00
MC/DC0%0/1
$params{'xPos'} || ''
$params{'xPos'}
Truth table0%0/2
A
A= $params{'xPos'}
Aresult
11
00
138 0 ▶ $self->{yPos} = $params{yPos} || "";
Condition0%0/2
$params{'yPos'} || ''
l!l
00
MC/DC0%0/1
$params{'yPos'} || ''
$params{'yPos'}
Truth table0%0/2
A
A= $params{'yPos'}
Aresult
11
00
139 0 ▶ $self->{data} = $params{data} if( $params{data} );
Branch: 1 branch
BranchTrueFalseTotal
if $params{"data"} 0 0 0
140 0 bless ($self, $class);
141 0 return $self;
142 }
143  
144 0 ▶sub set {
Subroutine set: not called CC=7 SCAR=40.3
145 0 my $self = shift;
146 0 my %params = @_;
147 0 ▶ $self->{xPos} = $params{xPos} if($params{xPos});
Branch: 1 branch
BranchTrueFalseTotal
if $params{"xPos"} 0 0 0
148 0 ▶ $self->{yPos} = $params{yPos} if($params{yPos});
Branch: 1 branch
BranchTrueFalseTotal
if $params{"yPos"} 0 0 0
149 0 ▶ $self->{data} = $params{data} if($params{data});
Branch: 1 branch
BranchTrueFalseTotal
if $params{"data"} 0 0 0
150 0 ▶ $self->{data} = " " x $self->{screen}{client}{width} if(length( $self->{data} ) < 1 );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"data"} < 1 0 0 0
151 0 my $fh = $self->{screen}->{client}->{lcd};
152 print $fh "widget_set $self->{screen}->{name} $self->{name} $self->{xPos} $self->{yPos} {" .
153 ($self->{align} =~ /center/ ? $self->_center($self->{data}) :
154 ($self->{align} =~ /right/ ? $self->_right($self->{data}) : $self->{data})
155 0 ▶ ) . "}\n";
Branch: 2 branches
BranchTrueFalseTotal
$self->{'align'} =~ /center/ ? : 0 0 0
$self->{'align'} =~ /right/ ? : 0 0 0
156 }
157  
158 0 ▶sub _center {
Subroutine _center: not called CC=1 SCAR=6.9
159 0 my $self = shift;
160 0 return(" " x (($self->{screen}{client}{width} - length($_[0]))/2) . $_[0]);
161 }
162  
163 0 ▶sub _right {
Subroutine _right: not called CC=1 SCAR=6.9
164 0 my $self = shift;
165 0 return(" " x (($self->{screen}{client}{width} - length($_[0]))) . $_[0]);
166 }
167  
168 0 ▶sub save {
Subroutine save: not called CC=1 SCAR=6.9
169 0 my $self = shift;
170 0 $self->{saved} = $self->{data};
171 }
172  
173 0 ▶sub restore {
Subroutine restore: not called CC=1 SCAR=6.9
174 0 my $self = shift;
175 0 $self->{data} = $self->{saved};
176 0 $self->{saved} = "";
177 0 $self->set;
178 }
179  
180 0 ▶sub xIncrement {
Subroutine xIncrement: not called CC=1 SCAR=6.9
181 0 my $self = shift;
182 0 $self->{xPos}++
183 }
184  
185 1 1;
186  
187 __END__
↑ Summary