blib/lib/MIDI/Device.pm

filter: Statementstmt 100% 59 / 59 Branchbran 90.0% 9 / 10 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 17 / 17 Podpod 87.5% 7 / 8 totaltotal 96.0% 96 / 100 CC 9 SCAR 7.2
CC
9
Cov
97%
find
4.0
_build_shared
3.1
BUILD
3.0
CRAP 2.1
↑ Summary
1 package MIDI::Device;
2 3 our $AUTHORITY = 'cpan:GENE';
3  
4 # ABSTRACT: MIDI device metadata
5  
6 3 our $VERSION = '0.0304';
7  
8 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 # use Data::Dumper::Compact qw(ddc);
12 3 ▶use File::ShareDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use YAML::XS qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 3 has name => (
19 is => 'ro',
20 required => 1,
21 );
22  
23  
24 3 has module => (
25 is => 'ro',
26 default => 'MIDI::Device',
27 required => 1,
28 );
29  
30  
31 3 has shared => (
32 is => 'lazy',
33 );
34 13 ▶sub _build_shared {
Subroutine _build_shared: called CC=3 SCAR=11.3
35 13 my ($self) = @_;
36 13 ▶ my $shared = eval { dist_dir($self->module) } || './share/';
Condition50%1/2
eval { do { dist_dir($self->module) } } || './share/'
l!l
013
MC/DC0%0/1
eval { do { dist_dir($self->module) } } || './share/'
eval { do { dist_dir($self->module) } }
Truth table50%1/2
A
A= eval { do { dist_dir($self->module) } }
Aresult
11
00
37 13 ▶ croak "File $shared doesn't exist: $!" unless -e $shared;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $shared 0 13 13
38 13 return $shared;
39 }
40  
41 has _device => (
42 is => 'rw',
43 25 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 3 );
45  
46  
47 24 ▶sub cc {
Subroutine cc: called CC=2 SCAR=6.9
Pod documented
48 24 my ($self) = @_;
49 24 ▶ my $cc = $self->_device->{control_change} || [];
Condition100%2/2
$self->_device->{'control_change'} || []
l!l
231
MC/DC100%1/1
$self->_device->{'control_change'} || []
$self->_device->{'control_change'}
Truth table100%2/2
A
A= $self->_device->{'control_change'}
Aresult
11
00
50 24 return $cc;
51 }
52  
53  
54 16 ▶sub manufacturer {
Subroutine manufacturer: called CC=1 SCAR=0.0
Pod documented
55 16 my ($self) = @_;
56 16 return $self->_device->{manufacturer};
57 }
58  
59  
60 25 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
61 25 my ($self) = @_;
62 25 ▶ return unless $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name 1 24 25
63  
64 24 my $file = File::Spec->catfile($self->shared, $self->name . '.yml');
65 24 ▶ croak "File $file doesn't exist: $!" unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 2 22 24
66  
67 22 $self->_device(LoadFile($file));
68 }
69  
70  
71 14 ▶sub note_on {
Subroutine note_on: called CC=1 SCAR=0.0
Pod documented
72 14 my ($self) = @_;
73 14 return $self->_device->{note_on};
74 }
75  
76  
77 2 ▶sub pitch_bend {
Subroutine pitch_bend: called CC=1 SCAR=0.0
Pod documented
78 2 my ($self) = @_;
79 2 return $self->_device->{pitch_wheel_change};
80 }
81  
82  
83 15 ▶sub port_in {
Subroutine port_in: called CC=1 SCAR=0.0
Pod documented
84 15 my ($self) = @_;
85 15 return $self->_device->{port}{in};
86 }
87  
88  
89 15 ▶sub port_out {
Subroutine port_out: called CC=1 SCAR=0.0
Pod documented
90 15 my ($self) = @_;
91 15 return $self->_device->{port}{out};
92 }
93  
94  
95 13 ▶sub find {
Subroutine find: called CC=4 SCAR=13.9
Pod documented
96 13 my ($self, $key, $value) = @_;
97 13 ▶ return unless exists $self->_device->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->_device->{$key} 2 11 13
98 11 my @found;
99 11 for my $i (@{ $self->_device->{$key} }) {
100 154 ▶ push @found, $i if $i->{note} =~ /\Q$value\E/i;
Branch: 1 branch
BranchTrueFalseTotal
if $i->{"note"} =~ /\Q$value\E/i 11 143 154
101 }
102 11 return \@found;
103 }
104  
105  
106 3 1;
107  
108 __END__
↑ Summary