Line.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 12 / 12 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 95.2% 80 / 84 CC 18 SCAR 26.2
CC
18
Cov
97%
new
18.0
BEGIN
1.0
BEGIN
1.0
CRAP 13.8
↑ Summary Line/SelfLoopVertex.pm »
1 package Graph::Line;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use parent 'Graph::Undirected';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use Graph::Line::SelfLoopVertex;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Graph::Undirected;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Generate line graphs
13 6 our $VERSION = '0.1.0'; # VERSION
14  
15 sub new
16 9 ▶{
Subroutine new: called CC=18 SCAR=28.9
Pod documented
17 9 my( $class, $graph, $options ) = @_;
18  
19 9 ▶ if( !blessed $graph || !$graph->isa( Graph::Undirected:: ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($graph) and $graph->isa("Graph::Undirected")) 1 8 9
Condition66%2/3
builtin::blessed($graph) and $graph->isa("Graph::Undirected")
!ll&&!rl&&r
018
MC/DC50%1/2
builtin::blessed($graph) and $graph->isa("Graph::Undirected")
builtin::blessed($graph) $graph->isa("Graph::Undirected")
Truth table66%2/3
A and B
A= builtin::blessed($graph)B= $graph->isa("Graph::Undirected")
ABresult
0X0
100
111
20 1 die 'only Graph::Undirected and its derivatives accepted' . "\n";
21 }
22  
23 8 ▶ $options = {} unless $options;
Branch: 1 branch
BranchTrueFalseTotal
unless $options 6 2 8
24  
25 # Collect all edges prior to converting them to vertices:
26 8 my @originals;
27 my @new_vertices;
28 8 ▶ if( $graph->is_multiedged ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph->is_multiedged) { } 4 4 8
29 4 for my $unique_edge ($graph->unique_edges) {
30 4 for my $edge ($graph->get_multiedge_ids( @$unique_edge )) {
31 9 push @originals, $unique_edge;
32 9 ▶ push @new_vertices,
Condition50%1/2
$graph->get_edge_attributes_by_id(@$unique_edge, $edge) || {}
l!l
90
MC/DC0%0/1
$graph->get_edge_attributes_by_id(@$unique_edge, $edge) || {}
$graph->get_edge_attributes_by_id(@$unique_edge, $edge)
Truth table50%1/2
A
A= $graph->get_edge_attributes_by_id(@$unique_edge, $edge)
Aresult
11
00
33 $graph->get_edge_attributes_by_id( @$unique_edge,
34 $edge ) || {};
35 }
36 }
37 } else {
38 # Have to do this in for cycle to maintain relation between the
39 # parallel arrays:
40 4 for my $edge ($graph->edges) {
41 10 push @originals, $edge;
42 10 ▶ push @new_vertices,
Condition100%2/2
$graph->get_edge_attributes(@$edge) || {}
l!l
28
MC/DC100%1/1
$graph->get_edge_attributes(@$edge) || {}
$graph->get_edge_attributes(@$edge)
Truth table100%2/2
A
A= $graph->get_edge_attributes(@$edge)
Aresult
11
00
43 $graph->get_edge_attributes( @$edge ) || {};
44 }
45 }
46  
47 # Collect adjacent edges for every vertice
48 8 my $adjacency = {};
49 8 for my $i (0..$#originals) {
50 19 push @{$adjacency->{$originals[$i]->[0]}}, $new_vertices[$i];
51  
52 # Self-loops have to be detected and not added once again
53 19 ▶ next if $originals[$i]->[0] eq $originals[$i]->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $originals[$i][0] eq $originals[$i][1] 3 16 19
54  
55 16 push @{$adjacency->{$originals[$i]->[1]}}, $new_vertices[$i];
56 }
57  
58 # Create the line graph
59 8 my $line_graph = Graph::Undirected->new;
60 8 $line_graph->add_vertices( @new_vertices );
61 8 for my $vertex (sort keys %$adjacency) {
62 20 for my $i (0..$#{$adjacency->{$vertex}}-1) {
63 15 for my $j ($i+1..$#{$adjacency->{$vertex}}) {
64 $line_graph->set_edge_attribute( $adjacency->{$vertex}[$i],
65 17 $adjacency->{$vertex}[$j],
66 'original_vertex',
67 $vertex );
68 }
69 }
70 }
71  
72 # Add self-loops for end vertices if requested
73 8 ▶ if( $options->{loop_end_vertices} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"loop_end_vertices"}) 2 6 8
74 2 for my $vertex ($graph->vertices) {
75 5 ▶ next if $graph->degree( $vertex ) != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $graph->degree($vertex) != 1 3 2 5
76 # Adjacency matrix will only have one item
77 2 $line_graph->set_edge_attribute( $adjacency->{$vertex}[0],
78 Graph::Line::SelfLoopVertex->new,
79 'original_vertex',
80 $vertex );
81 }
82 }
83  
84 8 return bless $line_graph, $class;
85 }
86  
87 6 1;
88  
89 __END__
↑ Summary Line/SelfLoopVertex.pm »