UnitName.pm

filter: Statementstmt 15.8% 10 / 63 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 21.4% 3 / 14 Podpod 0.0% 0 / 10 totaltotal 7.6% 13 / 171 CC 33 SCAR 57.7
CC
33
Cov
8%
new
600.0
equals
42.0
long_string
6.0
CRAP 319.8
« PreProcessor/Cish.pm ↑ Summary Compiler/ModelSim.pm »
1 package Hardware::Vhdl::Automake::UnitName;
2 # just a holder of information, at the moment
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 0 ▶sub new { # class or object method, returns a new object
Subroutine new: not called CC=24 SCAR=64.0
Pod undocumented
9 0 my $class = shift;
10 0 my $arg1 = shift;
11
12 0 ▶ $class = ref $class || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
13 0 my $self={
14 type => undef,
15 library => undef,
16 pname => undef,
17 };
18
19 0 ▶ if (ref $arg1 eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $arg1 eq 'HASH') { } 0 0 0
elsif (lc $arg1 eq 'architecture' and @_ == 3) { } 0 0 0
elsif (not ref $arg1 and @_ == 2 or (@_ == 3 or not defined $_[2])) { } 0 0 0
20 # check required args
21 0 for my $argname (qw/ type library pname /) {
22 0 ▶ croak "'$argname' parameter is required for new $class" unless exists $arg1->{$argname};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $arg1->{$argname} 0 0 0
23 }
24 croak "'type' parameter to new $class must be package, package body, entity, architecture, configuration, or Verilog unit"
25 0 ▶ unless $arg1->{type} =~ m/^(package|package body|entity|architecture|configuration|Verilog unit)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg1->{"type"} =~ /^(package|package body|entity|architecture|configuration|Verilog unit)$/i 0 0 0
26 0 ▶ if (lc $arg1->{type} eq 'architecture') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $arg1->{'type'} eq 'architecture') { } 0 0 0
elsif (exists $arg1->{'sname'}) { } 0 0 0
27 0 ▶ croak "'sname' parameter is required for new architecture UnitName" if !exists $arg1->{sname};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $arg1->{"sname"} 0 0 0
28 } elsif (exists $arg1->{sname}) {
29 0 ▶ croak "'sname' parameter is only allowed for architecture UnitNames" if defined $arg1->{sname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg1->{"sname"} 0 0 0
30 0 delete $arg1->{sname};
31 }
32 # copy args to self
33 0 for my $argname (qw/ type library pname sname /) {
34 0 ▶ if (exists $arg1->{$argname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg1->{$argname}) 0 0 0
35 0 $self->{$argname} = $arg1->{$argname};
36 0 delete $arg1->{$argname};
37 }
38 }
39 # check there are no passed args left
40 0 ▶ if (scalar keys %$arg1) { croak "unrecognised parameter(s) ".join(', ', keys %$arg1)." passed to new UnitName" }
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$arg1) 0 0 0
41 ▶ } elsif (lc $arg1 eq 'architecture' && @_ == 3) {
Condition0%0/3
lc $arg1 eq "architecture" and @_ == 3
!ll&&!rl&&r
000
MC/DC0%0/2
lc $arg1 eq "architecture" and @_ == 3
lc $arg1 eq "architecture" @_ == 3
Truth table0%0/3
A and B
A= lc $arg1 eq "architecture"B= @_ == 3
ABresult
0X0
100
111
42 0 $self->{type} = $arg1;
43 0 ($self->{library}, $self->{pname}, $self->{sname}) = @_;
44 ▶ } elsif (!(ref $arg1) && @_ == 2 || (@_ == 3 || !defined $_[2])) {
Condition0%0/9
not ref $arg1 and @_ == 2 or (@_ == 3 or not defined $_[2])
l!l&&r!l&&!r
000
not ref $arg1 and @_ == 2
!ll&&!rl&&r
000
@_ == 3 or not defined $_[2]
l!l&&r!l&&!r
000
MC/DC0%0/4
not ref $arg1 and @_ == 2 or (@_ == 3 or not defined $_[2])
not ref $arg1 @_ == 2 @_ == 3 not defined $_[2]
Truth table0%0/7
not(A) and B or C or not(D)
A= not ref $arg1B= @_ == 2C= @_ == 3D= not defined $_[2]
ABCDresult
11XX1
0X1X1
0X011
101X1
10011
0X000
10000
45 0 ▶ croak "first parameter to new $class must be package, package body, entity, architecture, configuration, or Verilog unit"
Branch: 1 branch
BranchTrueFalseTotal
unless $arg1 =~ /^(package|package body|entity|architecture|configuration|Verilog unit)$/i 0 0 0
46 unless $arg1 =~ m/^(package|package body|entity|architecture|configuration|Verilog unit)$/i;
47 0 $self->{type} = $arg1;
48 0 ($self->{library}, $self->{pname}) = @_;
49 } else {
50 0 croak "${class}::new should be passed a hashref of information, or a 3 or 4-element list";
51 }
52
53 # normalise the names, check none is undef
54 0 for my $k (qw/type library pname sname/) {
55 0 ▶ if ( exists $self->{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$k}) 0 0 0
56 0 ▶ croak "'$k' parameter to new $class must be defined" unless defined $self->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$k} 0 0 0
57 0 ▶ $self->{$k} = lc $self->{$k} unless substr( $self->{$k}, 0, 1 ) eq '\\' ;
Branch: 1 branch
BranchTrueFalseTotal
unless substr($self->{$k}, 0, 1) eq "\\" 0 0 0
58 }
59 }
60
61 0 bless $self, $class;
62 }
63
64 # field accessors
65 0 ▶sub type { $_[0]->{type} } # returns package, package body, entity, architecture, or configuration
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
66 0 ▶sub library { $_[0]->{library} }
Subroutine library: not called CC=1 SCAR=6.9
Pod undocumented
67 0 ▶sub pname { $_[0]->{pname} }
Subroutine pname: not called CC=1 SCAR=6.9
Pod undocumented
68 0 ▶sub sname { $_[0]->{sname} }
Subroutine sname: not called CC=1 SCAR=6.9
Pod undocumented
69
70 0 ▶sub long_string {
Subroutine long_string: not called CC=2 SCAR=17.9
Pod undocumented
71 0 my $self = shift;
72 $self->{type}.' '
73 .(exists $self->{sname} ? $self->{sname}.' of '.$self->{pname} : $self->{pname})
74 0 ▶ .' in library '.$self->{library};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'sname'} ? : 0 0 0
75 }
76
77 0 ▶sub short_string {
Subroutine short_string: not called CC=2 SCAR=17.9
Pod undocumented
78 0 my $self = shift;
79 $self->{type}.' '
80 .$self->{library}.'.'
81 .$self->{pname}
82 0 ▶ .(exists $self->{sname} ? '('.$self->{sname}.')' : '');
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'sname'} ? : 0 0 0
83 }
84
85 0 ▶sub filename_string {
Subroutine filename_string: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my $self = shift;
87 # convert a design-unit name to a valid and unique file name, preserving the case of the name
88 0 my $file = $self->{type};
89 0 $file =~ s/ /_/g;
90 0 $file .= ' '.&_name2file($self->{library}).' '.&_name2file($self->{pname});
91 0 ▶ $file .= ' '.&_name2file($self->{sname}) if exists $self->{sname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"sname"} 0 0 0
92 0 $file;
93 }
94
95 0 ▶sub library_dirname_string {
Subroutine library_dirname_string: not called CC=1 SCAR=6.9
Pod undocumented
96 0 my $self = shift;
97 # convert a library name to a valid and unique directory name with no spaces, preserving the case of the name
98 &_name2file($self->{library})
99 0 }
100
101 0 ▶sub _name2file {
Subroutine _name2file: not called CC=2 SCAR=17.9
102 0 my $name = shift;
103 0 ▶ croak "name passed to _name2file not defined" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
104 # convert a library or design-unit name to a valid and unique directory/file name with no spaces, preserving the case of the name
105 0 $name =~ s/([^A-Za-z0-9_])/sprintf('%%%02x',ord($1))/ge;
106 0 $name =~ s/[A-Z]/\@$1/g;
107 0 lc $name;
108 }
109
110 0 ▶sub equals {
Subroutine equals: not called CC=6 SCAR=37.4
Pod undocumented
111 0 my ($s1, $s2) = @_;
112 $s1->{type} eq $s2->{type}
113 && $s1->{pname} eq $s2->{pname}
114 && $s1->{library} eq $s2->{library}
115 && (exists $s1->{sname}) == (exists $s2->{sname})
116 0 ▶ && ((!exists $s1->{sname}) || ($s1->{sname} eq $s2->{sname}));
Branch: 1 branch
BranchTrueFalseTotal
$s1->{"type"} eq $s2->{"type"} and $s1->{"pname"} eq $s2->{"pname"} and $s1->{"library"} eq $s2->{"library"} and exists $s1->{"sname"} == exists $s2->{"sname"} and !exists $s1->{"sname"} || $s1->{"sname"} eq $s2->{"sname"} 0 0 0
Condition0%0/15
$s1->{'type'} eq $s2->{'type'} && $s1->{'pname'} eq $s2->{'pname'} && $s1->{'library'} eq $s2->{'library'} && exists $s1->{'sname'} == exists $s2->{'sname'} && (!exists $s1->{'sname'} || $s1->{'sname'} eq $s2->{'sname'})
!ll&&!rl&&r
000
$s1->{"type"} eq $s2->{"type"} and $s1->{"pname"} eq $s2->{"pname"} and $s1->{"library"} eq $s2->{"library"} and exists $s1->{"sname"} == exists $s2->{"sname"}
!ll&&!rl&&r
000
$s1->{"type"} eq $s2->{"type"} and $s1->{"pname"} eq $s2->{"pname"} and $s1->{"library"} eq $s2->{"library"}
!ll&&!rl&&r
000
$s1->{"type"} eq $s2->{"type"} and $s1->{"pname"} eq $s2->{"pname"}
!ll&&!rl&&r
000
not exists $s1->{"sname"} or $s1->{"sname"} eq $s2->{"sname"}
l!l&&r!l&&!r
000
MC/DC0%0/6
$s1->{'type'} eq $s2->{'type'} && $s1->{'pname'} eq $s2->{'pname'} && $s1->{'library'} eq $s2->{'library'} && exists $s1->{'sname'} == exists $s2->{'sname'} && (!exists $s1->{'sname'} || $s1->{'sname'} eq $s2->{'sname'})
$s1->{"type"} eq $s2->{"type"} $s1->{"pname"} eq $s2->{"pname"} $s1->{"library"} eq $s2->{"library"} exists $s1->{"sname"} == exists $s2->{"sname"} not exists $s1->{"sname"} $s1->{"sname"} eq $s2->{"sname"}
Truth table0%0/7
A and B and C and D && not(E) or F
A= $s1->{"type"} eq $s2->{"type"}B= $s1->{"pname"} eq $s2->{"pname"}C= $s1->{"library"} eq $s2->{"library"}D= exists $s1->{"sname"} == exists $s2->{"sname"}E= not exists $s1->{"sname"}F= $s1->{"sname"} eq $s2->{"sname"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
1111000
11111X1
1111011
117 }
118
119 1 1;
« PreProcessor/Cish.pm ↑ Summary Compiler/ModelSim.pm »