r73794 - in /branches/upstream/libxml-writer-simple-perl/current: Changes MANIFEST META.yml lib/XML/Writer/Simple.pm t/06-html.t
gregoa at users.alioth.debian.org
gregoa at users.alioth.debian.org
Fri Apr 29 00:40:44 UTC 2011
Author: gregoa
Date: Fri Apr 29 00:40:35 2011
New Revision: 73794
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=73794
Log:
[svn-upgrade] new version libxml-writer-simple-perl (0.07)
Added:
branches/upstream/libxml-writer-simple-perl/current/t/06-html.t
Modified:
branches/upstream/libxml-writer-simple-perl/current/Changes
branches/upstream/libxml-writer-simple-perl/current/MANIFEST
branches/upstream/libxml-writer-simple-perl/current/META.yml
branches/upstream/libxml-writer-simple-perl/current/lib/XML/Writer/Simple.pm
Modified: branches/upstream/libxml-writer-simple-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libxml-writer-simple-perl/current/Changes?rev=73794&op=diff
==============================================================================
--- branches/upstream/libxml-writer-simple-perl/current/Changes (original)
+++ branches/upstream/libxml-writer-simple-perl/current/Changes Fri Apr 29 00:40:35 2011
@@ -1,15 +1,21 @@
Revision history for XML-Writer-Simple
+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 <a/>
- Thanks to TONNERRE for the bug report.
+ - Fixed bug with toxml that found a(0) to the <a/>
+ 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);
+ - 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.
+ - Added support to partial tags construction.
0.02 2009, 6 February
- About three years after the first release, here comes a new
Modified: branches/upstream/libxml-writer-simple-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libxml-writer-simple-perl/current/MANIFEST?rev=73794&op=diff
==============================================================================
--- branches/upstream/libxml-writer-simple-perl/current/MANIFEST (original)
+++ branches/upstream/libxml-writer-simple-perl/current/MANIFEST Fri Apr 29 00:40:35 2011
@@ -12,5 +12,6 @@
t/03-xml.xml
t/04-power.t
t/05-partial.t
+t/06-html.t
t/pod-coverage.t
t/pod.t
Modified: branches/upstream/libxml-writer-simple-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libxml-writer-simple-perl/current/META.yml?rev=73794&op=diff
==============================================================================
--- branches/upstream/libxml-writer-simple-perl/current/META.yml (original)
+++ branches/upstream/libxml-writer-simple-perl/current/META.yml Fri Apr 29 00:40:35 2011
@@ -1,12 +1,14 @@
--- #YAML:1.0
name: XML-Writer-Simple
-version: 0.05
+version: 0.07
abstract: Create XML files easily!
author:
- Alberto Simoes <ambs at cpan.org>
license: unknown
distribution_type: module
configure_requires:
+ ExtUtils::MakeMaker: 0
+build_requires:
ExtUtils::MakeMaker: 0
requires:
Test::More: 0
@@ -16,7 +18,7 @@
directory:
- t
- inc
-generated_by: ExtUtils::MakeMaker version 6.48
+generated_by: ExtUtils::MakeMaker version 6.56
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
Modified: branches/upstream/libxml-writer-simple-perl/current/lib/XML/Writer/Simple.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libxml-writer-simple-perl/current/lib/XML/Writer/Simple.pm?rev=73794&op=diff
==============================================================================
--- branches/upstream/libxml-writer-simple-perl/current/lib/XML/Writer/Simple.pm (original)
+++ branches/upstream/libxml-writer-simple-perl/current/lib/XML/Writer/Simple.pm Fri Apr 29 00:40:35 2011
@@ -13,18 +13,46 @@
=cut
-our $VERSION = '0.05';
+our $VERSION = '0.07';
@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 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
@@ -75,6 +103,11 @@
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
@@ -188,35 +221,36 @@
}
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 {
+ 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, at _);
- }
- }
+ }
+ }
}
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>"
@@ -227,6 +261,7 @@
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/>"
@@ -237,55 +272,63 @@
sub _close_tag {
my $tag = shift;
+ $tag = "tr" if $tag eq "Tr" && $IS_HTML;
return "</$tag>";
}
+
sub import {
- my $class = shift;
- my %opts = @_;
-
- my $partial = 0;
- $partial = 1 if exists $opts{partial};
-
- if (exists($opts{tags})) {
- if (ref($opts{tags}) eq "ARRAY") {
- push @EXPORT, @{$opts{tags}};
- if ($partial) {
- push @EXPORT, map { "start_$_" } @{$opts{tags}};
- push @EXPORT, map { "end_$_" } @{$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 @EXPORT, keys %$tags;
- if ($partial) {
- push @EXPORT, map { "start_$_" } keys %$tags;
- push @EXPORT, map { "end_$_" } keys %$tags;
- }
- }
-
- if (exists($opts{dtd})) {
- my $DTD = ParseDTDFile($opts{dtd});
- push @EXPORT, keys %$DTD;
- if ($partial) {
- push @EXPORT, map { "start_$_" } keys %$DTD;
- push @EXPORT, map { "end_$_" } keys %$DTD;
- }
- }
-
- if (exists($opts{powertags})) {
- my @ptags = @{$opts{powertags}};
- @PTAGS{@ptags} = map { [split/_/] } @ptags;
- push @EXPORT, @ptags;
- }
-
- XML::Writer::Simple->export_to_level(1, $class, @EXPORT);
+ 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
Added: branches/upstream/libxml-writer-simple-perl/current/t/06-html.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libxml-writer-simple-perl/current/t/06-html.t?rev=73794&op=file
==============================================================================
--- branches/upstream/libxml-writer-simple-perl/current/t/06-html.t (added)
+++ branches/upstream/libxml-writer-simple-perl/current/t/06-html.t Fri Apr 29 00:40:35 2011
@@ -1,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More tests => 2;
+use XML::Writer::Simple ':html';
+
+is(p("foo"), "<p>foo</p>");
+
+is(table(Tr([td([qw.a b c.]),
+ td([qw.d e f.]),
+ td([qw.g h i.])]))."\n", <<EOH);
+<table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>d</td><td>e</td><td>f</td></tr><tr><td>g</td><td>h</td><td>i</td></tr></table>
+EOH
+
+
+
More information about the Pkg-perl-cvs-commits
mailing list