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