XML-AutoWriter

 view release on metacpan or  search on metacpan

lib/XML/Doctype/ElementDecl.pm  view on Meta::CPAN


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.

=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} ;
}




( run in 0.576 second using v1.01-cache-2.11-cpan-39bf76dae61 )