| 1 | package Graph::Reader::TGF; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use base qw(Graph::Reader); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Encode qw(decode_utf8); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | our $VERSION = 0.04; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # Edge callback. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | sub _edge_callback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_edge_callback: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | my ($self, $graph, $id1, $id2, $edge_label) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | $graph->set_edge_attribute($id1, $id2, 'label', $edge_label); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # Init. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | my ($self, $param_hr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | $self->SUPER::_init(); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | if (exists $param_hr->{'edge_callback'} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $param_hr->{"edge_callback"} and defined $param_hr->{"edge_callback"} and ref $param_hr->{"edge_callback"} ne "CODE"
exists $param_hr->{"edge_callback"} and defined $param_hr->{"edge_callback"}
MC/DC100%3/3
exists $param_hr->{"edge_callback"} and defined $param_hr->{"edge_callback"} and ref $param_hr->{"edge_callback"} ne "CODE"
exists $param_hr->{"edge_callback"}
defined $param_hr->{"edge_callback"}
ref $param_hr->{"edge_callback"} ne "CODE"
Truth table100%4/4
A and B and C
A= exists $param_hr->{"edge_callback"}B= defined $param_hr->{"edge_callback"}C= ref $param_hr->{"edge_callback"} ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | && defined $param_hr->{'edge_callback'} | ||||||||||||||||||||||||||||||||||||||||||
| 25 | && ref $param_hr->{'edge_callback'} ne 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | err "Parameter 'edge_callback' isn't reference to code."; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | $self->{'edge_callback'} = $param_hr->{'edge_callback'}; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | if (exists $param_hr->{'vertex_callback'} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $param_hr->{"vertex_callback"} and defined $param_hr->{"vertex_callback"} and ref $param_hr->{"vertex_callback"} ne "CODE"
exists $param_hr->{"vertex_callback"} and defined $param_hr->{"vertex_callback"}
MC/DC100%3/3
exists $param_hr->{"vertex_callback"} and defined $param_hr->{"vertex_callback"} and ref $param_hr->{"vertex_callback"} ne "CODE"
exists $param_hr->{"vertex_callback"}
defined $param_hr->{"vertex_callback"}
ref $param_hr->{"vertex_callback"} ne "CODE"
Truth table100%4/4
A and B and C
A= exists $param_hr->{"vertex_callback"}B= defined $param_hr->{"vertex_callback"}C= ref $param_hr->{"vertex_callback"} ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | && defined $param_hr->{'vertex_callback'} | ||||||||||||||||||||||||||||||||||||||||||
| 32 | && ref $param_hr->{'vertex_callback'} ne 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | err "Parameter 'vertex_callback' isn't reference to code."; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | $self->{'vertex_callback'} = $param_hr->{'vertex_callback'}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # Read graph subroutine. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | sub _read_graph { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_graph: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | my ($self, $graph, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | my $vertexes = 1; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | while (my $line = decode_utf8(<$fh>)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 24 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # End of vertexes section. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 24 | ▶ | if ($line =~ m/^#/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | $vertexes = 0; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # Vertexes. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 18 | ▶ | if ($vertexes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | my ($id, $vertex_label) = split m/\s+/ms, $line, 2; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | ▶ | if (! defined $vertex_label) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | $vertex_label = $id; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | $graph->add_vertex($id); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | if ($self->{'vertex_callback'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | $self->{'vertex_callback'}->($self, $graph, | |||||||||||||||||||||||||||||||||||||||||
| 62 | $id, $vertex_label); | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | $self->_vertex_callback($graph, $id, | |||||||||||||||||||||||||||||||||||||||||
| 65 | $vertex_label); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Edges. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 6 | my ($id1, $id2, $edge_label) = split m/\s+/ms, $line, 3; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | $graph->add_edge($id1, $id2); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | ▶ | if ($self->{'edge_callback'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | $self->{'edge_callback'}->($self, $graph, $id1, | |||||||||||||||||||||||||||||||||||||||||
| 74 | $id2, $edge_label); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | $self->_edge_callback($graph, $id1, $id2, | |||||||||||||||||||||||||||||||||||||||||
| 77 | $edge_label); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # Vertex callback. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 10 | ▶ | sub _vertex_callback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_vertex_callback: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | my ($self, $graph, $id, $vertex_label) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | $graph->set_vertex_attribute($id, 'label', $vertex_label); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||||||||||||||||