PML/Schema/Seq.pm

filter: Statementstmt 44.8% 39 / 87 Branchbran 13.3% 4 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 65.2% 15 / 23 Podpod 92.8% 13 / 14 totaltotal 43.2% 71 / 164 CC 19 SCAR 44.9
CC
19
Cov
35%
validate_object
240.0
get_element_names
6.0
get_element_by_name
2.0
CRAP 89.0
« PML/Schema/Derive.pm ↑ Summary PML/IO.pm »
1 package Treex::PML::Schema::Seq;
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  
13 9 ▶use Treex::PML::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use base qw( Treex::PML::Schema::Decl );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use UNIVERSAL::DOES;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 Treex::PML::Schema::Seq - implements declaration of a sequence.
20  
21 =head1 INHERITANCE
22  
23 This class inherits from L<Treex::PML::Schema::Decl>.
24  
25 =head1 METHODS
26  
27 See the super-class for the complete list.
28  
29 =over 3
30  
31 =item $decl->get_decl_type ()
32  
33 Returns the constant PML_SEQUENCE_DECL.
34  
35 =item $decl->get_decl_type_str ()
36  
37 Returns the string 'sequence'.
38  
39 =item $decl->is_mixed ()
40  
41 Return 1 if the sequence allows text content, otherwise
42 return 0.
43  
44 =item $decl->is_atomic ()
45  
46 Returns 0.
47  
48 =item $decl->get_content_decl ()
49  
50 Returns undef.
51  
52 =item $decl->get_content_pattern ()
53  
54 Return content pattern associated with the declaration (if
55 any). Content pattern specifies possible ordering and occurences of
56 elements in DTD-like content-model grammar.
57  
58 =cut
59  
60 0 ▶sub is_atomic { 0 }
Subroutine is_atomic: not called CC=1 SCAR=6.9
Pod documented
61 452 ▶sub get_decl_type { return PML_SEQUENCE_DECL; }
Subroutine get_decl_type: called CC=1 SCAR=0.0
Pod documented
62 0 ▶sub get_decl_type_str { return 'sequence'; }
Subroutine get_decl_type_str: not called CC=1 SCAR=6.9
Pod documented
63 0 ▶sub get_content_decl { return(undef); }
Subroutine get_content_decl: not called CC=1 SCAR=6.9
Pod documented
64 123 ▶sub is_mixed { return $_[0]->{text} ? 1 : 0 }
Subroutine is_mixed: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'text'} ? : 5 118 123
65 41 ▶sub get_content_pattern {
Subroutine get_content_pattern: called CC=1 SCAR=0.0
Pod documented
66 41 return $_[0]->{content_pattern};
67 }
68  
69 90 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
70 90 my ($self,$opts)=@_;
71 90 $self->{-parent}{-decl} = 'sequence';
72 }
73  
74 =item $decl->get_elements ()
75  
76 Return a list of element declarations (C<Treex::PML::Schema::Element>).
77  
78 =cut
79  
80 42 ▶sub get_elements {
Subroutine get_elements: called CC=2 SCAR=7.0
Pod documented
81 42 my $members = $_[0]->{element};
82 42 ▶ return $members ? map { $_->[0] } sort { $a->[1]<=> $b->[1] } map { [ $_, $_->{'-#'} ] } values %$members : ();
Branch: 1 branch
BranchTrueFalseTotal
$members ? : 42 0 42
83 }
84  
85 =item $decl->get_element_names ()
86  
87 Return a list of names of elements declared for the sequence.
88  
89 =cut
90  
91 0 ▶sub get_element_names {
Subroutine get_element_names: not called CC=2 SCAR=17.9
Pod documented
92 0 my $members = $_[0]->{element};
93 0 ▶ return $members ? map { $_->[0] } sort { $a->[1]<=> $b->[1] } map { [ $_, $members->{$_}->{'-#'} ] } keys %$members : ();
Branch: 1 branch
BranchTrueFalseTotal
$members ? : 0 0 0
94 }
95  
96 =item $decl->get_element_by_name (name)
97  
98 Return the declaration of the element with a given name.
99  
100 =cut
101  
102 163 ▶sub get_element_by_name {
Subroutine get_element_by_name: called CC=2 SCAR=7.1
Pod documented
103 163 my ($self, $name) = @_;
104 163 my $members = $_[0]->{element};
105 163 ▶ return $members ? $members->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$members ? : 163 0 163
106 }
107  
108 =item $decl->find_elements_by_content_decl
109  
110 Lookup and return those element declarations whose content declaration
111 is decl.
112  
113 =cut
114  
115 0 ▶sub find_elements_by_content_decl {
Subroutine find_elements_by_content_decl: not called CC=1 SCAR=6.9
Pod documented
116 0 my ($self, $decl) = @_;
117 0 return grep { $decl == $_->get_content_decl } $self->get_elements;
118 }
119  
120 =item $decl->find_elements_by_type_name
121  
122 Lookup and return those element declarations whose content is
123 specified via a reference to the named type with a given name.
124  
125 =cut
126  
127  
128 0 ▶sub find_elements_by_type_name {
Subroutine find_elements_by_type_name: not called CC=1 SCAR=6.9
Pod documented
129 0 my ($self, $type_name) = @_;
130 # using directly $member->{type}
131 0 return grep { $type_name eq $_->{type} } $self->get_elements;
132 }
133  
134 =item $decl->find_elements_by_role
135  
136 Lookup and return declarations of all elements with a given role.
137  
138 =cut
139  
140 0 ▶sub find_elements_by_role {
Subroutine find_elements_by_role: not called CC=1 SCAR=6.9
Pod documented
141 0 my ($self, $role) = @_;
142 # using directly $member->{role}
143 0 return grep { $role eq $_->{role} } $self->get_elements;
144 }
145  
146 0 ▶sub validate_object {
Subroutine validate_object: not called CC=15 SCAR=54.8
Pod documented
147 0 my ($self, $object, $opts) = @_;
148  
149 0 my ($path,$tag,$flags);
150 0 my $log = [];
151 0 ▶ if (ref($opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts) 0 0 0
152 0 $flags = $opts->{flags};
153 0 $path = $opts->{path};
154 0 $tag = $opts->{tag};
155 0 ▶ $path.="/".$tag if $tag ne q{};
Branch: 1 branch
BranchTrueFalseTotal
if $tag ne "" 0 0 0
156 }
157  
158 0 ▶ if (UNIVERSAL::DOES::does($object,'Treex::PML::Seq')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::DOES::does($object, 'Treex::PML::Seq')) { } 0 0 0
159 0 my $i = 0;
160 0 foreach my $element ($object->elements) {
161 0 $i++;
162 0 ▶ if (!UNIVERSAL::isa($element,'ARRAY')) {
Branch: 2 branches
BranchTrueFalseTotal
if (not UNIVERSAL::isa($element, 'ARRAY')) { } 0 0 0
elsif ($element->[0] eq '#TEXT') { } 0 0 0
163 0 push @$log, "$path: invalid sequence content: ",ref($element);
164 } elsif ($element->[0] eq '#TEXT') {
165 0 ▶ if ($self->is_mixed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_mixed) { } 0 0 0
166 0 ▶ if (ref($element->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $element->[1]) 0 0 0
167 0 push @$log, "$path: expected CDATA, got: ",ref($element->[1]);
168 }
169 } else {
170 0 push @$log, "$path: text node not allowed here\n";
171 }
172 } else {
173 0 my $ename = $element->[0];
174 0 my $edecl = $self->get_element_by_name($ename);
175 # KNIT on elements not supported yet
176 0 ▶ if ($edecl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edecl) { } 0 0 0
177 0 $edecl->validate_object($element->[1],{
178 flags => $flags,
179 path => $path,
180 tag => "[$i]",
181 log => $log,
182 });
183 } else {
184 0 push @$log, "$path: undefined element '$ename'";
185 }
186 }
187 0 my $content_pattern = $self->get_content_pattern;
188 0 ▶ if ($content_pattern and !$object->validate($content_pattern)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_pattern and not $object->validate($content_pattern)) 0 0 0
Condition0%0/3
$content_pattern and not $object->validate($content_pattern)
!ll&&!rl&&r
000
MC/DC0%0/2
$content_pattern and not $object->validate($content_pattern)
$content_pattern not $object->validate($content_pattern)
Truth table0%0/3
A and not(B)
A= $content_patternB= not $object->validate($content_pattern)
ABresult
0X0
100
111
189 0 push @$log, "$path: sequence content (".join(",",$object->names).") does not follow the pattern ".$content_pattern;
190 }
191 }
192 } else {
193 0 push @$log, "$path: unexpected content of a sequence: $object";
194 }
195 0 ▶ if ($opts and ref($opts->{log})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts and ref $opts->{"log"}) 0 0 0
Condition0%0/3
$opts and ref $opts->{"log"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts and ref $opts->{"log"}
$opts ref $opts->{"log"}
Truth table0%0/3
A and B
A= $optsB= ref $opts->{"log"}
ABresult
0X0
100
111
196 0 push @{$opts->{log}}, @$log;
197 }
198 0 ▶ return @$log ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@$log ? : 0 0 0
199 }
200  
201 =back
202  
203 =cut
204  
205  
206 9 1;
207 __END__
« PML/Schema/Derive.pm ↑ Summary PML/IO.pm »