| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2020-2026 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | package Devel::MAT::ToolBase::GraphWalker 0.56; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use base qw( Devel::MAT::Tool ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use feature qw( postderef signatures ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | no warnings qw( experimental::postderef experimental::signatures ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use List::Util qw( any pairs ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use List::UtilsBy qw( nsort_by ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | my %STRENGTH_ORDER = ( | |||||||||||||||||||||||||||||||||||||||||
| 20 | strong => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | weak => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | indirect => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | inferred => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | my $next_id; | |||||||||||||||||||||||||||||||||||||||||
| 27 | my %id_for; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub reset ( $self ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $next_id = "A"; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | undef %id_for; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | undef %seen; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | sub walk_graph ( $self, $node, @args ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walk_graph: called CC=15 SCAR=32.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | my $addr = $node->addr; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | my @roots = $node->roots; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | my @edges = $node->edges_in; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | ▶ | if( !@roots and !@edges ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@roots or @edges
MC/DC0%0/2
@roots or @edges
@roots
@edges
Truth table66%2/3
A or B
A= @rootsB= @edges
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->on_walk_nothing( $node, @args ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | if( @roots == 1 and $roots[0] eq "EDEPTH" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@roots == 1 and $roots[0] eq "EDEPTH"
MC/DC0%0/2
@roots == 1 and $roots[0] eq "EDEPTH"
@roots == 1
$roots[0] eq "EDEPTH"
Truth table66%2/3
A and B
A= @roots == 1B= $roots[0] eq "EDEPTH"
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $self->on_walk_EDEPTH( $node, @args ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # Don't bother showing any non-root edges if we have a strong root | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | @edges = () if any { $_->strength eq "strong" } @roots; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | if( @edges > 0 and $seen{$addr} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@edges > 0 and $seen{$addr}
MC/DC0%0/2
@edges > 0 and $seen{$addr}
@edges > 0
$seen{$addr}
Truth table66%2/3
A and B
A= @edges > 0B= $seen{$addr}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $cyclic = $seen{$addr} == 1; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $id = $id_for{$addr}; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $self->on_walk_again( $node, $cyclic, $id, @args ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | $seen{$addr}++; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | foreach my $idx ( 0 .. $#roots ) { | |||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | my $root = $roots[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | ▶ | my $isfinal = $idx == $#roots && !@edges; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$idx == $#roots && !@edges
MC/DC0%0/2
$idx == $#roots && !@edges
$idx == $#roots
!@edges
Truth table33%1/3
A && not(B)
A= $idx == $#rootsB= !@edges
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | $self->on_walk_root( $node, $root, $isfinal, @args ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | my @refs = nsort_by { $STRENGTH_ORDER{$_->[0]->strength} } pairs @edges; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | foreach my $idx ( 0 .. $#refs ) { | |||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | my ( $ref, $refnode ) = $refs[$idx]->@*; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | my $is_final = $idx == $#refs; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | my $ref_id; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | if( $refnode->edges_out > 1 and not $refnode->roots and not $id_for{$refnode->addr} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$refnode->edges_out > 1 and not $refnode->roots and not $id_for{$refnode->addr}
$refnode->edges_out > 1 and not $refnode->roots
MC/DC0%0/3
$refnode->edges_out > 1 and not $refnode->roots and not $id_for{$refnode->addr}
$refnode->edges_out > 1
not $refnode->roots
not $id_for{$refnode->addr}
Truth table50%2/4
A and not(B) and not(C)
A= $refnode->edges_out > 1B= not $refnode->rootsC= not $id_for{$refnode->addr}
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $ref_id = $id_for{$refnode->addr} = $next_id++; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | my @subargs = | |||||||||||||||||||||||||||||||||||||||||
| 84 | $self->on_walk_ref( $node, $ref, $refnode->sv, $ref_id, $is_final, @args ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | if( $refnode->addr == $addr ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $self->on_walk_itself( $node, @subargs ); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | $self->walk_graph( $refnode, @subargs ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | $seen{$addr}++; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | 0x55AA; | |||||||||||||||||||||||||||||||||||||||||