VIC/PIC/Base.pm

filter: Statementstmt 42.2% 30 / 71 Branchbran 13.6% 3 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 3 totaltotal 39.6% 42 / 106 SCAR 42.0
CC
14
Cov
35%
print_pinout
110.0
doesrole
4.1
doesroles
3.0
CRAP 66.6
« VIC/PIC/Functions/ECCP.pm ↑ Summary VIC/PIC/Functions/Operations.pm »
1 package VIC::PIC::Base;
2 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 31 our $VERSION = '0.29';
6 31 $VERSION = eval $VERSION;
7  
8 31 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 31 ▶use VIC::PIC::Roles; # load all the roles
Subroutine BEGIN: called CC=1 SCAR=0.0
11 31 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub doesrole {
14 1512 ▶ my $a = $_[0]->does('VIC::PIC::Roles::' . $_[1]);
Subroutine doesrole: called CC=3 SCAR=14.2
Pod undocumented
15 1512 ▶ unless ($_[1]) { # no logging
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[1]) 0 1512 1512
16 0 ▶ carp ref($_[0]) . " does not do role $_[1]" unless $a;
Branch: 1 branch
BranchTrueFalseTotal
unless $a 0 0 0
17 }
18 1512 return $a;
19 }
20  
21 sub doesroles {
22 240 ▶ my $self = shift;
Subroutine doesroles: called CC=3 SCAR=11.0
Pod undocumented
23 240 foreach (@_) {
24 600 ▶ return unless $self->doesrole($_);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesrole($_) 12 588 600
25 }
26 228 return 1;
27 }
28  
29 16 ▶has chip_config => (is => 'ro', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
30  
31 sub print_pinout {
32 0 ▶ my ($self, $fh) = @_;
Subroutine print_pinout: not called CC=10 SCAR=47.0
Pod undocumented
33 0 ▶ $fh = *STDOUT unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
34 0 ▶ return unless $self->doesroles(qw(CodeGen Chip));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesroles("CodeGen", "Chip") 0 0 0
35 0 my $pinref = $self->pins;
36 0 my @pinnames = ();
37 0 my $maxlen = 0;
38 0 foreach (sort(keys %$pinref)) {
39 0 ▶ next unless $_ =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /^\d+$/ 0 0 0
40 0 my $aa = $pinref->{$_};
41 0 ▶ my $str = join('/', @{$aa}) if ref $aa eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $aa eq "ARRAY" 0 0 0
42 0 ▶ $str = $aa unless ref $aa;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $aa 0 0 0
43 0 $pinnames[$_ - 1] = $str;
44 0 ▶ $maxlen = length($str) if $maxlen < length($str);
Branch: 1 branch
BranchTrueFalseTotal
if $maxlen < length $str 0 0 0
45 }
46 0 my $pdip = scalar(@pinnames) / 2;
47 0 my $start = 5 + $maxlen;
48 0 my $chip = uc($self->type);
49 0 my $w = 14;
50 0 my $notch = '__';
51 0 my $w0 = ($w - length($notch)) / 2;
52 0 print $fh "\n\n";
53 0 print $fh ' ' x $start, '+', '=' x $w0, $notch, '=' x $w0, '+', "\n";
54 0 my $pinline = '---';
55 0 ▶ for (my $i = 0; $i < $pdip; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $pdip) 0 0 0
56 0 my $s1 = $pinnames[$i];
57 0 my $s2 = $pinnames[2 * $pdip - $i - 1];
58 0 my $l1 = $start - 1 - length($pinline) - length($s1);
59 0 my $p1 = sprintf "%d", ($i + 1);
60 0 my $p2 = sprintf "%d", (2 * $pdip - $i);
61 0 my $w1 = $w - length($p1) - length($p2);
62 0 print $fh ' ' x $l1, $s1, ' ', $pinline, '|', $p1, ' ' x $w1, $p2, '|', $pinline, ' ', $s2, "\n";
63 0 print $fh ' ' x $start, '|', ' ' x $w, '|', "\n";
64 0 ▶ if (($i + 1) == int($pdip / 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 == int $pdip / 2) 0 0 0
65 0 my $w2 = int(($w - length($chip)) / 2);
66 0 my $w3 = $w - $w2 - length($chip);
67 0 print $fh ' ' x $start, '|', ' ' x $w2, $chip, ' ' x $w3, '|', "\n";
68 0 print $fh ' ' x $start, '|', ' ' x $w, '|', "\n";
69 }
70 }
71 0 print $fh ' ' x $start, '+', '=' x $w, '+', "\n";
72 0 print $fh "\n\n";
73 0 1;
74 }
75  
76 31 1;
« VIC/PIC/Functions/ECCP.pm ↑ Summary VIC/PIC/Functions/Operations.pm »