blib/lib/Map/Tube/Graph.pm

filter: Statementstmt 40.6% 26 / 64 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 61.5% 8 / 13 Podpod 100% 2 / 2 totaltotal 32.4% 36 / 111 CC 14 SCAR 31.9
CC
14
Cov
29%
new
56.0
graph
30.0
__ANON__
20.0
CRAP 24.4
↑ 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 English;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use List::MoreUtils qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Version.
16 3 our $VERSION = 0.04;
17  
18 # Constructor.
19 sub new {
20 0 ▶ my ($class, @params) = @_;
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
21  
22 # Create object.
23 0 my $self = bless {}, $class;
24  
25 # Edge callback.
26 $self->{'callback_edge'} = sub {
27 0 ▶ my ($self, $node, $link) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 $self->{'graph'}->add_edge($node->id, $link);
29 0 return;
30 0 };
31  
32 # Vertex callback.
33 $self->{'callback_vertex'} = sub {
34 0 ▶ my ($self, $node) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 $self->{'graph'}->add_vertex($node->id);
36 0 return;
37 0 };
38  
39 # Graph object.
40 0 $self->{'graph'} = undef;
41  
42 # Map::Tube object.
43 0 $self->{'tube'} = undef;
44  
45 # Process params.
46 0 set_params($self, @params);
47  
48 # Check Map::Tube object.
49 0 ▶ if (! defined $self->{'tube'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"tube"}) 0 0 0
50 0 err "Parameter 'tube' is required.";
51 }
52 0 ▶ if (! defined &UNIVERSAL::DOES) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &UNIVERSAL::DOES) 0 0 0
53 0 eval {
54 0 require UNIVERSAL::DOES;
55 };
56 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Map::Tube::Graph::EVAL_ERROR) 0 0 0
57 0 err 'Cannot load UNIVERSAL::DOES module.';
58 }
59 }
60 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
61 || ! $self->{'tube'}->DOES('Map::Tube')) {
62  
63 0 err "Parameter 'tube' must be 'Map::Tube' object.";
64 }
65  
66 # Graph object.
67 0 ▶ if (! defined $self->{'graph'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"graph"}) 0 0 0
68 0 $self->{'graph'} = Graph->new;
69 }
70  
71 # Object.
72 0 return $self;
73 }
74  
75 # Get graph.
76 sub graph {
77 0 ▶ my $self = shift;
Subroutine graph: not called CC=5 SCAR=34.0
Pod documented
78 0 foreach my $node (values %{$self->{'tube'}->nodes}) {
79 0 $self->{'callback_vertex'}->($self, $node);
80 }
81 0 my @processed;
82 0 foreach my $node (values %{$self->{'tube'}->nodes}) {
83 0 foreach my $link (split m/,/ms, $node->link) {
84 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
85 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
86 ||
87 ($_->[0] eq $link && $_->[1] eq $node->id)
88 } @processed) {
89  
90 0 $self->{'callback_edge'}->($self, $node, $link);
91 0 push @processed, [$node->id, $link];
92 }
93 }
94 }
95 0 return $self->{'graph'};
96 }
97  
98 3 1;
99  
100 __END__
↑ Summary