| 1 | package Graph::Maker::Lollipop; | ||||||||||||||||||||||||||||
| 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 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base qw/Graph::Maker/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Graph; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub init | ||||||||||||||||||||||||||||
| 12 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=13 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 2 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | my $n1 = delete($params{N1}); | |||||||||||||||||||||||||||
| 16 | 2 | my $n2 = delete($params{N2}); | |||||||||||||||||||||||||||
| 17 | 2 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||
| 18 | 2 | ▶ | croak "graph_maker must be a reference to a function that creates a Graph.\n" if $gm && ref($gm) ne 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$gm and ref $gm ne "CODE"
MC/DC0%0/2
$gm and ref $gm ne "CODE"
$gm
ref $gm ne "CODE"
Truth table33%1/3
A and B
A= $gmB= ref $gm ne "CODE"
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | $gm ||= sub { new Graph(@_); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub {
"Graph"->new(@_);
}
MC/DC0%0/2
$gm ||= sub {
"Graph"->new(@_);
}
$gm
sub {
"Graph"->new(@_);
}
Truth table33%1/3
A ||= B
A= $gmB= sub {
"Graph"->new(@_);
}
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | croak "n1 must be defined and greater than 1\n" unless defined $n1 && $n1 >= 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $n1 and $n1 >= 2
MC/DC0%0/2
defined $n1 and $n1 >= 2
defined $n1
$n1 >= 2
Truth table33%1/3
A and B
A= defined $n1B= $n1 >= 2
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | croak "n2 must be defined and positive\n" unless defined $n2 && $n2 >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $n2 and $n2 >= 0
MC/DC0%0/2
defined $n2 and $n2 >= 0
defined $n2
$n2 >= 0
Truth table33%1/3
A and B
A= defined $n2B= $n2 >= 0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | my $g = $gm->(%params); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Left | ||||||||||||||||||||||||||||
| 27 | 2 | for my $u(1..$n1) | |||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 8 | ▶ | my $min = $g->is_directed() ? 1 : $u+1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 8 | for my $v($min..$n1) | |||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 22 | ▶ | next if $u == $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 18 | $g->add_edge($u, $v); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | # Bar | ||||||||||||||||||||||||||||
| 37 | 2 | $g->add_path($n1..$n1+$n2); | |||||||||||||||||||||||||||
| 38 | 2 | ▶ | $g->add_path(reverse $n1..$n1+$n2) if $g->is_directed(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | return $g; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | Graph::Maker->add_factory_type( 'lollipop' => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | 1; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | __DATA__ | ||||||||||||||||||||||||||||