File Coverage

blib/lib/Treex/PML/Schema/Alt.pm
Criterion Covered Total %
statement 25 50 50.0
branch 0 14 0.0
condition 0 6 0.0
subroutine 10 14 71.4
pod 5 6 83.3
total 40 90 44.4


line stmt bran cond sub pod time code
1             package Treex::PML::Schema::Alt;
2              
3 6     6   38 use strict;
  6         12  
  6         153  
4 6     6   26 use warnings;
  6         11  
  6         143  
5              
6 6     6   27 use vars qw($VERSION);
  6         11  
  6         236  
7             BEGIN {
8 6     6   143 $VERSION='2.24'; # version template
9             }
10 6     6   33 no warnings 'uninitialized';
  6         10  
  6         204  
11 6     6   39 use Carp;
  6         11  
  6         276  
12              
13 6     6   41 use Treex::PML::Schema::Constants;
  6         10  
  6         503  
14 6     6   34 use base qw( Treex::PML::Schema::Decl );
  6         9  
  6         3217  
15              
16             =head1 NAME
17              
18             Treex::PML::Schema::Alt - implements declaration of an alternative (alt).
19              
20             =head1 INHERITANCE
21              
22             This class inherits from L.
23              
24             =head1 METHODS
25              
26             See the super-class for the complete list.
27              
28             =over 3
29              
30             =item $decl->get_decl_type ()
31              
32             Returns the constant PML_ALT_DECL.
33              
34             =item $decl->get_decl_type_str ()
35              
36             Returns the string 'alt'.
37              
38             =item $decl->get_content_decl ()
39              
40             Return type declaration of the list members.
41              
42             =item $decl->is_flat ()
43              
44             Return 1 for ``flat'' alternatives, otherwise return 0. (Flat
45             alternatives are not part of PML specification, but are used for
46             translating attribute values from C.)
47              
48             =item $decl->is_atomic ()
49              
50             Returns 0.
51              
52             =back
53              
54             =cut
55              
56 0     0 1 0 sub is_atomic { 0 }
57 73     73 1 146 sub get_decl_type { return PML_ALT_DECL; }
58 0     0 1 0 sub get_decl_type_str { return 'alt'; }
59 0     0 1 0 sub is_flat { return $_[0]->{-flat} }
60             sub init {
61 10     10 0 33 my ($self,$opts)=@_;
62 10         42 $self->{-parent}{-decl} = 'alt';
63             }
64              
65             sub validate_object {
66 0     0 1   my ($self, $object, $opts) = @_;
67              
68 0           my ($path,$tag,$flags);
69 0           my $log = [];
70 0 0         if (ref($opts)) {
71 0           $flags = $opts->{flags};
72 0           $path = $opts->{path};
73 0           $tag = $opts->{tag};
74 0 0         $path.="/".$tag if $tag ne q{};
75             }
76 0           my $am_decl = $self->get_content_decl;
77 0 0 0       if ($self->is_flat) {
    0          
78             # flat alternative:
79 0 0         if (ref($object)) {
80 0           push @$log, "$path: flat alternative is supposed to be a string: $object";
81             } else {
82 0           my $i = 1;
83 0           foreach my $val (split /\|/,$object) {
84 0           $am_decl->validate_object($val, {
85             flags => $flags,
86             path=> $path,
87             tag => "[".($i++)."]",
88             log => $log,
89             });
90             }
91             }
92             } elsif (ref($object) and UNIVERSAL::DOES::does($object,'Treex::PML::Alt')) {
93 0           for (my $i=0; $i<@$object; $i++) {
94 0           $am_decl->validate_object($object->[$i], {
95             flags => $flags,
96             path=> $path,
97             tag => "[".($i+1)."]",
98             log => $log,
99             });
100             }
101             } else {
102 0           $am_decl->validate_object($object,{
103             flags => $flags,
104             path=>$path,
105             # tag => "[1]", # TrEdNodeEdit would very much like [1] here
106             log => $log});
107             }
108 0 0 0       if ($opts and ref($opts->{log})) {
109 0           push @{$opts->{log}}, @$log;
  0            
110             }
111 0 0         return @$log ? 0 : 1;
112             }
113              
114              
115             1;
116             __END__