TabsCreator/TabParser.pm

filter: Statementstmt 80.0% 32 / 40 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 77.0% 47 / 61 CC 7 SCAR 17.8
CC
7
Cov
77%
parse
10.1
BEGIN
1.0
BEGIN
1.0
CRAP 5.9
« TabsCreator/NoteToToneConverter.pm ↑ Summary TabsCreator/Warning.pm »
1 package Music::Harmonica::TabsCreator::TabParser;
2  
3 4 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our $VERSION = '0.05';
11  
12 # This class converts a tab into tones (degrees) relative to the key of C4.
13 # It accepts an input specifying the tuning of an harmonica.
14  
15 2 ▶sub new ($class, $tab_to_tones) {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
16 # We order the keys by length, so that we match the longest ones first.
17 2 my $re = join('|', map { quotemeta } sort { length $b <=> length $a } keys %{$tab_to_tones});
18 2 my $self = bless {
19 tab_to_tones => $tab_to_tones,
20 tab_re => qr/$re/,
21 }, $class;
22 2 return $self;
23 }
24  
25 2 ▶sub parse ($self, $tab) {
Subroutine parse: called CC=7 SCAR=23.2
Pod undocumented
26 2 my @out;
27 2 pos($tab) = 0;
28 2 ▶ while (pos($tab) < length($tab)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $tab < length $tab) 16 2 18
29 16 ▶ next if $tab =~ m/\G\h+/gc;
Branch: 1 branch
BranchTrueFalseTotal
if $tab =~ /\G\h+/cgu 7 9 16
30  
31 9 ▶ if ($tab =~ m/\G(\v+)/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tab =~ /\G(\v+)/cgu) 0 9 9
32 0 push @out, $1;
33 0 next;
34 }
35  
36 9 ▶ if ($tab =~ m/ \G \# \s* ( .*? (?:\r\n|\n|\r|\v|\z) )/xgc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tab =~ / \G \# \s* ( .*? (?:\r\n|\n|\r|\v|\z) )/cgux) 0 9 9
37 0 push @out, $1;
38 0 next;
39 }
40  
41 9 ▶ if ($tab =~ m/\G($self->{tab_re})/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tab =~ /\G($self->{"tab_re"})/cgu) 9 0 9
42 9 push @out, $self->{tab_to_tones}{$1};
43 9 next;
44 }
45  
46 0 my $pos = pos($tab);
47 0 substr $tab, $pos, 0, '-->';
48 0 $pos++;
49 0 die "Invalid syntax in the input tab at character ${pos}: ${tab}\n";
50 }
51 2 ▶ return wantarray ? @out : \@out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
52 }
53  
54 4 1;
« TabsCreator/NoteToToneConverter.pm ↑ Summary TabsCreator/Warning.pm »