blib/lib/App/Asciio/Connections.pm

filter: Statementstmt 40.2% 41 / 102 Branchbran 11.1% 2 / 18 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 62.5% 10 / 16 Podpod 0.0% 0 / 10 totaltotal 32.5% 54 / 166 CC 24 SCAR 26.9
CC
24
Cov
33%
delete_connections_containing
30.0
get_possible_connections
21.5
get_connections_containing
20.0
CRAP 14.8
« blib/lib/App/Asciio/stripes/if_box.pm ↑ Summary blib/lib/App/Asciio/Ascii.pm »
1  
2 package App::Asciio;
3  
4 4 $|++ ;
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use Data::TreeDumper ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Clone;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use List::Util qw(min max) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use List::MoreUtils qw(any minmax first_value) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #-----------------------------------------------------------------------------
15  
16 sub connect_elements
17 169 ▶{
Subroutine connect_elements: called CC=1 SCAR=0.0
Pod undocumented
18 169 my ($self, @elements) = @_ ;
19  
20 169 my @possible_connections = $self->get_possible_connections(@elements) ;
21  
22 169 $self->add_connections(@possible_connections) ;
23 }
24  
25 #-----------------------------------------------------------------------------
26  
27 sub add_connections
28 169 ▶{
Subroutine add_connections: called CC=1 SCAR=0.0
Pod undocumented
29 169 my ($self, @connections) = @_ ;
30  
31 169 $self->flash_new_connections(@connections) ;
32  
33 169 push @{$self->{CONNECTIONS}}, @connections ;
34 169 $self->{MODIFIED }++ ;
35 }
36  
37 #-----------------------------------------------------------------------------
38  
39 sub get_possible_connections
40 169 ▶{
Subroutine get_possible_connections: called CC=9 SCAR=30.7
Pod undocumented
41 169 my ($self, @elements) = @_ ;
42  
43 169 my @possible_connections ;
44 my %connected_connectors ;
45  
46 169 for my $element (@elements)
47 {
48 169 my @connectors = $element->get_connector_points() ;
49
50 169 ▶ last unless @connectors ;
Branch: 1 branch
BranchTrueFalseTotal
unless @connectors 0 169 169
51
52 # tbd: optimize search by eliminating those elements that are too far
53 169 ▶ for my $connectee (reverse grep { $_->is_autoconnect_enabled() || $_->is_border_connection_allowed() } @{$self->{ELEMENTS}})
Condition33%1/3
$_->is_autoconnect_enabled || $_->is_border_connection_allowed
l!l&&r!l&&!r
16900
MC/DC0%0/2
$_->is_autoconnect_enabled || $_->is_border_connection_allowed
$_->is_autoconnect_enabled $_->is_border_connection_allowed
Truth table33%1/3
A || B
A= $_->is_autoconnect_enabledB= $_->is_border_connection_allowed
ABresult
1X1
011
000
54 {
55 169 ▶ next if $connectee == $element ; # dont connect to self
Branch: 1 branch
BranchTrueFalseTotal
if $connectee == $element 169 0 169
56
57 0 for my $connector (@connectors)
58 {
59 my @connections = $connectee->match_connector
60 (
61 # translate coordinates to connectee reference
62 ($element->{X} - $connectee->{X}) + $connector->{X},
63 ($element->{Y} - $connectee->{Y}) + $connector->{Y},
64 0 ) ;
65
66 # make connection if possible. connect to a single point
67 0 ▶ if(defined $connections[0] && ! exists $connected_connectors{$element.$connector->{NAME}})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connections[0] and not exists $connected_connectors{$element . $connector->{"NAME"}}) 0 0 0
Condition0%0/3
defined $connections[0] and not exists $connected_connectors{$element . $connector->{"NAME"}}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $connections[0] and not exists $connected_connectors{$element . $connector->{"NAME"}}
defined $connections[0] not exists $connected_connectors{$element . $connector->{"NAME"}}
Truth table0%0/3
A and not(B)
A= defined $connections[0]B= not exists $connected_connectors{$element . $connector->{"NAME"}}
ABresult
0X0
100
111
68 {
69 0 push @possible_connections,
70 {
71 CONNECTED => $element,
72 CONNECTOR =>$connector,
73 CONNECTEE => $connectee,
74 CONNECTION => $connections[0],
75 } ;
76
77 0 $connected_connectors{$element.$connector->{NAME}}++ ;
78 0 next ;
79 }
80 }
81 }
82 }
83
84 169 return(@possible_connections) ;
85 }
86  
87 #-----------------------------------------------------------------------------
88  
89 sub get_connections_containing
90 0 ▶{
Subroutine get_connections_containing: not called CC=4 SCAR=30.0
Pod undocumented
91 0 my($self, @elements) = @_ ;
92  
93 0 my %elements_to_find = map {$_ => 1} @elements ;
94 0 my @connections ;
95  
96 0 for my $connection (@{$self->{CONNECTIONS}})
97 {
98 0 ▶ if(exists $elements_to_find{$connection->{CONNECTED}} || exists $elements_to_find{$connection->{CONNECTEE}})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $elements_to_find{$connection->{"CONNECTED"}} or exists $elements_to_find{$connection->{"CONNECTEE"}}) 0 0 0
Condition0%0/3
exists $elements_to_find{$connection->{"CONNECTED"}} or exists $elements_to_find{$connection->{"CONNECTEE"}}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $elements_to_find{$connection->{"CONNECTED"}} or exists $elements_to_find{$connection->{"CONNECTEE"}}
exists $elements_to_find{$connection->{"CONNECTED"}} exists $elements_to_find{$connection->{"CONNECTEE"}}
Truth table0%0/3
A or B
A= exists $elements_to_find{$connection->{"CONNECTED"}}B= exists $elements_to_find{$connection->{"CONNECTEE"}}
ABresult
1X1
011
000
99 {
100 0 push @connections, $connection;
101 }
102 }
103  
104 0 return(@connections) ;
105 }
106  
107 #-----------------------------------------------------------------------------
108  
109 sub delete_connections
110 0 ▶{
Subroutine delete_connections: not called CC=3 SCAR=24.8
Pod undocumented
111 0 my($self, @connections) = @_ ;
112  
113 0 my %connections_to_delete = map {$_ => 1} @connections ;
114  
115 0 for my $connection (@{$self->{CONNECTIONS}})
116 {
117 0 ▶ if(exists $connections_to_delete{$connection})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $connections_to_delete{$connection}) 0 0 0
118 {
119 0 $connection = undef ;
120 }
121 }
122  
123 0 @{$self->{CONNECTIONS}} = grep { defined $_} @{$self->{CONNECTIONS}} ;
124  
125 0 $self->{MODIFIED }++ ;
126 }
127  
128 #-----------------------------------------------------------------------------
129  
130 sub delete_connections_containing
131 0 ▶{
Subroutine delete_connections_containing: not called CC=5 SCAR=34.0
Pod undocumented
132 0 my($self, @elements) = @_ ;
133  
134 0 for my $element(@elements)
135 {
136 0 for my $connection (@{$self->{CONNECTIONS}})
137 {
138 0 ▶ if($connection->{CONNECTED} == $element || $connection->{CONNECTEE} == $element)
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->{"CONNECTED"} == $element or $connection->{"CONNECTEE"} == $element) 0 0 0
Condition0%0/3
$connection->{"CONNECTED"} == $element or $connection->{"CONNECTEE"} == $element
l!l&&r!l&&!r
000
MC/DC0%0/2
$connection->{"CONNECTED"} == $element or $connection->{"CONNECTEE"} == $element
$connection->{"CONNECTED"} == $element $connection->{"CONNECTEE"} == $element
Truth table0%0/3
A or B
A= $connection->{"CONNECTED"} == $elementB= $connection->{"CONNECTEE"} == $element
ABresult
1X1
011
000
139 {
140 0 $connection = undef ;
141 }
142 }
143 }
144  
145 0 @{$self->{CONNECTIONS}} = grep { defined $_} @{$self->{CONNECTIONS}} ;
146  
147 0 $self->{MODIFIED }++ ;
148 }
149  
150 #-----------------------------------------------------------------------------
151  
152 sub is_connectee
153 0 ▶{
Subroutine is_connectee: not called CC=3 SCAR=24.8
Pod undocumented
154 0 my($self, $element) = @_ ;
155  
156 0 my $connectee = 0 ;
157  
158 0 for my $connection (@{$self->{CONNECTIONS}})
159 {
160 0 ▶ if($connection->{CONNECTEE} == $element)
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->{"CONNECTEE"} == $element) 0 0 0
161 {
162 0 $connectee++ ;
163 last
164 0 }
165 }
166  
167 0 return($connectee) ;
168 }
169  
170 #-----------------------------------------------------------------------------
171  
172 sub get_connected
173 0 ▶{
Subroutine get_connected: not called CC=3 SCAR=24.8
Pod undocumented
174 0 my($self, $element) = @_ ;
175  
176 0 my(@connected) ;
177  
178 0 for my $connection (@{$self->{CONNECTIONS}})
179 {
180 0 ▶ if($connection->{CONNECTEE} == $element)
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->{"CONNECTEE"} == $element) 0 0 0
181 {
182 0 push @connected, $connection ;
183 }
184 }
185  
186 0 return(@connected) ;
187 }
188  
189 #-----------------------------------------------------------------------------
190  
191 sub is_connected
192 0 ▶{
Subroutine is_connected: not called CC=3 SCAR=24.8
Pod undocumented
193 0 my($self, $element) = @_ ;
194  
195 0 my $connected = 0 ;
196  
197 0 for my $connection (@{$self->{CONNECTIONS}})
198 {
199 0 ▶ if($connection->{CONNECTED} == $element)
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->{"CONNECTED"} == $element) 0 0 0
200 {
201 0 $connected++ ;
202 last
203 0 }
204 }
205  
206 0 return($connected) ;
207 }
208  
209 #-----------------------------------------------------------------------------
210  
211 sub flash_new_connections
212 169 ▶{
Subroutine flash_new_connections: called CC=1 SCAR=0.0
Pod undocumented
213 169 my($self, @connections) = @_ ;
214  
215 169 push @{$self->{NEW_CONNECTIONS}}, @connections ;
216 }
217  
218 #-----------------------------------------------------------------------------
219  
220  
221 4 1 ;
« blib/lib/App/Asciio/stripes/if_box.pm ↑ Summary blib/lib/App/Asciio/Ascii.pm »