From 83eb1374310b3ebc3523f7bc37adee80bde03184 Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Thu, 1 Mar 2007 13:51:07 +0100 Subject: [PATCH] Add perl-sax/attribute[23] tests. Work directly. --- perl-sax/XML/TemplateSAX.pm | 15 +++++++++++++++ perl-sax/attribute2.pl | 13 +++++++++++++ perl-sax/attribute3.pl | 14 ++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 perl-sax/attribute2.pl create mode 100644 perl-sax/attribute3.pl diff --git a/perl-sax/XML/TemplateSAX.pm b/perl-sax/XML/TemplateSAX.pm index 10714a4..638f4b2 100644 --- a/perl-sax/XML/TemplateSAX.pm +++ b/perl-sax/XML/TemplateSAX.pm @@ -72,4 +72,19 @@ sub process_file_to_buffer { return $buffer; } +sub alternate { + my ($tag, $array, @elems) = @_; + + my $i = 0; + my $num = scalar @elems; + + for my $ref (@$array) { + if (defined($ref)) { + $ref->{$tag} = $elems[$i++ % $num]; + } + } + + return $array; +} + 1; diff --git a/perl-sax/attribute2.pl b/perl-sax/attribute2.pl new file mode 100644 index 0000000..3821a33 --- /dev/null +++ b/perl-sax/attribute2.pl @@ -0,0 +1,13 @@ +#! /usr/bin/perl +use XML::TemplateSAX; + +my $doc = XML::TemplateSAX::process_file('../xml/clone.xml', { + 'color' => 'blue', + '#things' => XML::TemplateSAX::alternate('li/class', [ + { 'li' => 'Raindrops on roses' }, + { 'li' => 'Whiskers on kittens' }, + { 'li' => 'Bright copper kettles' }, + { 'li' => 'Warm, woolen mittens'}, + ], 'odd', 'even') +}); +print $doc; diff --git a/perl-sax/attribute3.pl b/perl-sax/attribute3.pl new file mode 100644 index 0000000..6b955cc --- /dev/null +++ b/perl-sax/attribute3.pl @@ -0,0 +1,14 @@ +#! /usr/bin/perl +use XML::TemplateSAX; + +my $doc = XML::TemplateSAX::process_file('../xml/clone.xml', { + 'color' => 'blue', + '#things' => XML::TemplateSAX::alternate('li/class', [ + { 'li' => 'Raindrops on roses' }, + { 'li' => 'Whiskers on kittens' }, + undef, + { 'li' => 'Bright copper kettles' }, + { 'li' => 'Warm, woolen mittens'}, + ], 'odd', 'even') +}); +print $doc; -- 2.39.2