blib/lib/MIDI/Device.pm

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