PML/Schema/Import.pm

filter: Statementstmt 87.1% 68 / 78 Branchbran 62.5% 20 / 32 Conditioncond 57.6% 34 / 59 MC/DCmcdc 16.0% 4 / 25 Subroutinesub 86.6% 13 / 15 Podpod 75.0% 3 / 4 totaltotal 66.6% 142 / 213 CC 41 SCAR 42.2
CC
41
Cov
72%
simplify
100.0
_import_type
4.1
get_decl_type
2.0
CRAP 67.9
« PML/Schema/Alt.pm ↑ Summary PML/Schema/Decl.pm »
1 package Treex::PML::Schema::Import;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 $VERSION='2.29'; # version template
9 }
10 9 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Treex::PML::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 ▶use base qw(Treex::PML::Schema::XMLNode);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub get_decl_type { return(PML_IMPORT_DECL); }
Subroutine get_decl_type: not called CC=1 SCAR=6.9
Pod documented
19 0 ▶sub get_decl_type_str { return('import'); }
Subroutine get_decl_type_str: not called CC=1 SCAR=6.9
Pod documented
20  
21 16 ▶sub schema {
Subroutine schema: called CC=2 SCAR=6.9
Pod undocumented
22 16 my ($self)=@_;
23 16 ▶ $self=$self->{-parent} while $self->{-parent};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"-parent"} and do { $self = $self->{"-parent"} } 17 16 33
24 16 return $self;
25 }
26  
27 16 ▶sub simplify {
Subroutine simplify: called CC=37 SCAR=46.1
Pod documented
28 16 my ($import,$opts)=@_;
29 16 my $target = $import->schema;
30 16 ▶ my $base_url = $target->{URL}||'';
Condition50%1/2
$target->{'URL'} || ''
l!l
160
MC/DC0%0/1
$target->{'URL'} || ''
$target->{'URL'}
Truth table50%1/2
A
A= $target->{'URL'}
Aresult
11
00
31 16 my $parent = $import->{-parent}; # FIXME: for templates
32 return if
33 ($parent->get_decl_type == PML_TEMPLATE_DECL and $opts->{no_template_import} or
34 16 ▶ $parent->get_decl_type == PML_SCHEMA_DECL and $opts->{no_import});
Branch: 1 branch
BranchTrueFalseTotal
if $parent->get_decl_type == 22 and $opts->{"no_template_import"} or $parent->get_decl_type == 14 and $opts->{"no_import"} 0 16 16
Condition55%5/9
$parent->get_decl_type == 22 and $opts->{"no_template_import"} or $parent->get_decl_type == 14 and $opts->{"no_import"}
l!l&&r!l&&!r
0016
$parent->get_decl_type == 22 and $opts->{"no_template_import"}
!ll&&!rl&&r
1510
$parent->get_decl_type == 14 and $opts->{"no_import"}
!ll&&!rl&&r
1150
MC/DC0%0/4
$parent->get_decl_type == 22 and $opts->{"no_template_import"} or $parent->get_decl_type == 14 and $opts->{"no_import"}
$parent->get_decl_type == 22 $opts->{"no_template_import"} $parent->get_decl_type == 14 $opts->{"no_import"}
Truth table28%2/7
A and B or C and D
A= $parent->get_decl_type == 22B= $opts->{"no_template_import"}C= $parent->get_decl_type == 14D= $opts->{"no_import"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
35 16 ▶ die "Missing 'schema' attribute on element <import> in $base_url!" unless $import->{schema};
Branch: 1 branch
BranchTrueFalseTotal
unless $import->{"schema"} 0 16 16
36  
37 16 ▶ $opts->{schemas}||={};
Condition50%1/2
$opts->{"schemas"} ||= {}
l!l
160
MC/DC0%0/1
$opts->{"schemas"} ||= {}
$opts->{"schemas"}
Truth table50%1/2
A
A= $opts->{"schemas"}
Aresult
11
00
38 16 my $url = URI->new(Encode::encode_utf8($import->{schema}));
39  
40 my $schema = ref($target)->new({
41 48 (map { ($_=>$opts->{$_}) } qw(schemas use_resources validate)),
42 filename => $url,
43 base_url => $base_url,
44 imported => 1,
45 (map {
46 16 ▶ exists($import->{$_}) ? ( $_ => $import->{$_} ) : ()
Branch: 1 branch
BranchTrueFalseTotal
exists $import->{$_} ? : 11 37 48
47 } qw(revision minimal_revision maximal_revision)),
48 revision_error => "Error importing schema %f to $base_url - revision mismatch: %e"
49 });
50 16 ▶ if ((!exists($import->{type}) and
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $import->{'type'} || exists $import->{'template'} || exists $import->{'root'} or defined $import->{'type'} and $import->{'type'} eq '*') { } 3 13 16
Condition58%7/12
not exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"} or defined $import->{"type"} and $import->{"type"} eq "*"
l!l&&r!l&&!r
3013
exists $import->{'type'} || exists $import->{'template'} || exists $import->{'root'}
l!l&&r!l&&!r
1303
exists $import->{"type"} or exists $import->{"template"}
l!l&&r!l&&!r
1303
defined $import->{"type"} and $import->{"type"} eq "*"
!ll&&!rl&&r
0130
MC/DC20%1/5
not exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"} or defined $import->{"type"} and $import->{"type"} eq "*"
exists $import->{"type"} exists $import->{"template"} exists $import->{'root'} defined $import->{"type"} $import->{"type"} eq "*"
Truth table20%2/10
not(A or B || C) or D and E
A= exists $import->{"type"}B= exists $import->{"template"}C= exists $import->{'root'}D= defined $import->{"type"}E= $import->{"type"} eq "*"
ABCDEresult
000XX1
1XX111
01X111
001111
1XX0X0
1XX100
01X0X0
01X100
0010X0
001100
51 !exists($import->{template}) and
52 !exists($import->{root})
53 ) or defined($import->{type}) and $import->{type} eq '*') {
54 # print STDERR "IMPORTING *\n";
55 3 ▶ if (ref $schema->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"type"}) 3 0 3
56 3 ▶ $parent->{type}||={};
Condition100%2/2
$parent->{"type"} ||= {}
l!l
21
MC/DC100%1/1
$parent->{"type"} ||= {}
$parent->{"type"}
Truth table100%2/2
A
A= $parent->{"type"}
Aresult
11
00
57 3 foreach my $name (keys(%{$schema->{type}})) {
58 16 ▶ unless (exists $parent->{type}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $parent->{"type"}{$name}) 16 0 16
59 16 $parent->{type}{$name}=$parent->copy_decl($schema->{type}{$name});
60 }
61 }
62 }
63 } else {
64 13 my $name = $import->{type};
65 # print STDERR "IMPORTING $name\n";
66 13 ▶ if (ref($schema->{type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"type"}) 13 0 13
67 13 $import->_import_type($parent,$schema,$name);
68 }
69 }
70 16 ▶ if ((!exists($import->{type}) and
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $import->{'type'} || exists $import->{'template'} || exists $import->{'root'} or defined $import->{'template'} and $import->{'template'} eq '*') { } 3 13 16
Condition58%7/12
not exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"} or defined $import->{"template"} and $import->{"template"} eq "*"
l!l&&r!l&&!r
3013
exists $import->{'type'} || exists $import->{'template'} || exists $import->{'root'}
l!l&&r!l&&!r
1303
exists $import->{"type"} or exists $import->{"template"}
l!l&&r!l&&!r
1303
defined $import->{"template"} and $import->{"template"} eq "*"
!ll&&!rl&&r
1300
MC/DC20%1/5
not exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"} or defined $import->{"template"} and $import->{"template"} eq "*"
exists $import->{"type"} exists $import->{"template"} exists $import->{'root'} defined $import->{"template"} $import->{"template"} eq "*"
Truth table20%2/10
not(A or B || C) or D and E
A= exists $import->{"type"}B= exists $import->{"template"}C= exists $import->{'root'}D= defined $import->{"template"}E= $import->{"template"} eq "*"
ABCDEresult
000XX1
1XX111
01X111
001111
1XX0X0
1XX100
01X0X0
01X100
0010X0
001100
71 !exists($import->{template}) and
72 !exists($import->{root})
73 ) or defined($import->{template}) and $import->{template} eq '*') {
74 3 ▶ if (ref $schema->{template}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"template"}) 0 3 3
75 0 ▶ $parent->{template}||={};
Condition0%0/2
$parent->{"template"} ||= {}
l!l
00
MC/DC0%0/1
$parent->{"template"} ||= {}
$parent->{"template"}
Truth table0%0/2
A
A= $parent->{"template"}
Aresult
11
00
76 0 foreach my $name (keys(%{$schema->{template}})) {
77 0 ▶ unless (exists $parent->{template}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $parent->{"template"}{$name}) 0 0 0
78 0 $parent->{template}{$name}=$parent->copy_decl($schema->{template}{$name});
79 }
80 }
81 }
82 } else {
83 13 my $name = $import->{template};
84 13 ▶ if (ref($schema->{template})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"template"}) 0 13 13
85 0 ▶ unless (exists $parent->{template}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $parent->{"template"}{$name}) 0 0 0
86 0 $parent->{template}{$name}=$parent->copy_decl($schema->{template}{$name});
87 }
88 }
89 }
90 16 ▶ if (((!exists($import->{type}) and
Branch: 1 branch
BranchTrueFalseTotal
if (!(exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"}) || defined $import->{"root"} && $import->{"root"} eq 1 and not exists $parent->{"root"} and $schema->{"root"}) 3 13 16
Condition61%11/18
!(exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"}) || defined $import->{"root"} && $import->{"root"} eq 1 and not exists $parent->{"root"} and $schema->{"root"}
!ll&&!rl&&r
1303
!(exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"}) || defined $import->{"root"} && $import->{"root"} eq 1 and not exists $parent->{"root"}
!ll&&!rl&&r
1303
not exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"} or defined $import->{"root"} and $import->{"root"} eq 1
l!l&&r!l&&!r
3013
exists $import->{'type'} || exists $import->{'template'} || exists $import->{'root'}
l!l&&r!l&&!r
1303
exists $import->{"type"} or exists $import->{"template"}
l!l&&r!l&&!r
1303
defined $import->{"root"} and $import->{"root"} eq 1
!ll&&!rl&&r
1300
MC/DC14%1/7
!(exists $import->{"type"} || exists $import->{"template"} || exists $import->{"root"}) || defined $import->{"root"} && $import->{"root"} eq 1 and not exists $parent->{"root"} and $schema->{"root"}
exists $import->{"type"} exists $import->{"template"} exists $import->{'root'} defined $import->{"root"} $import->{"root"} eq 1 not exists $parent->{"root"} $schema->{"root"}
Truth table11%2/18
not(A or B || C) or D and E and not(F) and G
A= exists $import->{"type"}B= exists $import->{"template"}C= exists $import->{'root'}D= defined $import->{"root"}E= $import->{"root"} eq 1F= not exists $parent->{"root"}G= $schema->{"root"}
ABCDEFGresult
1XX0XXX0
1XX10XX0
01X0XXX0
01X10XX0
0010XXX0
00110XX0
000XX0X0
1XX110X0
01X110X0
001110X0
000XX100
1XX11100
01X11100
00111100
000XX111
1XX11111
01X11111
00111111
91 !exists($import->{template}) and
92 !exists($import->{root})
93 ) or defined($import->{root}) and $import->{root} eq '1') and !exists($parent->{root}) and $schema->{root}) {
94 3 $parent->{root} = $parent->copy_decl($schema->{root});
95 }
96 16 return $schema;
97 }
98  
99 13 ▶sub _import_type {
Subroutine _import_type: called CC=4 SCAR=14.0
100 13 my ($self,$target,$src_schema, $name) = @_;
101 13 ▶ unless (exists $src_schema->{type}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $src_schema->{"type"}{$name}) 0 13 13
102 0 croak "Cannot import type '$name' from '$src_schema->{URL}' to '$target->{URL}': type not declared in the source schema\n";
103 }
104 13 my $type = $src_schema->{type}{$name};
105 13 my %referred = ($name => $type);
106 13 $src_schema->_get_referred_types($type,\%referred);
107 13 foreach my $n (keys %referred) {
108 22 ▶ unless (exists $target->{type}{$n}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $target->{'type'}{$n}) { } 4 18 22
109 18 $target->{type}{$n}=$target->copy_decl($referred{$n});
110 } else {
111 # print STDERR "already there\n";
112 }
113 }
114 }
115  
116  
117 9 1;
118 __END__
« PML/Schema/Alt.pm ↑ Summary PML/Schema/Decl.pm »