| 1 | package PMLTQ::Relation; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 22 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 22 | $PMLTQ::Relation::VERSION = '1.5.0'; | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$name and $schema and $node_type
$name and $schema
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$rel and exists $rel->{"iterator_class"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return $rel && $rel->{iterator_weight}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$rel && $rel->{'iterator_weight'}
MC/DC0%0/2
$rel && $rel->{'iterator_weight'}
$rel
$rel->{'iterator_weight'}
Truth table0%0/3
A && B
A= $relB= $rel->{'iterator_weight'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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}
MC/DC0%0/2
$rel && $rel->{$label}
$rel
$rel->{$label}
Truth table0%0/3
A && B
A= $relB= $rel->{$label}
| |||||||||||||||||||||||||||||||||||||||||||
| 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'}
MC/DC0%0/2
$rel && $rel->{'reversed_relation'}
$rel
$rel->{'reversed_relation'}
Truth table0%0/3
A && B
A= $relB= $rel->{'reversed_relation'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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'}
MC/DC0%0/2
$rel && $rel->{'test_code'}
$rel
$rel->{'test_code'}
Truth table0%0/3
A && B
A= $relB= $rel->{'test_code'}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 22 | 1; # End of PMLTQ::Relation | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||||||||||||||||