Template-Semantic
view release on metacpan or search on metacpan
t/05_value-type.t view on Meta::CPAN
<root>
<!-- foo -->
</root>
--- expected
<root>
<!--BAR-->
</root>
=== cdata x scalar
--- vars
'//text()[2]' => 'xxx > yyy'
--- template
<div>
<![CDATA[ foo > bar ]]>
</div>
--- expected
<div>
<![CDATA[xxx > yyy]]>
</div>
=== cdata x scalar-ref (TODO)
--- vars
'//text()[2]' => \'<b>xxx</b> > yyy²'
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
<![CDATA[<b>xxx</b> > yyy²]]>
</root>
=== cdata x undef
--- vars
'//text()[2]' => undef
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
</root>
=== cdata x XML::LibXML::Element
--- vars
use XML::LibXML;
'//text()[2]' => do {
my $elem = XML::LibXML::Element->new('span');
$elem->appendText('foo');
$elem;
}
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
<![CDATA[<span>foo</span>]]>
</root>
=== cdata x XML::LibXML::Text
--- vars
use XML::LibXML;
'//text()[2]' => XML::LibXML::Text->new('xxx > yyy')
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
<![CDATA[xxx > yyy]]>
</root>
=== cdata x XML::LibXML::Attr
--- vars
use XML::LibXML;
'//text()[2]' => XML::LibXML::Attr->new('class', 'xxx')
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- error
^Can't assign XML::LibXML::Attr to any element
=== cdata x XML::LibXML::Comment
--- vars
use XML::LibXML;
'//text()[2]' => XML::LibXML::Comment->new('xxx')
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
<![CDATA[xxx]]>
</root>
=== cdata x XML::LibXML::CDATASection
--- vars
use XML::LibXML;
'//text()[2]' => XML::LibXML::CDATASection->new('xxx')
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
<![CDATA[xxx]]>
</root>
=== cdata x Template::Semantic::Document
--- vars
'//text()[2]' => Template::Semantic->process(\'<span></span>')
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- error
^Can't assign Template::Semantic::Document to XML::LibXML::CDATASection
=== cdata x hashref
--- vars
'//text()[2]' => {
'/span' => 'xxx',
}
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- error
^Can't assign hashref to XML::LibXML::CDATASection
=== cdata x list
--- vars
'//text()[2]' => [
{ '/li' => 'AAA' },
{ '/li' => 'BBB' },
]
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- error
^Can't assign loop list to XML::LibXML::CDATASection
=== cdata x sub (using $_)
--- vars
'//text()[2]' => sub { uc }
--- template
<root>
<![CDATA[ foo > bar ]]>
</root>
--- expected
<root>
<![CDATA[ FOO > BAR ]]>
</root>
=== cdata x sub (using @_)
--- vars
'//text()[2]' => sub {
my $node = shift;
return ref($node) .'/'. $node->nodeName .'/'. $node->textContent;
}
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
<![CDATA[XML::LibXML::CDATASection/#cdata-section/ foo ]]>
</root>
=== cdata x sub (do nothing)
--- vars
'//text()[2]' => sub { \$_ }
--- template
<root>
<![CDATA[ foo > bar ]]>
</root>
--- expected
<root>
<![CDATA[ foo > bar ]]>
</root>
=== cdata x filter
--- vars
'//text()[2]' => [ ' bar ', sub { uc }, 'trim' ]
--- template
<root>
<![CDATA[ foo ]]>
</root>
--- expected
<root>
<![CDATA[BAR]]>
</root>
( run in 0.325 second using v1.01-cache-2.11-cpan-454fe037f31 )