blib/lib/PMLTQ/Relation.pm

filter: Statementstmt 59.6% 37 / 62 Branchbran 28.5% 4 / 14 Conditioncond 9.5% 2 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 56.2% 9 / 16 Podpod 0.0% 0 / 8 totaltotal 38.8% 52 / 134 CC 17 SCAR 17.3
CC
17
Cov
44%
create_iterator
12.0
iterator_weight
12.0
relations_for_node_type
6.0
CRAP 5.6
« blib/lib/PMLTQ/Relation/TreeIterator.pm ↑ Summary blib/lib/PMLTQ/Loader.pm »
1 package PMLTQ::Relation;
2 22 our $AUTHORITY = 'cpan:MATY';
3 22 $PMLTQ::Relation::VERSION = '1.2.2';
4 # ABSTRACT: Base class for all Relations standard or user defined
5  
6 22 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶use PMLTQ::Loader qw/find_modules load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 22 my %user_defined;
14 my %start_to_target_type_map;
15  
16 22 our @RELATIONS;
17  
18 sub load {
19 13 ▶ return if (@RELATIONS);
Subroutine load: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if @PMLTQ::Relation::RELATIONS 2 11 13
20  
21 11 @RELATIONS = find_modules('PMLTQ::Relation');
22  
23 11 load_class($_) for (@RELATIONS);
24 }
25  
26 sub import {
27 144 ▶ my $class = shift;
Subroutine import: called CC=5 SCAR=17.8
28 144 for my $def (@_) {
29 128 my $name = $def->{name};
30 128 my $schema = $def->{schema};
31 128 my $node_type = $def->{start_node_type};
32  
33 128 ▶ next unless ( $name && $schema && $node_type ); # This will prevent from importing obsolete definitions
Branch: 1 branch
BranchTrueFalseTotal
unless $name and $schema and $node_type 0 128 128
Condition33%2/6
$name and $schema and $node_type
!ll&&!rl&&r
00128
$name and $schema
!ll&&!rl&&r
00128
MC/DC0%0/3
$name and $schema and $node_type
$name $schema $node_type
Truth table25%1/4
A and B and C
A= $nameB= $schemaC= $node_type
ABCresult
0XX0
10X0
1100
1111
34  
35 128 _relation( $schema, $node_type, $name, $def );
36 }
37 }
38  
39 sub _relation {
40 128 ▶ my ( $schema_name, $node_type, $name, $def ) = @_;
Subroutine _relation: called CC=2 SCAR=7.0
41 128 ▶ if ($def) {
Branch: 1 branch
BranchTrueFalseTotal
if ($def) 128 0 128
42 128 $user_defined{$schema_name}{$node_type}{$name} = $def;
43 128 $start_to_target_type_map{$schema_name}{$node_type}{$name} = $def->{target_node_type};
44 }
45 128 $user_defined{$schema_name}{$node_type}{$name};
46 }
47  
48 sub create_iterator {
49 0 ▶ my ( $class, $schema_name, $node_type, $label ) = ( shift, shift, shift, shift );
Subroutine create_iterator: not called CC=3 SCAR=24.8
Pod undocumented
50 0 my $rel = _relation( $schema_name, $node_type, $label );
51 0 ▶ if ( $rel and exists( $rel->{iterator_class} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel and exists $rel->{'iterator_class'}) { } 0 0 0
Condition0%0/3
$rel and exists $rel->{"iterator_class"}
!ll&&!rl&&r
000
MC/DC0%0/2
$rel and exists $rel->{"iterator_class"}
$rel exists $rel->{"iterator_class"}
Truth table0%0/3
A and B
A= $relB= exists $rel->{"iterator_class"}
ABresult
0X0
100
111
52 0 $rel->{iterator_class}->new(@_);
53 } else {
54 0 return;
55 }
56 }
57  
58 sub iterator_weight {
59 0 ▶ my ( $class, $schema_name, $node_type, $label ) = @_;
Subroutine iterator_weight: not called CC=3 SCAR=24.8
Pod undocumented
60 0 my $rel = _relation( $schema_name, $node_type, $label );
61 0 ▶ return unless $rel;
Branch: 1 branch
BranchTrueFalseTotal
unless $rel 0 0 0
62 0 ▶ return $rel && $rel->{iterator_weight};
Condition0%0/3
$rel && $rel->{'iterator_weight'}
!ll&&!rl&&r
000
MC/DC0%0/2
$rel && $rel->{'iterator_weight'}
$rel $rel->{'iterator_weight'}
Truth table0%0/3
A && B
A= $relB= $rel->{'iterator_weight'}
ABresult
0X0
100
111
63 }
64  
65 sub relations_for_node_type {
66 0 ▶ my ( $class, $schema_name, $start_type ) = @_;
Subroutine relations_for_node_type: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my $map = $start_to_target_type_map{$schema_name}{$start_type};
68 0 ▶ return $map ? [ sort keys %$map ] : [];
Branch: 1 branch
BranchTrueFalseTotal
$map ? : 0 0 0
69 }
70  
71 sub relations_for_schema {
72 0 ▶ my ( $class, $schema_name ) = @_;
Subroutine relations_for_schema: not called CC=2 SCAR=17.9
Pod undocumented
73  
74 0 my $map = $user_defined{$schema_name};
75 0 ▶ return $map ? [ map { values %$_ } values %$map ] : [];
Branch: 1 branch
BranchTrueFalseTotal
$map ? : 0 0 0
76 }
77  
78 sub target_type {
79 0 ▶ my ( $class, $schema_name, $start_type, $label ) = @_;
Subroutine target_type: not called CC=2 SCAR=17.9
Pod undocumented
80 0 my $rel = $start_to_target_type_map{$schema_name}{$start_type};
81 0 ▶ return $rel && $rel->{$label};
Condition0%0/3
$rel && $rel->{$label}
!ll&&!rl&&r
000
MC/DC0%0/2
$rel && $rel->{$label}
$rel $rel->{$label}
Truth table0%0/3
A && B
A= $relB= $rel->{$label}
ABresult
0X0
100
111
82 }
83  
84 sub reversed_relation {
85 0 ▶ my ( $class, $schema_name, $start_type, $name ) = @_;
Subroutine reversed_relation: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my $rel = _relation( $schema_name, $start_type, $name );
87 0 ▶ return $rel && $rel->{reversed_relation};
Condition0%0/3
$rel && $rel->{'reversed_relation'}
!ll&&!rl&&r
000
MC/DC0%0/2
$rel && $rel->{'reversed_relation'}
$rel $rel->{'reversed_relation'}
Truth table0%0/3
A && B
A= $relB= $rel->{'reversed_relation'}
ABresult
0X0
100
111
88 }
89  
90 sub test_code {
91 0 ▶ my ( $class, $schema_name, $start_type, $name ) = @_;
Subroutine test_code: not called CC=2 SCAR=17.9
Pod undocumented
92 0 my $rel = _relation( $schema_name, $start_type, $name );
93 0 ▶ return $rel && $rel->{test_code};
Condition0%0/3
$rel && $rel->{'test_code'}
!ll&&!rl&&r
000
MC/DC0%0/2
$rel && $rel->{'test_code'}
$rel $rel->{'test_code'}
Truth table0%0/3
A && B
A= $relB= $rel->{'test_code'}
ABresult
0X0
100
111
94 }
95  
96 22 1; # End of PMLTQ::Relation
97  
98 __END__
« blib/lib/PMLTQ/Relation/TreeIterator.pm ↑ Summary blib/lib/PMLTQ/Loader.pm »