Text-XML

 view release on metacpan or  search on metacpan

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

use warnings;
use Types;
use Text::Pretty qw(:all !text);
use Exporter;
use base qw/Exporter/;

our $VERSION = '0.1';

sub pptext ($) { Text::Pretty::text(shift) }

our @EXPORT_OK = qw(elem ielem attr text comment cdata);

our %EXPORT_TAGS = ( all => \@EXPORT_OK );

newtype Text::XML::Attribute;
newtype Text::XML::Element;
newtype Text::XML::Text;
newtype Text::XML::Comment, sub{ shift !~ qr{-->}   };
newtype Text::XML::CData,   sub{ shift !~ qr{]]>}   };
newtype Text::XML::Name,    sub{ shift =~ qr{^[\w:-]*$} };

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

                             Text::XML::CData
                             Text::XML::Name);

# element( name, [element|Text|CData|Comment] )
sub elem (*;$$) { Element( Name(shift), shift() || [], shift() || [] ) }
# inline-element( name, [element|Text|CData|Comment] )
sub ielem (*;$$){ Element( Name(shift), shift() || [], shift() || [], 1 ) }
sub attr   ($$) { Attribute( Name(shift), shift ) }
sub text    ($) { Text(shift)            }
sub comment ($) { Comment(shift)         }
sub cdata   ($) { CData(shift)           }

instance Text::Pretty::Print, Text::XML::XML,
pretty => sub
{ my( $doc, %opts ) = @_
; $opts{encoding} = 'UTF-8' unless defined $opts{encoding}
; $opts{indent}   = 4       unless defined $opts{indent}
; $doc = pretty_proc($doc, $opts{indent})
; $opts{doctype}
? $doc = vcat [ hcat [ pptext '<!DOCTYPE'
                     , (nest 10, hsep [ (map {pptext $_} @{$opts{doctype}}) ])

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

Version 0.1


=head1 SYNOPSIS

XML combinators and pretty printer.
More documentation is coming.

=head1 EXPORT

elem ielem attr text comment cdata

=head1 AUTHOR

Eugene Grigoriev, C<< <eugene.grigoriev at gmail.com> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-text-xml at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-XML>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.



( run in 0.655 second using v1.01-cache-2.11-cpan-454fe037f31 )