Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated test suite & docs. Minor additions/fixes for new tests to work

  • Loading branch information...
commit 714787a5127551c165c64f204de6d5e94020a49e 1 parent c8d83d6
@draegtun authored
View
4 Build.PL
@@ -9,10 +9,10 @@ my $builder = Module::Build->new(
dist_version_from => 'lib/Builder.pm',
build_requires => {
'Test::More' => 0,
- 'Carp' => 0,
+ 'Carp' => 0,
},
add_to_cleanup => [ 'Builder-*' ],
- create_makefile_pl => 'traditional',
+ create_makefile_pl => 'traditional',
);
$builder->create_build_script();
View
11 Changes
@@ -1,5 +1,16 @@
Revision history for Builder
+0.02 Thurs January 1, 2009
+ * Updated test suite & docs. Minor additions/fixes for new tests to work!
+ - CDATA now fixed
+ - block() method now expects hashref for 2nd arg (ie. named options)
+ - block() named arg changed from qualifiedAttrib to qualified_attr
+ - added builder_xml_pretty.t & builder_xml_output.t
+ - B::XML - added open_newline, close_newline & pre_indent args
+ - Added empty tags, eg. <br /> (tag can be defined with empty_tag arg)
+ - Oh and Happy New Year!
+
+
0.01 Weds November 26, 2008
* First ever version on CPAN
- Also my first ever CPAN module!
View
6 MANIFEST
@@ -4,15 +4,17 @@ lib/Builder.pm
lib/Builder/Utils.pm
lib/Builder/XML.pm
lib/Builder/XML/Utils.pm
+Makefile.PL
MANIFEST
+META.yml
README
t/00-load.t
t/boilerplate.t
t/builder_xml_basic.t
t/builder_xml_cdata.t
t/builder_xml_namespace.t
+t/builder_xml_output.t
+t/builder_xml_pretty.t
t/pod-coverage.t
t/pod.t
TODO
-Makefile.PL
-META.yml
View
13 MANIFEST.bak
@@ -1,9 +1,18 @@
Build.PL
Changes
-MANIFEST
-README
lib/Builder.pm
+lib/Builder/Utils.pm
lib/Builder/XML.pm
+lib/Builder/XML/Utils.pm
+MANIFEST
+README
t/00-load.t
+t/boilerplate.t
+t/builder_xml_basic.t
+t/builder_xml_cdata.t
+t/builder_xml_namespace.t
t/pod-coverage.t
t/pod.t
+TODO
+Makefile.PL
+META.yml
View
10 META.yml
@@ -1,6 +1,6 @@
---
name: Builder
-version: 0.01
+version: 0.02
author:
- 'Barry Walsh <draegtun@cpan.org>'
abstract: 'Build XML, HTML, CSS and other outputs in blocks'
@@ -13,16 +13,16 @@ build_requires:
provides:
Builder:
file: lib/Builder.pm
- version: 0.01
+ version: 0.02
Builder::Utils:
file: lib/Builder/Utils.pm
- version: 0.01
+ version: 0.02
Builder::XML:
file: lib/Builder/XML.pm
- version: 0.01
+ version: 0.02
Builder::XML::Utils:
file: lib/Builder/XML/Utils.pm
- version: 0.01
+ version: 0.02
generated_by: Module::Build version 0.3
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
View
39 README
@@ -1,11 +1,11 @@
-Builder version 0.01
+Builder version 0.02
This distribution includes the following modules:
- Builder (0.01)
- Builder::Utils (0.01)
- Builder::XML (0.01)
- Builder::XML::Utils (0.01)
+ Builder (0.02)
+ Builder::Utils (0.02)
+ Builder::XML (0.02)
+ Builder::XML::Utils (0.02)
SYNOPSIS
@@ -13,20 +13,31 @@ SYNOPSIS
Using building blocks to render XML, CSS, HTML and other outputs.
use Builder;
+ my $builder = Builder->new;
+ my $xm = $builder->block( 'Builder::XML' );
- my $builder = Builder->new();
- my $xm = $builder->block( 'Builder::XML' );
+ # example 1
- $xm->body(
- $xm->div( { id => 'mydiv' },
- $xm->bold( 'hello' ),
- $xm->em( 'world' )
- );
- );
+ $xm->parent( { isa => 'Mother' }, $xm->child( 'Hi Mum!' ) );
say $builder->render;
+ # <parent isa="Mother"><child>Hi Mum!</child></parent>
+
+
+ # example 2
+
+ $xm->parent( sub {
+ for my $say qw/Mum Dad/ {
+ $xm->child( "Hi $say" );
+ }
+ });
+
+ say $builder->render;
+
+ # <parent><child>Hi Mum</child><child>Hi Dad</child></parent>
+
INSTALLATION
@@ -55,7 +66,7 @@ perldoc command.
COPYRIGHT AND LICENCE
-Copyright (C) 2008 Barry Walsh (Draegtun Systems Ltd)
+Copyright (C) 2008,2009 Barry Walsh (Draegtun Systems Ltd)
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
View
25 TODO
@@ -1,8 +1,23 @@
-0.01
- Finish off docs
- Add more tests
+0.03
+ Continue to improve docs - Document other (hidden) features!?
+ Add more tests - more complicated sub/loop tests (see my original example dir) - also other from older tests
+ - (More checks on mixed content of subs, text & objects)
Bring git (GitHub) up-to-date with latest version in my SVN
- (NB. Above includes CSS module)
+ - Above includes CSS module
+ - Putting back in comments & <? ?> tags - And helpers
+ - DocTypes & DTD <!ELEMENT>
Add subs saving to Builder::XML (benchmark first)
Create Builder::HTML & Builder::HTML::Validated
- Refactor! Refactor! Refactor!
+ Refactor! Refactor! Refactor!
+ Nick tests from XML::Writer & XML::Generator and amend for Builder::XML
+ Fix order of attributes? (ie. document workaround)
+
+ # from Builder::XML....
+ # Builder::Declare (for Builder func import)
+ * building subs (for speed). Lets do benchmarking before attempting this!
+ * XML::Entities (option to decode on reading data & to encode on way out)
+ * AUTOLOAD & DESTROY tags - solution?
+ * test B::XML __render__ does work on local stack only (done this? certainly needs more stringent tests)
+
+ # doesnt work... $xm->p( 'one', $xm->span( 'two' ), 'and three' );
+ # only works if $xm-> is first parameter ( __say__ workaround )
View
137 lib/Builder.pm
@@ -2,7 +2,7 @@ package Builder;
use strict;
use warnings;
use Carp;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
sub new {
@@ -19,10 +19,13 @@ sub new {
}
sub block {
- my ( $self, $block, %args ) = @_;
+ my ( $self, $block, $args_ref ) = @_;
+ # TODO: check args_ref is hashref and if anything left in @_ then croak
eval "require $block";
+ # TODO: put $@ check here and add relevant test
+
return $self->_new_block( $block->__new__(
- %args,
+ %$args_ref,
_output => $self->{output},
_inc => $self->{inc},
_dec => $self->{dec},
@@ -74,43 +77,108 @@ Builder - Build XML, HTML, CSS and other outputs in blocks
=head1 VERSION
-Version 0.01
+Version 0.02
=head1 SYNOPSIS
-Example using just one building block (for now!)....
+Simple example....
use Builder;
-
- my $builder = Builder->new();
+ my $builder = Builder->new;
my $xm = $builder->block( 'Builder::XML' );
+ $xm->parent( $xm->child( 'Hi Mum!' ) );
+
+ say $builder->render;
+
+ # => <parent><child>Hi Mum!</child></parent>
+
+
+Another example using same block object....
$xm->body(
- $xm->div( { id => 'mydiv' },
- $xm->bold( 'hello' ),
- $xm->em( 'world' )
- );
+ $xm->div(
+ $xm->span( { id => 1 }, 'one' ),
+ $xm->span( { id => 2 }, 'two' ),
+ ),
);
-
say $builder->render;
+ # => <body><div><span id="1">one</span><span id="2">two</span>/div></body>
- # will produce =>
- # <body><div id="mydiv"><bold>hello</bold><em>world</em></div></body>
+And finally something a bit more whizzy....
+ my $rainbow = $builder->block( 'Builder::XML', { indent => 4, newline => 1 } );
+
+ $rainbow->colours( sub {
+ for my $colour qw/red green blue/ {
+ $rainbow->$colour( uc $colour );
+ }
+ });
+
+ say $builder->render;
+
+ # <colours>
+ # <red>RED</red>
+ # <green>GREEN</green>
+ # <blue>BLUE</blue>
+ # </colours>
=head1 DESCRIPTION
-TBD... add multiple blocks & sub (coderef) examples.
+=head2 Marketing Spiel
+
+If you need to build structured output then Builder will be exactly what you you've always been waiting for!
+
+Just select and/or tailor the blocks you need then simply click them all together to construct the output of your dreams!
+
+
+=head2 Technical Reality
+
+First we need to create the stack / buffer / scaffold / bucket / zimmerframe (pick your favourite term) object....
-TBD... add Builder non-OO example (once back in codebase!)
+ use Builder;
+ my $builder = Builder->new;
+
+Then you create the blocks associated with this build object....
+
+ my $xm = $builder->block( 'Builder::XML' );
+ my $ns = $builder->block( 'Builder::XML', { namespace => 'baz' } );
+
+Then build your output using these blocks....
+
+ $xm->fubar(
+ $xm->before( 'foo' ),
+ $ns->during( 'I3az' ),
+ $xm->after( 'bar' ),
+ );
+
+Continue to add more blocks to hearts content until happy then render it.....
+
+ my $output = $builder->render;
+
+ # <fubar><before>foo</before><baz:during>I3az</baz:during><after>bar</after><fubar>
+
+
+
+=head2 So how does it work?
+
+Remove the smoke and mirrors and all you are left with is parameter context.
+
+Each block component will have its own parameter context.
+For example when Builder::XML receives no parameters then it will return a closed tag....
+
+ $xm->br;
+
+ # => <br />
+
+For more information see relevant Builder::* block docs.
=head1 EXPORT
@@ -122,23 +190,31 @@ Nothing (at this moment!)
=head2 new
-Constructor. Currently no args are used.
+By default the constructor will maintain an internal stack (buffer) of the blocks being built.
- my $builder = Builder->new();
+ my $builder = Builder->new;
+
+This is then later returned (processed) using render method on this object.
+
+Using the I<output> named parameter changes default behaviour to immediately output the blocks to the filehandle provided.
+
+ my $builder = Builder->new( output => \*STDOUT );
+
+There are no other parameters used by constructor.
=head2 block
-Create a block. First arg is the block to use, for eg. 'Builder::XML'. Second arg is a hashref (or it will be!)
+Creates a block in this stack.
- my $builder = Builder->new();
+First arg is the block to use, for eg. 'Builder::XML'. Second arg must be a hashref of options (named parameters).
- my $xm = $builder->block( 'Builder::XML', cdata => 1 ); # v 0.01
+ my $builder = Builder->new();
- my $xm = $builder->block( 'Builder::XML', { cdata => 1 } ); # v 0.02 onwards
+ my $xm = $builder->block( 'Builder::XML', { cdata => 1 } );
-For options that can be passed as args please see relevant builder documentation.
+For options that can be passed as args please see relevant Builder::* documentation.
=head2 render
@@ -149,15 +225,22 @@ Renders all the blocks for the requested builder stack returning the information
=head2 flush
-The render method will automatically flush the builder stack. Unlikely this will be any use externally!
+The render method will automatically flush the builder stack (by calling this method).
+Unlikely this will be of any use in the outside world!
- $builder->flush; # there goes all the blocks just built ;-(
+ $builder->flush; # there goes all the blocks I just built ;-(
=head1 AUTHOR
Barry Walsh C<< <draegtun at cpan.org> >>
+
+=head1 MOTIVATION
+
+Yep there was some... more on that later!
+
+
=head1 BUGS
Please report any bugs or feature requests to C<bug-builder at rt.cpan.org>, or through
@@ -223,7 +306,7 @@ L<Class::XML>, L<XML::Generator>
=head2 Builder Source Code
-Can be (shortly!) found on GitHub at http://github.com/draegtun/builder/tree/master
+GitHub at http://github.com/draegtun/builder/tree/master
=head1 DISCLAIMER
@@ -235,7 +318,7 @@ However I accept no liability I<whatsoever> should this software do what you exp
=head1 COPYRIGHT & LICENSE
-Copyright 2008 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
+Copyright 2008,2009 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
View
6 lib/Builder/Utils.pm
@@ -2,7 +2,7 @@ package Builder::Utils;
use strict;
use warnings;
use Carp;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
# common utilities put here and not exported into Builder::* because it would pollute namespace (ie. tags!)
@@ -34,7 +34,7 @@ Builder::Utils - Internal Builder Utils
=head1 VERSION
-Version 0.01
+Version 0.02
=cut
@@ -103,7 +103,7 @@ See L<Builder>
=head1 COPYRIGHT & LICENSE
-Copyright 2008 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
+Copyright 2008,2009 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
View
239 lib/Builder/XML.pm
@@ -4,7 +4,7 @@ use warnings;
use Carp;
use Builder::Utils;
use Builder::XML::Utils;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
our $AUTOLOAD;
@@ -53,21 +53,10 @@ sub AUTOLOAD {
$self;
}
-# TODO: look at XML::Element as alternative to my context method
-# Hmmm... XML::Element (& HTML::Element) doesnt have namespaces!? ;-(
-
-# TODO: So forget above!! But do look at...
-# 1. building subs (for speed). Lets do benchmarking before attempting this!
-# 2. XML::Entities (option to decode on reading data & to encode on way out)
-# 3. cdata - DONE
-# 4. Direct print option - Added to Builder.pm.. appears to work.. need to write test
-# 5. AUTOLOAD & DESTROY tags - solution?
-
######################################################
# methods
-# Todo: amend below to only work on local stack (block_id) - NB. makes it different to Builder->render then? Already Done?!
sub __render__ {
my $self = shift;
my $render;
@@ -97,13 +86,13 @@ sub __cdata__ {
sub __cdatax__ {
my $self = shift;
- return q{<!CDATA[[} . $_[0] . q{]]>};
+ return q{<![CDATA[} . $_[0] . q{]]>};
}
sub __say__ {
my ( $self, @say ) = @_;
for my $said ( @say ) { $self->__push__( sub { $said } ) }
- return;
+ $self;
}
sub __push__ {
@@ -127,11 +116,31 @@ sub __level__ { $_[0]->{ _level }->() }
sub __tab__ {
my $self = shift;
- return q{ } x ( $self->{ indent } * $self->__level__ ) if $self->{ indent };
- return q{};
+ my $tab = q{};
+ $tab = q{ } x $self->{ pre_indent } if $self->{ pre_indent };
+ $tab.= q{ } x ( $self->{ indent } * $self->__level__ ) if $self->{ indent };
+ return $tab;
+}
+
+sub __start_tab__ { $_[0]->__tab__ }
+
+sub __end_tab__ {
+ my $self = shift;
+ return q{} if $self->{ newline } && ! $self->{ open_newline };
+ $self->__tab__;
}
+sub __open_newline__ {
+ my $self = shift;
+ return $self->{cr} if $self->{ open_newline };
+ return q{};
+}
+sub __close_newline__ {
+ my $self = shift;
+ return $self->{cr} if $self->{ close_newline };
+ return q{};
+}
sub DESTROY {
my $self = shift;
@@ -150,7 +159,7 @@ Builder::XML - Building block for XML
=head1 VERSION
-Version 0.01
+Version 0.02
=cut
@@ -158,7 +167,82 @@ Version 0.01
=head1 SYNOPSIS
-TBD
+Please look at L<Builder> docs. This currently contains the necessary synopsis & description for Builder::XML.
+At some point in future it will be moved here and Builder docs will be replaced with something more generic.
+
+
+=head1 DESCRIPTION
+
+See above.
+
+=head2 So how does it work? (in more detail!)
+
+Here are Builder::XML parameter contexts....
+
+no parameters => produces a closed tag
+
+ $xm->br;
+
+ # => <br />
+
+
+first parameter is a hashref => attributes
+
+ $xm->span( { id => 'mydiv', class => 'thisClass' }, 'some content' );
+
+ # => <span class="thisClass" id="mydiv">some content</span>
+
+
+parameter(s) are a anon sub or code ref --> callback
+
+ $xm->ul( { class => 'list' }, sub {
+ for my $numb qw/one two three/ {
+ $xm->li( $numb );
+ }
+ });
+
+ # => <ul class="list"><li>one</li><li>two</li><li>three</li></ul>
+
+
+parameter(s) are content => element text
+
+ $xm->p( 'one', 'two', 'and three' );
+
+ # => <p>one two and three</p>
+
+
+parameter(s) are Builder blocks or content => nesting
+
+ $xm->p( 'one', $xm->span( 'two' ), 'and three' );
+
+ # => <p>one <span>two</span> and three</p>
+
+ # NB. THIS DOESN'T WORK YET... unless first param is an object
+ # Workaround - use __say__ method around text like so...
+ #
+ # $xm->p( $xm->__say__('one'), $xm->span( 'two' ), 'and three' );
+ #
+ # This needs "fixing" for HTML usage
+
+
+parameter(s) are Builder blocks within builder blocks => nesting ad-infinitum
+
+ $xm->div(
+ $xm->div(
+ xm->span( 'hi there'),
+ ),
+ );
+
+ # => <div><div><span>hi there</span></div></div>
+
+
+=head2 Gotchas?
+
+TODO: XML entities not implemented
+
+TODO: invalid method calls... $xm->flip-flop, $xm->DESTROY, $xm->AUTOLOAD
+
+TODO: Fix / workaround for attribute ordering
=head1 EXPORT
@@ -168,9 +252,124 @@ None.
=head1 METHODS
+All methods are prefix/postfixed with __ so that ambigious method calls wont clash
+and can be turned successfully into XML elements.
+
+Below is a complete list of defined methods in Builder::XML.
+NB. Most of these are private methods and only listing here for reference.
+
+
+=head2 __new__
+
+Private.
+
+This is the contructor called by the Builder object when creating a block...
+
+ $xm = $builder->block( 'Builder::XML' );
+
+All arguments are passed from Builder->block method straight to Builder::XML->__new__
+
+
+=head2 __render__
+
+Will immediately render the building block.
+Can be useful in some cases...
+
+ # provide example here of it working
+
+ # and then provide example of what can go wrong!
+
+...but recommend $builder->render for best practise.
+
+
+=head2 __element__
+
+Private
+
+
+=head2 __cdata__
+
+Wraps content in <![CDATA[ ]]> element.
+Useful for quick ditties like....
+
+ $xm->span( $xm->__cdata__( 'yada yada' ) );
+
+ # => <span><!CDATA[yada yada]]></span>
+
+But for best practise you probably still find building a block more useful in the long run...
+
+ my $xm = $builder->block( 'Builder::XML', { cdata => 1 } );
+
+ $xm->span( 'yada yada' );
+
+
+=head2 __cdatax__
+
+PRIVATE - used with __cdata__
+
+
+=head2 __say__
+
+Really a Private method but as mentioned in I<Gotchas> it can be useful for working around some implementation issues.
+
+=head2 __push__
+
+Private
+
+
+=head2 __inc__
+
+Private
+
+
+=head2 __dec__
+
+Private
+
+
+=head2 __level__
+
+Private
+
+
+=head2 __tab__
+
+Private
+
+
+=head2 __start_tab__
+
+Private
+
+
+=head2 __end_tab__
+
+Private
+
+
+=head2 __open_newline__
+
+Private
+
+
+=head2 __close_newline__
+
+Private
+
+
=head2 AUTOLOAD
-=head2 DESTORY
+Used in method to XML element resolution.
+
+Therefore at present AUTOLOAD cannot be used as a XML element.
+
+
+=head2 DESTROY
+
+Standard POOP!
+
+Therefore at present DESTROY cannot be used as a XML element.
+
=head1 AUTHOR
@@ -221,7 +420,7 @@ L<http://search.cpan.org/dist/Builder/>
=head1 COPYRIGHT & LICENSE
-Copyright 2008 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
+Copyright 2008,2009 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
View
32 lib/Builder/XML/Utils.pm
@@ -2,7 +2,7 @@ package Builder::XML::Utils;
use strict;
use warnings;
use Carp;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
sub build_context {
@@ -16,7 +16,7 @@ sub build_context {
$self->__push__( sub {
# start building the return string
- my $return .= $self->__tab__ . q{<}.$tag;
+ my $return .= $self->__start_tab__ . q{<}.$tag;
# any spec attrs?
if ( $attr_ref->{ _xmlns_ } ) {
@@ -29,7 +29,7 @@ sub build_context {
$return .= sprintf( ' %s%s="%s"', $self->{attr_ns}, $k, $attr_ref->{$k} );
}
- $return .= q{>} . $self->{cr};
+ $return .= q{>} . $self->__open_newline__;
$self->__inc__;
return $return;
@@ -43,7 +43,7 @@ sub build_context {
$self->__push__( sub {
$self->__dec__;
- $self->__tab__ . q{</}.$tag.q{>} . $self->{cr}
+ $self->__end_tab__ . q{</}.$tag.q{>} . $self->__close_newline__;
});
},
@@ -58,9 +58,13 @@ sub build_context {
$attrib .= sprintf( ' %s%s="%s"', $self->{attr_ns}, $k, $param->{attr}->{$k} );
}
+ return $self->__push__( sub {
+ $self->__tab__ . q{<}.$tag.$attrib.q{>}.$text.q{</}.$tag.q{>} . $self->__close_newline__
+ }) if $text;
+
$self->__push__( sub {
- $self->__tab__ . q{<}.$tag.$attrib.q{>}.$text.q{</}.$tag.q{>} . $self->{cr}
- });
+ $self->__tab__ . q{<}.$tag.$attrib.$self->{empty_tag} . $self->__close_newline__
+ })
},
};
@@ -72,9 +76,17 @@ sub get_args {
my ( %arg ) = @_;
$arg{ns} = defined $arg{namespace} ? $arg{namespace} . q{:} : q{};
$arg{attr_ns} = defined $arg{attr_namespace} ? ( $arg{attr_namespace} . ':' ) : q{};
- $arg{attr_ns} = $arg{qualifiedAttrib} ? $arg{ns} : $arg{attr_ns};
- $arg{cr} = $arg{ newline } ? "\n" : q{};
+ $arg{attr_ns} = $arg{qualified_attr} ? $arg{ns} : $arg{attr_ns};
+ $arg{cr} = $arg{ newline } ? "\n" x $arg{ newline } : q{};
$arg{cdata} ||= 0;
+
+ $arg{ open_newline } = defined $arg{ open_newline } ? $arg{ open_newline } : 1;
+ $arg{ close_newline } = defined $arg{ close_newline } ? $arg{ close_newline } : 1;
+
+ $arg{ pre_indent } ||= 0;
+
+ $arg{ empty_tag } ||= q{ />};
+
return %arg;
}
@@ -88,7 +100,7 @@ Builder::XML::Utils - Internal Builder XML Utils
=head1 VERSION
-Version 0.01
+Version 0.02
=cut
@@ -159,7 +171,7 @@ See L<Builder>
=head1 COPYRIGHT & LICENSE
-Copyright 2008 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
+Copyright 2008,2009 Barry Walsh (Draegtun Systems Ltd), all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
View
22 t/builder_xml_basic.t
@@ -1,4 +1,4 @@
-use Test::More tests => 3;
+use Test::More tests => 5;
use Builder;
my $builder = Builder->new();
@@ -45,3 +45,23 @@ $xm->body( sub {
$expected = q{<body><em>emphasized</em><div id="mydiv"><bold>hello</bold><em>world</em><test>hello</test><div><p>para</p><test>hello</test></div></div></body>};
is $builder->render, $expected, "xml test 3 failed";
+
+
+# test 4
+# parameter(s) are content => element text
+
+$xm->p( 'one', 'two', 'and three' );
+is $builder->render, q{<p>one two and three</p>}, "xml test 4 failed";
+
+# test 5
+# parameter(s) are Builder blocks => nesting
+
+$xm->p( $xm->span( 'one' ), 'two', 'and three' );
+is $builder->render, q{<p><span>one</span>twoand three</p>}, "xml test 5 failed";
+
+__END__
+
+# however this fails (doesn't do span callback)... need to look at....
+$xm->p( 'one', $xm->span( 'two' ), 'and three' );
+
+
View
6 t/builder_xml_cdata.t
@@ -2,7 +2,7 @@ use Test::More tests => 2;
use Builder;
my $builder = Builder->new();
-my $with_cdata = $builder->block( 'Builder::XML', cdata => 1 );
+my $with_cdata = $builder->block( 'Builder::XML', { cdata => 1 } );
my $without_cdata = $builder->block( 'Builder::XML' );
my $text = "Tom, Dick & Harry";
my $text2 = lc $text;
@@ -12,7 +12,7 @@ $with_cdata->body( sub {
$with_cdata->span($text);
$with_cdata->span( $with_cdata->__cdata__( $text2 ) );
});
-is $builder->render, data("<!CDATA[[$text]]>", $text2), "xml cdata test 1";
+is $builder->render, data("<![CDATA[$text]]>", $text2), "xml cdata test 1";
# test 2
$without_cdata->body( sub {
@@ -22,7 +22,7 @@ $without_cdata->body( sub {
is $builder->render, data($text, $text2), "xml cdata test 2";
sub data {
- return qq{<body><span>$_[0]</span><span><!CDATA[[$_[1]]]></span></body>};
+ return qq{<body><span>$_[0]</span><span><![CDATA[$_[1]]]></span></body>};
}
View
4 t/builder_xml_namespace.t
@@ -2,7 +2,7 @@ use Test::More tests => 4;
use Builder;
my $builder = Builder->new();
-my $xm = $builder->block( 'Builder::XML', namespace => 'foo', qualifiedAttrib => 0 );
+my $xm = $builder->block( 'Builder::XML', { namespace => 'foo', qualified_attr => 0 } );
my $expected = q{<foo:body><foo:em>emphasized</foo:em><foo:div id="mydiv"><foo:bold>hello</foo:bold><foo:em>world</foo:em></foo:div></foo:body>};
@@ -15,7 +15,7 @@ $xm->body( sub {
is $builder->render, $expected, "xml test 1";
# test2
-my $xm2 = $builder->block( 'Builder::XML', namespace => 'foo', qualifiedAttrib => 1 );
+my $xm2 = $builder->block( 'Builder::XML', { namespace => 'foo', qualified_attr => 1 } );
$expected = q{<foo:body><foo:em>emphasized</foo:em><foo:div foo:id="mydiv"><foo:bold>hello</foo:bold><foo:em>world</foo:em></foo:div></foo:body>};
$xm2->body( sub {
Please sign in to comment.
Something went wrong with that request. Please try again.