blib/lib/Acme/Morse/Audible.pm

filter: Statementstmt 100% 20 / 20 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 50.0% 1 / 2 totaltotal 96.7% 30 / 31 CC 3 SCAR 4.5
CC
3
Cov
100%
record
2.0
play
2.0
BEGIN
1.0
CRAP 1.6
↑ Summary
1 package Acme::Morse::Audible;
2 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 our $VERSION = '1.10';
7
8 my $hearable = "\x4d\x54\x68\x64\0\0\0\6\0\0\0\1\x60\0\115\124\162\153";
9 my($long,$short)=("\xFF\x40\x90\x56\x50\x82\xDF\0\x80\x56\x00","\xFF\x40\x90\x56\x50\xFF\x40\x80\x56\x00");
10
11 1 ▶sub record{
Subroutine record: called CC=2 SCAR=6.9
Pod documented
12 1 local $_ = unpack 'b*', pop;
13 1 ▶ s/(.)/$1?$long:$short/eg;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 1097 1391 2488
14 1 $_="\0\xC0\x11\0\xFF\x59\x02\0\0$_\0\xFF\x2F";
15 1 $hearable . pack('L', length($_)) . $_;
16 }
17
18 2 ▶sub play{
Subroutine play: called CC=2 SCAR=6.9
Pod undocumented
19 2 local $_ = pop;
20 2 chomp;
21 2 s/^$hearable.{4}.+?\0{2}//;s/\0\xFF\x2F$//;
22 2 ▶ s/\xFF\x40(.+?)\x56\0/length($1)==7?1:0/ge;
Branch: 1 branch
BranchTrueFalseTotal
length $1 == 7 ? : 12 20 32
23 2 pack 'b*', $_;
24 }
25
26 open 0 or die "Cannot hear '$0'.\n";
27 (my $telegram = do{local $/=undef;<0>}) =~ s/.*^\s*(use|no)\s+Acme::Morse::Audible\s*;\n//sm;
28 close 0;
29
30 if($1 eq 'use'){
31 if($telegram =~ /^$hearable/){
32 eval play $telegram;
33 }else{
34 open my $rec,'>',$0 or die "Cannot record '$0'.\n";
35 binmode($rec);
36 print $rec "use Acme::Morse::Audible;\n" . record $telegram;
37 close $rec;
38 }
39 exit;
40 }else{
41 if($telegram =~ /^$hearable/){
42 open my $pl,'>',$0 or die "Cannot record '$0'.\n";
43 print $pl "no Acme::Morse::Audible;\n" . play $telegram;
44 close $pl;
45 exit;
46 }
47 }
48 1;
49
50
51 __END__
↑ Summary