| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 17 | 0 | my %params = @_; | |||||||||||||||||||
| 18 | 0 | ▶ | croak "No name for Client: $!" unless($params{name}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | 0 | my $self = {}; | |||||||||||||||||||
| 20 | 0 | $self->{name} = $params{name}; | |||||||||||||||||||
| 21 | 0 | ▶ | $self->{host} = $params{host} || "localhost"; | ||||||||||||||||||
|
Condition0%0/2
$params{'host'} || 'localhost'
MC/DC0%0/1
$params{'host'} || 'localhost'
$params{'host'}
Truth table0%0/2
A
A= $params{'host'}
| |||||||||||||||||||||
| 22 | 0 | ▶ | $self->{port} = $params{port} || "13666"; | ||||||||||||||||||
|
Condition0%0/2
$params{'port'} || '13666'
MC/DC0%0/1
$params{'port'} || '13666'
$params{'port'}
Truth table0%0/2
A
A= $params{'port'}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 94 | 0 | my %params = @_; | |||||||||||||||||||
| 95 | 0 | ▶ | croak "No name for Screen: $!" unless($params{name}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 0 | my $self = {}; | |||||||||||||||||||
| 97 | 0 | $self->{name} = $params{name}; | |||||||||||||||||||
| 98 | 0 | ▶ | $self->{heartbeat} = $params{heartbeat} || "on"; | ||||||||||||||||||
|
Condition0%0/2
$params{'heartbeat'} || 'on'
MC/DC0%0/1
$params{'heartbeat'} || 'on'
$params{'heartbeat'}
Truth table0%0/2
A
A= $params{'heartbeat'}
| |||||||||||||||||||||
| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 131 | 0 | my %params = @_; | |||||||||||||||||||
| 132 | 0 | ▶ | croak "No name for Widget: $!" unless($params{name}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 0 | my $self = {}; | |||||||||||||||||||
| 134 | 0 | $self->{name} = $params{name}; | |||||||||||||||||||
| 135 | 0 | ▶ | $self->{align} = $params{align} || "left"; | ||||||||||||||||||
|
Condition0%0/2
$params{'align'} || 'left'
MC/DC0%0/1
$params{'align'} || 'left'
$params{'align'}
Truth table0%0/2
A
A= $params{'align'}
| |||||||||||||||||||||
| 136 | 0 | ▶ | $self->{type} = $params{type} || "string"; | ||||||||||||||||||
|
Condition0%0/2
$params{'type'} || 'string'
MC/DC0%0/1
$params{'type'} || 'string'
$params{'type'}
Truth table0%0/2
A
A= $params{'type'}
| |||||||||||||||||||||
| 137 | 0 | ▶ | $self->{xPos} = $params{xPos} || ""; | ||||||||||||||||||
|
Condition0%0/2
$params{'xPos'} || ''
MC/DC0%0/1
$params{'xPos'} || ''
$params{'xPos'}
Truth table0%0/2
A
A= $params{'xPos'}
| |||||||||||||||||||||
| 138 | 0 | ▶ | $self->{yPos} = $params{yPos} || ""; | ||||||||||||||||||
|
Condition0%0/2
$params{'yPos'} || ''
MC/DC0%0/1
$params{'yPos'} || ''
$params{'yPos'}
Truth table0%0/2
A
A= $params{'yPos'}
| |||||||||||||||||||||
| 139 | 0 | ▶ | $self->{data} = $params{data} if( $params{data} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 148 | 0 | ▶ | $self->{yPos} = $params{yPos} if($params{yPos}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 149 | 0 | ▶ | $self->{data} = $params{data} if($params{data}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | 0 | ▶ | $self->{data} = " " x $self->{screen}{client}{width} if(length( $self->{data} ) < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||