blib/lib/Map/Tube/Graph.pm

filter: Statementstmt 41.0% 23 / 56 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 32.6% 32 / 98 CC 12 SCAR 28.3
CC
12
Cov
29%
new
30.0
graph
30.0
__ANON__
20.0
CRAP 17.0
↑ Summary
1 package Map::Tube::Graph;
2  
3 # Pragmas.
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # Modules.
8 3 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use List::MoreUtils qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Version.
15 3 our $VERSION = 0.03;
16  
17 # Constructor.
18 sub new {
19 0 ▶ my ($class, @params) = @_;
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
20  
21 # Create object.
22 0 my $self = bless {}, $class;
23  
24 # Edge callback.
25 $self->{'callback_edge'} = sub {
26 0 ▶ my ($self, $node, $link) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 $self->{'graph'}->add_edge($node->id, $link);
28 0 return;
29 0 };
30  
31 # Vertex callback.
32 $self->{'callback_vertex'} = sub {
33 0 ▶ my ($self, $node) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 $self->{'graph'}->add_vertex($node->id);
35 0 return;
36 0 };
37  
38 # Graph object.
39 0 $self->{'graph'} = undef;
40  
41 # Map::Tube object.
42 0 $self->{'tube'} = undef;
43  
44 # Process params.
45 0 set_params($self, @params);
46  
47 # Check Map::Tube object.
48 0 ▶ if (! defined $self->{'tube'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"tube"}) 0 0 0
49 0 err "Parameter 'tube' is required.";
50 }
51 0 ▶ if (! blessed($self->{'tube'})
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($self->{"tube"}) and $self->{"tube"}->DOES("Map::Tube")) 0 0 0
Condition0%0/3
builtin::blessed($self->{"tube"}) and $self->{"tube"}->DOES("Map::Tube")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($self->{"tube"}) and $self->{"tube"}->DOES("Map::Tube")
builtin::blessed($self->{"tube"}) $self->{"tube"}->DOES("Map::Tube")
Truth table0%0/3
A and B
A= builtin::blessed($self->{"tube"})B= $self->{"tube"}->DOES("Map::Tube")
ABresult
0X0
100
111
52 || ! $self->{'tube'}->DOES('Map::Tube')) {
53  
54 0 err "Parameter 'tube' must be 'Map::Tube' object.";
55 }
56  
57 # Graph object.
58 0 ▶ if (! defined $self->{'graph'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"graph"}) 0 0 0
59 0 $self->{'graph'} = Graph->new;
60 }
61  
62 # Object.
63 0 return $self;
64 }
65  
66 # Get graph.
67 sub graph {
68 0 ▶ my $self = shift;
Subroutine graph: not called CC=5 SCAR=34.0
Pod documented
69 0 foreach my $node (values %{$self->{'tube'}->nodes}) {
70 0 $self->{'callback_vertex'}->($self, $node);
71 }
72 0 my @processed;
73 0 foreach my $node (values %{$self->{'tube'}->nodes}) {
74 0 foreach my $link (split m/,/ms, $node->link) {
75 0 ▶ if (none {
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $_->[0] eq $node->id and $_->[1] eq $link or $_->[0] eq $link and $_->[1] eq $node->id; } , @processed)) 0 0 0
76 0 ▶ ($_->[0] eq $node->id && $_->[1] eq $link)
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
$_->[0] eq $node->id and $_->[1] eq $link or $_->[0] eq $link and $_->[1] eq $node->id 0 0 0
Condition0%0/9
$_->[0] eq $node->id && $_->[1] eq $link || $_->[0] eq $link && $_->[1] eq $node->id
l!l&&r!l&&!r
000
$_->[0] eq $node->id and $_->[1] eq $link
!ll&&!rl&&r
000
$_->[0] eq $link and $_->[1] eq $node->id
!ll&&!rl&&r
000
MC/DC0%0/4
$_->[0] eq $node->id && $_->[1] eq $link || $_->[0] eq $link && $_->[1] eq $node->id
$_->[0] eq $node->id $_->[1] eq $link $_->[0] eq $link $_->[1] eq $node->id
Truth table0%0/7
A and B || C and D
A= $_->[0] eq $node->idB= $_->[1] eq $linkC= $_->[0] eq $linkD= $_->[1] eq $node->id
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
77 ||
78 ($_->[0] eq $link && $_->[1] eq $node->id)
79 } @processed) {
80  
81 0 $self->{'callback_edge'}->($self, $node, $link);
82 0 push @processed, [$node->id, $link];
83 }
84 }
85 }
86 0 return $self->{'graph'};
87 }
88  
89 3 1;
90  
91 __END__
↑ Summary