blib/lib/Speech/Speakup.pm

filter: Statementstmt 20.9% 23 / 110 Branchbran 7.5% 3 / 40 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 4 / 16 Podpod 33.3% 4 / 12 totaltotal 17.3% 34 / 196 CC 25 SCAR 31.7
CC
25
Cov
16%
get
56.0
set
42.0
synthdir
20.0
CRAP 23.8
↑ Summary
1 # Speakup::Speakup.pm
2 #########################################################################
3 # This Perl module is Copyright (c) 2002, Peter J Billam #
4 # c/o P J B Computing, www.pjb.com.au #
5 # #
6 # This module is free software; you can redistribute it and/or #
7 # modify it under the same terms as Perl itself. #
8 #########################################################################
9  
10 package Speech::Speakup;
11 1 $VERSION = '1.05'; #
12 1 my $stupid_bloody_warning = $VERSION; # circumvent -w warning
13 1 require Exporter;
14 1 @ISA = qw(Exporter);
15 1 @EXPORT = qw();
16 1 @EXPORT_OK = qw(speakup_get speakup_set synth_get synth_set);
17 1 %EXPORT_TAGS = (ALL => [@EXPORT,@EXPORT_OK]);
18  
19 1 ▶no strict; no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 $Speech::Speakup::Message = undef;
22 1 $Speech::Speakup::SpDir = undef;
23 1 foreach ('/sys/accessibility/speakup','/proc/speakup') {
24 0 ▶ if (-d $_) { $SpDir = $_; }
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_) 0 2 2
25 }
26 # if (!$SpDir) { die ; } # results in 100% failure for CPAN-testers :-(
27 # eval 'require Speech::Speakup';
28 # sets $@ to "Can't locate ..." if Speech::Speakup is not installed
29 # sets $@ to "Compilation failed ..." if $SpDir is not present
30  
31 # /usr/lib/i386-linux-gnu/espeak-data/
32  
33 1 ▶use open ':locale'; # the open pragma was introduced in 5.8.6
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 0 ▶sub speakup_get { get($SpDir, @_); }
Subroutine speakup_get: not called CC=1 SCAR=6.9
Pod documented
36 0 ▶sub speakup_set { set($SpDir, @_); }
Subroutine speakup_set: not called CC=1 SCAR=6.9
Pod documented
37 0 ▶sub synth_get { get(synthdir(),@_); }
Subroutine synth_get: not called CC=1 SCAR=6.9
Pod documented
38 0 ▶sub synth_set { set(synthdir(),@_); }
Subroutine synth_set: not called CC=1 SCAR=6.9
Pod documented
39  
40 0 ▶sub set { my ($dir, $param, $value) = @_;
Subroutine set: not called CC=6 SCAR=37.4
Pod undocumented
41 0 ▶ if (! $param) { # return a list of all settable params
Branch: 1 branch
BranchTrueFalseTotal
unless ($param) 0 0 0
42 0 ▶ if (! opendir(D,$dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (opendir D, $dir) 0 0 0
43 0 $Message = "can't opendir $dir: ";
44 0 return undef;
45 }
46 my @l = sort grep
47 0 ▶ { (!/^\./) && (-f "$dir/$_") && is_w("$dir/$_") } readdir(D);
Condition0%0/6
!/^\./ && -f "$dir/$_" && is_w("$dir/$_")
!ll&&!rl&&r
000
not /^\./ and -f "$dir/$_"
!ll&&!rl&&r
000
MC/DC0%0/3
!/^\./ && -f "$dir/$_" && is_w("$dir/$_")
not /^\./ -f "$dir/$_" is_w("$dir/$_")
Truth table0%0/4
not(A) and B && C
A= not /^\./B= -f "$dir/$_"C= is_w("$dir/$_")
ABCresult
0XX0
10X0
1100
1111
48 0 closedir D;
49 0 $Message = undef;
50 0 return @l;
51 }
52 0 ▶ if (! open(F, '>', "$dir/$param")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not open(F, '>', "$dir/$param")) { } 0 0 0
53 0 $Message = "can't open $dir/$param: $!";
54 0 return undef;
55 } else {
56 0 print F "$value\n"; close F;
57 0 $Message = undef;
58 0 return 1;
59 }
60 }
61  
62 0 ▶sub get { my ($dir, $param) = @_;
Subroutine get: not called CC=7 SCAR=40.3
Pod undocumented
63 0 ▶ if (! $param) { # return a list of all gettable params
Branch: 1 branch
BranchTrueFalseTotal
unless ($param) 0 0 0
64 0 ▶ if (! opendir(D,$dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (opendir D, $dir) 0 0 0
65 0 $Message = "can't opendir $dir: ";
66 0 return undef;
67 }
68 my @l = sort grep
69 0 ▶ { (!/^\./) && (-f "$dir/$_") && is_r("$dir/$_") } readdir(D);
Condition0%0/6
!/^\./ && -f "$dir/$_" && is_r("$dir/$_")
!ll&&!rl&&r
000
not /^\./ and -f "$dir/$_"
!ll&&!rl&&r
000
MC/DC0%0/3
!/^\./ && -f "$dir/$_" && is_r("$dir/$_")
not /^\./ -f "$dir/$_" is_r("$dir/$_")
Truth table0%0/4
not(A) and B && C
A= not /^\./B= -f "$dir/$_"C= is_r("$dir/$_")
ABCresult
0XX0
10X0
1100
1111
70 0 closedir D;
71 0 $Message = undef;
72 0 return @l;
73 }
74 0 ▶ if (! open(F, '<', "$dir/$param")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not open(F, '<', "$dir/$param")) { } 0 0 0
75 0 $Message = "can't open $dir/$param: $!";
76 0 return undef;
77 } else {
78 0 my @lines = (<F>); close F;
79 0 $Message = undef;
80 # 1.03 keymap is 65 lines long ! the others are only one line.
81 0 ▶ if (1 < @lines) { return join('', @lines);
Branch: 1 branch
BranchTrueFalseTotal
if (1 < @lines) { } 0 0 0
82 0 } else { my $value = $lines[0]; $value =~ s/\s+$//; return $value;
83 }
84 }
85 }
86  
87 0 ▶sub synthdir {
Subroutine synthdir: not called CC=4 SCAR=30.0
Pod undocumented
88 0 my $sd = get($SpDir,'synth');
89 0 ▶ if (! $sd) { warn "can't find the synth directory\n"; return ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sd) 0 0 0
90 0 my $d = "$SpDir/$sd";
91 0 ▶ if (! -e $d) { warn "synth directory $d does not exist\n"; return ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $d) 0 0 0
92 0 ▶ if (! -d $d) { warn "synth directory $d is not a directory\n"; return ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $d) 0 0 0
93 0 return $d;
94 }
95  
96 0 ▶sub is_w {
Subroutine is_w: not called CC=1 SCAR=6.9
Pod undocumented
97 # because -w as root reports yes regardless of file permissions
98 0 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
99 $atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
100 0 return $mode & 2;
101 }
102 0 ▶sub is_r {
Subroutine is_r: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
104 $atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
105 0 return $mode & 4;
106 }
107  
108 0 ▶sub enter_speakup_silent { # 1.62
Subroutine enter_speakup_silent: not called CC=4 SCAR=30.0
Pod undocumented
109 # echo 7 > /sys/accessibility/speakup/silent if it exists
110 0 ▶ if (!$SpeakUpSilentFile) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($SpeakUpSilentFile) 0 0 0
111 0 ▶ if ($IsSpeakUpSilent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IsSpeakUpSilent) 0 0 0
112 0 warn "enter_speakup_silent but already IsSpeakUpSilent\r\n"; return 1 ;
113 }
114 0 ▶ if (open(S, '>', $SpeakUpSilentFile)) { print S "7\n"; close S; }
Branch: 1 branch
BranchTrueFalseTotal
if (open S, ">", $SpeakUpSilentFile) 0 0 0
115 0 $IsSpeakUpSilent = 1;
116 0 return 1;
117 }
118 0 ▶sub leave_speakup_silent { # 1.62
Subroutine leave_speakup_silent: not called CC=4 SCAR=30.0
Pod undocumented
119 # echo 4 > /sys/accessibility/speakup/silent if it exists
120 0 ▶ if (!$SpeakUpSilentFile) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($SpeakUpSilentFile) 0 0 0
121 0 ▶ if (!$IsSpeakUpSilent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($IsSpeakUpSilent) 0 0 0
122 0 warn "leave_speakup_silent but not IsSpeakUpSilent\r\n"; return 1 ;
123 }
124 0 ▶ if (open(S, '>', $SpeakUpSilentFile)) { print S "4\n"; close S; }
Branch: 1 branch
BranchTrueFalseTotal
if (open S, ">", $SpeakUpSilentFile) 0 0 0
125 0 $IsSpeakUpSilent = 0;
126 0 return 1;
127 }
128  
129 0 ▶sub which {
Subroutine which: not called CC=3 SCAR=24.8
Pod undocumented
130 0 my $f;
131 0 ▶ foreach $d (split(":",$ENV{'PATH'})) {$f="$d/$_[0]"; return $f if -x $f;}
Branch: 1 branch
BranchTrueFalseTotal
if -x $f 0 0 0
132 }
133 1 %SpeakMode = ();
134 1 ▶sub END {
Subroutine END: called CC=3 SCAR=17.3
135 0 ▶ if ($Eflite_FH) { print $Eflite_FH "s\nq { }\n"; close $Eflite_FH;
Branch: 2 branches
BranchTrueFalseTotal
if ($Eflite_FH) { } 0 1 1
elsif ($Espeak_PID) { } 0 1 1
136 0 } elsif ($Espeak_PID) { kill SIGHUP, $Espeak_PID; wait;
137 }
138 }
139  
140 1 1;
141  
142 __END__
↑ Summary