XML-Bits

 view release on metacpan or  search on metacpan

lib/XML/Bits.pm  view on Meta::CPAN

  delete $child->{root};
  delete $child->{parent};

  return $self->SUPER::add_child($child);
} # add_child ##########################################################

=head2 is_text

Returns true if this is a text node.

  $node->is_text;

=cut

sub is_text { shift->type eq 'text' }
########################################################################

=head2 stringify

Stringification (and operator overloading support.)

  my $string = $node->stringify;

=cut

sub stringify {
  my $self = shift;

  return($self->{content}) if($self->type eq 'text');

  my $string = '<' . $self->tag;
  if(my $dt = $self->doctype) {
    $string = '<!DOCTYPE ' . $dt . ">\n\n" . $string;
  }

  if(my @atts = $self->atts) {
    $string .= ' ' . join(' ', 
      map({$atts[2*$_] . '="' . $atts[2*$_+1] . '"'} 0..(($#atts-1)/2))
    );
  }

  if(my @kids = $self->children) {
    $string .= '>' .
    join('', map({$_->stringify} @kids)) .
    '</' . $self->tag . '>';
  }
  else {
    $string .= ' />';
  }
  return($string);
} # stringify ##########################################################

=head2 T

A shortcut tag constructor.

  T{tag => [%atts], @content};

=cut

sub T (&) {
  my ($sub) = @_;
  my @what = $sub->();
  #warn "what: (@what)\n";
  foreach my $item (@what) {
    $item = __PACKAGE__->new('', $item) unless(ref($item));
  }
  return(__PACKAGE__->new(@what));
} # T ##################################################################

=head1 AUTHOR

Eric Wilhelm @ <ewilhelm at cpan dot org>

http://scratchcomputing.com/

=head1 BUGS

If you found this module on CPAN, please report any bugs or feature
requests through the web interface at L<http://rt.cpan.org>.  I will be
notified, and then you'll automatically be notified of progress on your
bug as I make changes.

If you pulled this development version from my /svn/, please contact me
directly.

=head1 COPYRIGHT

Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.

=head1 NO WARRANTY

Absolutely, positively NO WARRANTY, neither express or implied, is
offered with this software.  You use this software at your own risk.  In
case of loss, no person or entity owes you anything whatsoever.  You
have been warned.

=head1 LICENSE

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

# vi:ts=2:sw=2:et:sta
1;



( run in 2.199 seconds using v1.01-cache-2.11-cpan-4ab04211f4c )