XML-Writer-Simple-0.08/000755 000765 000024 00000000000 11763410142 014666 5ustar00ambsstaff000000 000000 XML-Writer-Simple-0.08/Changes000644 000765 000024 00000001646 11763410064 016173 0ustar00ambsstaff000000 000000 Revision history for XML-Writer-Simple 0.08 2012, 5 June - POD fixes 0.07 2011, 11 April - Added the ':html' tagset (full set XHTML 1.1) 0.06 2011, 11 April - Added the ':html' tagset (still incomplete) 0.05 2009, 17 April - Fixed bug with toxml that found a(0) to the Thanks to TONNERRE for the bug report. 0.04 2009, 16 February - Added newlines at the end of start_tag and end_tag. - Require a recent perl version (5.8.3 or higher); 0.03 2009, 9 February - Added support to partial tags construction. 0.02 2009, 6 February - About three years after the first release, here comes a new one with new features. Would love to know if someone is using this module. - added xml_header function. Optional argument encoding => '...' 0.01 2006, 30 January First version with basic functionality XML-Writer-Simple-0.08/lib/000755 000765 000024 00000000000 11763410142 015434 5ustar00ambsstaff000000 000000 XML-Writer-Simple-0.08/Makefile.PL000644 000765 000024 00000001147 11146247736 016657 0ustar00ambsstaff000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; use 5.008003; WriteMakefile( NAME => 'XML::Writer::Simple', AUTHOR => 'Alberto Simoes ', VERSION_FROM => 'lib/XML/Writer/Simple.pm', ABSTRACT_FROM => 'lib/XML/Writer/Simple.pm', PL_FILES => {}, PREREQ_PM => { 'XML::DT' => 0.42, 'Test::More' => 0, 'XML::DTDParser' => 2.01, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'XML-Writer-Simple-*' }, ); XML-Writer-Simple-0.08/MANIFEST000644 000765 000024 00000000506 11763410142 016020 0ustar00ambsstaff000000 000000 Changes MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/XML/Writer/Simple.pm t/00-load.t t/01-simple.t t/02-dtd.dtd t/02-dtd.t t/03-xml.t t/03-xml.xml t/04-power.t t/05-partial.t t/06-html.t t/pod-coverage.t t/pod.t META.json Module JSON meta-data (added by MakeMaker) XML-Writer-Simple-0.08/META.json000644 000765 000024 00000001663 11763410142 016315 0ustar00ambsstaff000000 000000 { "abstract" : "Create XML files easily!", "author" : [ "Alberto Simoes " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "XML-Writer-Simple", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Test::More" : "0", "XML::DT" : "0.42", "XML::DTDParser" : "2.01" } } }, "release_status" : "stable", "version" : "0.08" } XML-Writer-Simple-0.08/META.yml000644 000765 000024 00000001021 11763410142 016131 0ustar00ambsstaff000000 000000 --- abstract: 'Create XML files easily!' author: - 'Alberto Simoes ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: XML-Writer-Simple no_index: directory: - t - inc requires: Test::More: 0 XML::DT: 0.42 XML::DTDParser: 2.01 version: 0.08 XML-Writer-Simple-0.08/README000644 000765 000024 00000000711 10730327732 015552 0ustar00ambsstaff000000 000000 XML-Writer-Simple ================= XML-Writer-Simple is a simple Perl module to write XML. It takes some ideas from CGI and applies them for the XML World. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install COPYRIGHT AND LICENCE Copyright (C) 2006 Alberto Simoes This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. XML-Writer-Simple-0.08/t/000755 000765 000024 00000000000 11763410142 015131 5ustar00ambsstaff000000 000000 XML-Writer-Simple-0.08/t/00-load.t000644 000765 000024 00000000124 10730327732 016454 0ustar00ambsstaff000000 000000 #!perl -T use Test::More tests => 1; BEGIN { use_ok( 'XML::Writer::Simple' ); } XML-Writer-Simple-0.08/t/01-simple.t000644 000765 000024 00000001262 11172155256 017034 0ustar00ambsstaff000000 000000 #!/usr/bin/perl use Test::More tests => 11; use XML::Writer::Simple tags => [qw/a b c d e/]; like(xml_header, qr/^<\?xml version="1\.0"\?>\n$/); like(xml_header(encoding=>'iso-8859-1'), qr/^<\?xml version="1\.0" encoding="iso-8859-1"\?>\n$/); is(a(b(c(d(e('f'))))), "f"); is(a(b('a'),c('a')), "aa"); is(a(b(['a'..'h'])), "abcdefgh"); is(a({-foo=>'bar'}), ""); is(a({foo=>'bar'}), ""); is(a({-foo=>'bar'},'x'), "x"); is(a({foo=>'bar'},'x'), "x"); is(a(), ""); is(a(0), "0"); XML-Writer-Simple-0.08/t/02-dtd.dtd000644 000765 000024 00000000107 10730327732 016623 0ustar00ambsstaff000000 000000 XML-Writer-Simple-0.08/t/02-dtd.t000644 000765 000024 00000000234 10730327732 016314 0ustar00ambsstaff000000 000000 #!/usr/bin/perl use Test::More tests => 2; use XML::Writer::Simple dtd => "t/02-dtd.dtd"; is(xx(), ""); is(xx(yy("foo")), "foo"); XML-Writer-Simple-0.08/t/03-xml.t000644 000765 000024 00000000244 10730327732 016343 0ustar00ambsstaff000000 000000 #!/usr/bin/perl use Test::More tests => 2; use XML::Writer::Simple xml => "t/03-xml.xml"; is(zbr(), ""); is(foo(bar("ugh")), "ugh"); XML-Writer-Simple-0.08/t/03-xml.xml000644 000765 000024 00000000064 10730327732 016700 0ustar00ambsstaff000000 000000 foo gah XML-Writer-Simple-0.08/t/04-power.t000644 000765 000024 00000003211 10730327732 016675 0ustar00ambsstaff000000 000000 #!/usr/bin/perl use Test::More tests => 8; use XML::Writer::Simple tags => [qw/foo bar/], powertags => [qw/foo_bar table_tr_td/]; is(foo(bar("ugh")), "ugh"); is(foo_bar("ugh"), "ugh"); is(foo_bar("a","b","c"), "abc"); is(foo_bar({attr=>"d"},"a","b","c"), "abc"); powertag("bar","foo"); is(bar_foo("a","b","c"), "abc"); is(table_tr_td( ["a","b","c"],["d","e","f"] ), "
abc
def
"); powertag(qw/div table tr td/); is(div_table_tr_td({-style=>'background-color: #defdef;'}, [['a','b','c'], ['d','e','f']], [['g','h','i'], ['j','k','l']]), '
abc
def
ghi
jkl
'); is(div_table_tr_td({-style=>'background-color: #defdef;'}, [{-style=>'border: solid 1px #000000;'}, ['a','b','c'], ['d','e','f']], [['g','h','i'], ['j','k','l']]), '
abc
def
ghi
jkl
'); XML-Writer-Simple-0.08/t/05-partial.t000644 000765 000024 00000000345 11144066004 017173 0ustar00ambsstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 3; use XML::Writer::Simple partial => 1, tags => [qw/a b c d e/]; is(start_a(),"\n"); is(start_a({foo=>'bar'}),"\n"); is(end_e(),"\n"); XML-Writer-Simple-0.08/t/06-html.t000644 000765 000024 00000000542 11550612025 016504 0ustar00ambsstaff000000 000000 #!/usr/bin/perl use Test::More tests => 2; use XML::Writer::Simple ':html'; is(p("foo"), "

foo

"); is(table(Tr([td([qw.a b c.]), td([qw.d e f.]), td([qw.g h i.])]))."\n", <abcdefghi EOH XML-Writer-Simple-0.08/t/pod-coverage.t000644 000765 000024 00000000254 10730327732 017677 0ustar00ambsstaff000000 000000 #!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); XML-Writer-Simple-0.08/t/pod.t000644 000765 000024 00000000214 10730327732 016102 0ustar00ambsstaff000000 000000 #!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); XML-Writer-Simple-0.08/lib/XML/000755 000765 000024 00000000000 11763410142 016074 5ustar00ambsstaff000000 000000 XML-Writer-Simple-0.08/lib/XML/Writer/000755 000765 000024 00000000000 11763410142 017350 5ustar00ambsstaff000000 000000 XML-Writer-Simple-0.08/lib/XML/Writer/Simple.pm000644 000765 000024 00000020523 11763410074 021145 0ustar00ambsstaff000000 000000 package XML::Writer::Simple; use warnings; use strict; use Exporter (); use vars qw/@ISA @EXPORT/; use XML::DT; use XML::DTDParser qw/ParseDTDFile/; =encoding utf-8 =head1 NAME XML::Writer::Simple - Create XML files easily! =cut our $VERSION = '0.08'; @ISA = qw/Exporter/; @EXPORT = (qw/powertag xml_header/); our %PTAGS = (); our $MODULENAME = "XML::Writer::Simple"; our $IS_HTML = 0; our %TAG_SET = ( html => { tags => [qw.a abbr acronym address area b base bdo big blockquote body br button caption cite code col colgroup dd del dfn div dl dt em fieldset form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins kbd label legend li link map meta noframes noscript object ol optgroup option p param pre q samp script select small span strong style sub sup table tbody td textarea tfoot th thead title Tr tt u ul var.] }, ); =head1 SYNOPSIS use XML::Writer::Simple dtd => "file.dtd"; print xml_header(encoding => 'iso-8859-1'); print para("foo",b("bar"),"zbr"); # if you want CGI but you do not want CGI :) use XML::Writer::Simple ':html'; =head1 USAGE This module takes some ideas from CGI to make easier the life for those who need to generated XML code. You can use the module in three flavours (or combine them): =over 4 =item tags When importing the module you can specify the tags you will be using: use XML::Writer::Simple tags => [qw/p b i tt/]; print p("Hey, ",b("you"),"! ", i("Yes ", b("you"))); that will generate

Hey you! Yes you

=item dtd You can supply a DTD, that will be analyzed, and the tags used: use XML::Writer::Simple dtd => "tmx.dtd"; print tu(seg("foo"),seg("bar")); =item xml You can supply an XML (or a reference to a list of XML files). They will be parsed, and the tags used: use XML::Writer::Simple xml => "foo.xml"; print foo("bar"); =item partial You can supply an 'partial' key, to generate prototypes for partial tags construction. For instance: use XML::Writer::Simple tags => qw/foo bar/, partial => 1; print start_foo; print ... print end_foo; =back You can also use tagsets, where sets of tags from a well known format are imported. For example, to use HTML: use XML::Writer::Simple ':html'; =head1 EXPORT This module export one function for each element at the dtd or xml file you are using. See below for details. =head1 FUNCTIONS =head2 import Used when you 'use' the module, should not be used directly. =head2 xml_header This function returns the xml header string, without encoding definition, with a trailing new line. Default XML encoding should be UTF-8, by the way. You can force an encoding passing it as argument: print xml_header(encoding=>'iso-8859-1'); =head2 powertag Used to specify a powertag. For instance: powertag("ul","li"); ul_li([qw/foo bar zbr ugh/]); will generate
  • foo
  • bar
  • zbr
  • ugh
You can also supply this information when loading the module, with use XML::Writer::Simple powertags=>["ul_li","ol_li"]; Powertags support three level tags as well: use XML::Writer::Simple powertags=>["table_tr_td"]; print table_tr_td(['a','b','c'],['d','e','f']); =cut sub xml_header { my %ops = @_; my $encoding = ""; $encoding =" encoding=\"$ops{encoding}\"" if exists $ops{encoding}; return "\n"; } sub powertag { my $nfunc = join("_", @_); $PTAGS{$nfunc}=[@_]; push @EXPORT, $nfunc; XML::Writer::Simple->export_to_level(1, $MODULENAME, $nfunc); } sub _xml_from { my ($tag, $attrs, @body) = @_; return (ref($body[0]) eq "ARRAY")? join("", map{ _toxml($tag, $attrs, $_) } @{$body[0]}) :_toxml($tag, $attrs, join("", @body)); } sub _clean_attrs { my $attrs = shift; for (keys %$attrs) { if (m!^-!) { $attrs->{$'}=$attrs->{$_}; delete($attrs->{$_}); } } return $attrs; } sub _toxml { my ($tag,$attr,$contents) = @_; if (defined($contents) && $contents ne "") { return _start_tag($tag,$attr) . $contents . _close_tag($tag); } else { return _empty_tag($tag,$attr); } } sub _go_down { my ($tags, @values) = @_; my $tag = shift @$tags; if (@$tags) { join("", map { my $attrs = {}; if (ref($_->[0]) eq 'HASH') { $attrs = _clean_attrs(shift @$_); } _xml_from($tag,$attrs,_go_down([@$tags],@$_)) } ### REALLY NEED TO COPY @values) } else { join("", map { _xml_from($tag,{},$_) } @values) } } sub AUTOLOAD { my $attrs = {}; my $tag = our $AUTOLOAD; $tag =~ s!${MODULENAME}::!!; $attrs = shift if ref($_[0]) eq "HASH"; $attrs = _clean_attrs($attrs); if (exists($PTAGS{$tag})) { my @tags = @{$PTAGS{$tag}}; my $toptag = shift @tags; return _xml_from($toptag, $attrs, _go_down(\@tags, @_)); } else { if ($tag =~ m/^end_(.*)$/) { return _close_tag($1)."\n"; } elsif ($tag =~ m/^start_(.*)$/) { return _start_tag($1, $attrs)."\n"; } else { return _xml_from($tag,$attrs,@_); } } } sub _start_tag { my ($tag,$attr) = @_; $tag = "tr" if $tag eq "Tr" && $IS_HTML; $attr = join(" ",map { "$_=\"$attr->{$_}\""} keys %$attr); if ($attr) { return "<$tag $attr>" } else { return "<$tag>" } } sub _empty_tag { my ($tag,$attr) = @_; $tag = "tr" if $tag eq "Tr" && $IS_HTML; $attr = join(" ",map { "$_=\"$attr->{$_}\""} keys %$attr); if ($attr) { return "<$tag $attr/>" } else { return "<$tag/>" } } sub _close_tag { my $tag = shift; $tag = "tr" if $tag eq "Tr" && $IS_HTML; return ""; } sub import { my $class = shift; my @tags; my @ptags; while ($_[0] && $_[0] =~ m!^:(.*)$!) { shift; my $pack = $1; $IS_HTML = 1 if $pack eq "html"; if (exists($TAG_SET{$pack})) { push @tags => exists $TAG_SET{$pack}{tags} ? @{$TAG_SET{$pack}{tags}} : (); push @ptags => exists $TAG_SET{$pack}{ptags} ? @{$TAG_SET{$pack}{ptags}} : (); } else { die "XML::Writer::Simple - Unknown tagset :$pack\n"; } } my %opts = @_; if (exists($opts{tags})) { if (ref($opts{tags}) eq "ARRAY") { push @tags => @{$opts{tags}}; } } if (exists($opts{xml})) { my @xmls = (ref($opts{xml}) eq "ARRAY")?@{$opts{xml}}:($opts{xml}); my $tags; for my $xml (@xmls) { dt($xml, -default => sub { $tags->{$q}++ }); } push @tags => keys %$tags; } if (exists($opts{dtd})) { my $DTD = ParseDTDFile($opts{dtd}); push @tags => keys %$DTD; } push @EXPORT => @tags; if (exists($opts{partial})) { push @EXPORT => map { "start_$_" } @tags; push @EXPORT => map { "end_$_" } @tags; } if (@ptags || exists($opts{powertags})) { push @ptags => @{$opts{powertags}} if exists $opts{powertags}; @PTAGS{@ptags} = map { [split/_/] } @ptags; push @EXPORT => @ptags; } XML::Writer::Simple->export_to_level(1, $class, @EXPORT); } =head1 AUTHOR Alberto Simões, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 COPYRIGHT AND LICENSE Copyright 1999-2012 Project Natura. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of XML::Writer::Simple