This file is indexed.

/usr/share/perl5/XML/Doctype/ElementDecl.pm is in libxml-autowriter-perl 0.40-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package XML::Doctype::ElementDecl ;

=head1 NAME

XML::Doctype::ElementDecl - A class representing an <!ELEMENT> tag

=head1 SYNOPSIS

   $elt = $dtd->element( 'foo' ) ;
   $elt->name() ;
   $elt->attr( 'foo' ) ;

=head1 DESCRIPTION

This module is used to represent <!ELEMENT> tags in an XML::Doctype object.
It contains <!ATTLIST> tags as well.

=head1 STATUS

This module is alpha code.  It's developed enough to support XML::ValidWriter,
but need a lot of work.  Some big things that are lacking are:

=cut

use strict ;
use vars qw( $VERSION %_default_dtds ) ;
use fields (
   'ATTDEFS',
   'CONTENT',   # 'EMPTY', 'ANY' or a regexp.  undef if ! is_declared().
   'DECLARED',
   'NAME',
   'NAMES',
   'PATHS',     # A hash which XML::ValidWriter uses to cache the paths
                # it finds from this element name to possible child elements.
   'TODO',      # A list of children that XML::ValidWriter has not yet
                # explored for possible inclusion in PATHS.
) ;

use Carp ;
use UNIVERSAL qw( isa ) ;

$VERSION = 0.1 ;

=head1 METHODS

=over

=item new

   # Undefined element constructors:
   $dtd = XML::Doctype::ElementDecl->new( $name ) ;
   $dtd = XML::Doctype::ElementDecl->new( $name, undef, \@attdefs ) ;

   # Defined element constructors
   $dtd = XML::Doctype::ElementDecl->new( $name, \@kids, \@attdef ) ;
   $dtd = XML::Doctype::ElementDecl->new( $name, [], \@attdefs ) ;

=cut

sub _assemble_re {
   ## Convert the tree of XML::Parser::ContentModel instances to a
   ## regular expression and accumulate a HASH of element names in
   ## NAMES.  This hash is later converted to an ARRAY.
   my XML::Doctype::ElementDecl $self = shift ;
   my ( $cp ) = @_ ;

   if ( $cp->isname ) {
      return '(?:#PCDATA)*' if $cp->name eq '#PCDATA' ;
      ${$self->{NAMES}->{$cp->name}} = 1 ;
      return join( '', '<', quotemeta $cp->name, '>' ) unless $cp->quant ;
   }
   
   return join( '', map $self->_assemble_re( $_ ), $cp->children )
      if $cp->isseq && ! $cp->quant ;

   return join( '',
      '(?:',
      $cp->isname
         ? ( '<', quotemeta( $cp->name ), '>' )
      : $cp->isseq
         ? join( '',  map $self->_assemble_re( $_ ), $cp->children )
      : $cp->ischoice
         ? join( '|', map $self->_assemble_re( $_ ), $cp->children )
      : $cp->ismixed
         ? join(
	    '|',
	    '(?:#PCDATA)?',
	    map(
	       defined $_ ? $self->_assemble_re( $_ ) : (),
	       $cp->children
	    )
	 )
      : (),
      ')',
      $cp->quant || ()
   ) ;

}

sub new {
   my XML::Doctype::ElementDecl $self = fields::new( shift );

   my $cm ; # The XML::Expat::ContentModel object for this DECL.
   ( $self->{NAME}, $cm, $self->{ATTDEFS} ) = @_ ;

   if ( $cm ) {
      if ( $cm->isany ) {
	 $self->{CONTENT} = 'ANY' ;
	 $self->{NAMES} = [] ;
      }
      elsif ( $cm->isempty ) {
	 $self->{CONTENT} = 'EMPTY' ;
	 $self->{NAMES} = [] ;
      }
      elsif ( $cm->ismixed || $cm->isseq || $cm->ischoice ) {
	 $self->{NAMES} = {} ;
	 my $re = $self->_assemble_re( $cm ) ;
	 $self->{CONTENT} = "^$re\$" ; # qr/^$re$/ ;
	 $self->{NAMES} = [ $self->{NAMES} ? keys %{$self->{NAMES}} : () ] ;
      }
      else {
	 croak "'$cm' passed for a content model" ;
      }
   }
   else {
      $self->{NAMES} = [] ;
   }

   return $self ;
}


sub _freeze {
   my $self = shift ;
   if ( defined $self->{CONTENT} && ref $self->{CONTENT} eq 'Regexp' ) {
      ## need two assigns to really, really divorce the SV from the
      ## quircky-half-object RegExp type.
      $self->{CONTENT} = '' ;
      $self->{CONTENT} = "$self->{CONTENT}" ;
   }
}


=item add_attdef

   $elt_decl->add_attdef( $att_def ) ;

=cut

sub add_attdef {
   my XML::Doctype::ElementDecl $self = shift ;
   my ( $attdef ) = @_ ;
   $self->{ATTDEFS}->{$attdef->name} = $attdef ;
}
  

=item attdef

   $attr = $elt->attdef( $name ) ;

Returns the XML::Doctype::AttDef named by $name or undef if there is no
such attribute.

=cut

sub attdef {
   my XML::Doctype::ElementDecl $self = shift ;
   my ( $name ) = @_ ;

   return $self->{ATTDEFS}->{$name} if exists $self->{ATTDEFS}->{$name} ;
   return ;
}


=item attdefs

   $attdefs = $elt->attdefs( $name ) ;

Returns the list of XML::Doctype::AttDef instances associated with this
element.

=cut

sub attdefs {
   my XML::Doctype::ElementDecl $self = shift ;
   my ( $name ) = @_ ;

   return $self->{ATTDEFS} ? values %{$self->{ATTDEFS}} : () ;
}


=item attribute_names

Returns a list of the attdefs' names.

=cut

sub attribute_names {
   my XML::Doctype::ElementDecl $self = shift ;

   return $self->{ATTDEFS} ? keys %{$self->{ATTDEFS}} : () ;
}


=item child_names

   @names = $elt->child_names ;

Returns a list of names of elements in this element decl's content model.

=cut

sub child_names {
   my XML::Doctype::ElementDecl $self = shift ;

   return @{$self->{NAMES}} ;
}


=item is_declared

   if ( $elt_decl->is_declared ) ...
   $elt_decl->is_declared( 1 ) ;

Returns TRUE if there is any data defined in the element other than name and
attributes or if is_declared has been set by calling is_declared( 1 ) or
passing DECLARED => 1 to new().

=cut

sub is_declared {
   my XML::Doctype::ElementDecl $self = shift ;

   $self->{DECLARED} = shift if @_ ;

   return $self->{DECLARED} || defined $self->{CONTENT} ;
}


=item is_empty

=cut

sub is_empty {
   my XML::Doctype::ElementDecl $self = shift ;

   return $self->{CONTENT} && $self->{CONTENT} eq 'EMPTY' ;
}


=item is_any

=cut

sub is_any {
   my XML::Doctype::ElementDecl $self = shift ;

   return $self->{CONTENT} && $self->{CONTENT} eq 'ANY' ;
}


=item is_mixed

=cut

sub is_mixed {
   my XML::Doctype::ElementDecl $self = shift ;

   return $self->{CONTENT} && $self->{CONTENT} =~ /#PCDATA/ ;
}

sub can_contain_pcdata {
   my XML::Doctype::ElementDecl $self = shift ;

   return $self->{CONTENT}
      && (
	 $self->{CONTENT} eq 'ANY'
	 || return $self->{CONTENT} =~ /#PCDATA/
      ) ;
}

=item name

   $n = $elt_decl->name ;

Gets the name of the element.

=cut

sub name {
   my XML::Doctype::ElementDecl $self = shift ;

   return $self->{NAME} ;
}


=item validate_content

   $v = $elt_decl->validate_content( \@seq ) ;

Takes an ARRAY ref of tag names (or '#PCDATA') and checks to see if
it would be valid content for elements of this type.

Right now, this must be called only when an element's end tag is
emitted.  It can be broadened to be incremental if need be.

=back

=cut

sub validate_content {
   my XML::Doctype::ElementDecl $self = shift ;
   my ( $c ) = @_ ;

   return 1     if ! defined $self->{CONTENT} || $self->{CONTENT} eq 'ANY' ;
   return ! @$c if $self->{CONTENT} eq 'EMPTY' ;

   ## Must be mixed.  If this elt can have no kids, the test
   ## is quick.  Otherwise we need to validate agains the content
   ## model tree.
   my $content_desc = join(
      '',
      map $_ eq '#PCDATA' ? $_ : "<$_>",
      @$c
   ) ;

# print STDERR "$content_desc\n$self->{CONTENT}\n" ;

#print $self->{CONTENT}, "\n" ;

   return $content_desc =~ $self->{CONTENT} ;
}


=head1 SUBCLASSING

This object uses the fields pragma, so you should use base and fields for
any subclasses.

=head1 AUTHOR

Barrie Slaymaker <barries@slaysys.com>

=head1 COPYRIGHT

This module is Copyright 2000, 2005 Barrie Slaymaker.  All rights reserved.

This module is licensed under your choice of the Artistic, BSD or
General Public License.

=cut

1 ;