Xmpcr/Network.pm

filter: Statementstmt 9.6% 8 / 83 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 14.2% 2 / 14 Podpod 0.0% 0 / 10 totaltotal 5.9% 10 / 168 CC 29 SCAR 31.7
CC
29
Cov
6%
_doop
56.0
_hashifySongEntry
42.0
new
20.0
CRAP 23.9
« Xmpcr/Serial.pm ↑ Summary Xmpcr.pm »
1 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2 # Audio::Xmpcr::Network
3 # Copyright Paul Bournival 2003
4 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 package Audio::Xmpcr::Network;
7  
8 1 $VERSION="1.02";
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
14 0 my($class,$host,$port,$locker)=@_;
15 0 ▶ $port ||= 32463;
Condition0%0/2
$port ||= 32463
l!l
00
MC/DC0%0/1
$port ||= 32463
$port
Truth table0%0/2
A
A= $port
Aresult
11
00
16 0 my $self={};
17  
18 0 ▶ $self->{s}=new IO::Socket::INET(PeerAddr => "$host:$port")
Branch: 1 branch
BranchTrueFalseTotal
$self->{"s"} = "IO::Socket::INET"->new("PeerAddr", "${host}:$port") or die "Can't contact xmdaemon: $!!\n" 0 0 0
19 or die "Can't contact xmdaemon: $!!\n";
20 0 bless $self,$class;
21  
22 0 ▶ $self->_doop("appname $locker") if $locker;
Branch: 1 branch
BranchTrueFalseTotal
if $locker 0 0 0
23  
24 0 $self->{queuedEvents}=[];
25 0 $self;
26 }
27  
28 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
29 # turn on/off power
30 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
31 0 ▶sub power {
Subroutine power: not called CC=3 SCAR=24.8
Pod undocumented
32 0 my($self,$status)=@_;
33 0 ▶ die "Xmpcr::power: incorrect parameters" if ! $status;
Branch: 1 branch
BranchTrueFalseTotal
unless $status 0 0 0
34 0 my @ret=$self->_doop($status);
35 0 ▶ scalar(@ret)==0 ? undef : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret == 0 ? : 0 0 0
36 }
37  
38 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
39 # turn on/off mute
40 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
41 0 ▶sub mute {
Subroutine mute: not called CC=3 SCAR=24.8
Pod undocumented
42 0 my($self,$status)=@_;
43 0 ▶ die "Xmpcr::mute: incorrect parameters" if ! $status;
Branch: 1 branch
BranchTrueFalseTotal
unless $status 0 0 0
44 0 my @ret=$self->_doop("mute $status");
45 0 ▶ scalar(@ret)==0 ? undef : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret == 0 ? : 0 0 0
46 }
47  
48 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
49 # change channel
50 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
51 0 ▶sub setchannel {
Subroutine setchannel: not called CC=3 SCAR=24.8
Pod undocumented
52 0 my($self,$chan)=@_;
53 0 ▶ die "Xmpcr::setchannel: incorrect parameters" if ! $chan;
Branch: 1 branch
BranchTrueFalseTotal
unless $chan 0 0 0
54 0 my @ret=$self->_doop("channel $chan");
55 0 ▶ scalar(@ret)==0 ? undef : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret == 0 ? : 0 0 0
56 }
57  
58 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
59 # force the lock
60 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
61 0 ▶sub forcelock {
Subroutine forcelock: not called CC=2 SCAR=17.9
Pod undocumented
62 0 my($self)=@_;
63 0 my @ret=$self->_doop("forcelock");
64 0 ▶ scalar(@ret)==0 ? undef : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret == 0 ? : 0 0 0
65 }
66  
67 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
68 # list 1 or all channels
69 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
70 0 ▶sub list {
Subroutine list: not called CC=4 SCAR=30.0
Pod undocumented
71 0 my($self,$chan)=@_;
72 0 ▶ my @list=$self->_doop("list" . ($chan ? " $chan" : ""));
Branch: 1 branch
BranchTrueFalseTotal
$chan ? : 0 0 0
73 0 my @ret;
74 0 for my $line (@list) {
75 0 push(@ret,$self->_hashifySongEntry($line));
76 }
77 0 ▶ $chan ? $ret[0] : @ret;
Branch: 1 branch
BranchTrueFalseTotal
$chan ? : 0 0 0
78 }
79  
80 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
81 # splits a tab-delimited entry into a hash
82 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
83 0 ▶sub _hashifySongEntry {
Subroutine _hashifySongEntry: not called CC=6 SCAR=37.4
84 0 my($self,$line)=@_;
85 0 my(@e)=split("\t",$line);
86 {
87 0 ▶ NUM => $e[0] || 0,
Condition0%0/10
$e[0] || 0
l!l
00
$e[1] || ''
l!l
00
$e[2] || ''
l!l
00
$e[3] || ''
l!l
00
$e[4] || ''
l!l
00
MC/DC0%0/1
$e[0] || 0
$e[0]
MC/DC0%0/1
$e[1] || ''
$e[1]
MC/DC0%0/1
$e[2] || ''
$e[2]
MC/DC0%0/1
$e[3] || ''
$e[3]
MC/DC0%0/1
$e[4] || ''
$e[4]
Truth table0%0/2
A
A= $e[0]
Aresult
11
00
Truth table0%0/2
A
A= $e[1]
Aresult
11
00
Truth table0%0/2
A
A= $e[2]
Aresult
11
00
Truth table0%0/2
A
A= $e[3]
Aresult
11
00
Truth table0%0/2
A
A= $e[4]
Aresult
11
00
88 NAME => $e[1] || "",
89 CAT => $e[2] || "",
90 SONG => $e[3] || "",
91 ARTIST => $e[4] || "",
92 };
93 }
94  
95 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
96 # obtain general radio status
97 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
98 0 ▶sub status {
Subroutine status: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my($self)=@_;
100 0 my %ret;
101 map {
102 0 my($k,$v)=split("\t",$_);
103 0 $ret{$k}=$v;
104 } $self->_doop("status");
105 0 %ret;
106 }
107  
108 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
109 # event support (i.e., song changing)
110 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
111 0 ▶sub events {
Subroutine events: not called CC=3 SCAR=24.8
Pod undocumented
112 0 my($self,$status)=@_;
113 0 ▶ die "Xmpcr::mute: incorrect parameters" if ! $status;
Branch: 1 branch
BranchTrueFalseTotal
unless $status 0 0 0
114 0 my @ret=$self->_doop("events $status");
115 0 ▶ scalar(@ret)==0 ? undef : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret == 0 ? : 0 0 0
116 }
117  
118 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
119 # find out which channels have changed songs
120 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
121 0 ▶sub processEvents {
Subroutine processEvents: not called CC=3 SCAR=24.8
Pod undocumented
122 0 my($self)=@_;
123 0 my($rin,$buf)="";
124 0 my @events=@{ $self->{queuedEvents} };
125 0 $self->{queuedEvents}=[];
126 0 vec($rin,fileno($self->{s}),1)=1;
127 0 ▶ if (select($rin,undef,undef,.05)) {
Branch: 1 branch
BranchTrueFalseTotal
if (select $rin, undef, undef, "0.05") 0 0 0
128 0 sysread($self->{s},$buf,16000);
129 0 ▶ if ($buf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf) 0 0 0
130 map {
131 0 s/^\+\t//;
132 0 push(@events,$_);
133 } split("\n",$buf);
134 }
135 }
136 map {
137 0 $_=$self->_hashifySongEntry($_);
138 } @events;
139 0 @events;
140 }
141 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
142 # return the server socket FD for select() calls
143 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
144 0 ▶sub eventFd {
Subroutine eventFd: not called CC=1 SCAR=6.9
Pod undocumented
145 0 my($self)=@_;
146 0 return fileno($self->{s});
147 }
148  
149 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
150 # a general send/receive method.
151 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
152 0 ▶sub _doop {
Subroutine _doop: not called CC=7 SCAR=40.3
153 0 my($self,$cmd)=@_;
154 0 my($ret,@ret)=("");
155 0 ▶ syswrite($self->{s},$cmd . "\n") if $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd 0 0 0
156  
157 0 my($rin,$rout)="";
158 0 vec($rin,fileno($self->{s}),1)=1;
159 0 while(1) {
160 0 my $buf;
161 0 sysread($self->{s},$buf,1024);
162 0 $ret .= $buf;
163 0 ▶ last if ! $buf or $ret =~ /Ready\n$/;
Branch: 1 branch
BranchTrueFalseTotal
if not $buf or $ret =~ /Ready\n$/ 0 0 0
Condition0%0/3
not $buf or $ret =~ /Ready\n$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $buf or $ret =~ /Ready\n$/
not $buf $ret =~ /Ready\n$/
Truth table0%0/3
not(A) or B
A= not $bufB= $ret =~ /Ready\n$/
ABresult
1X1
011
000
164 }
165 0 for my $line (split("\n",$ret)) {
166 0 ▶ if ($line =~ /^\+/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\+/) { } 0 0 0
elsif ($line eq 'Ready') { } 0 0 0
167 0 push(@{ $self->{queuedEvents} },$line) ;
168 } elsif ($line eq "Ready") {
169 } else {
170 0 push(@ret,$line);
171 }
172 }
173 0 @ret;
174 }
175  
176 1 1;
« Xmpcr/Serial.pm ↑ Summary Xmpcr.pm »