XML-CompactTree-0.03/0000755000175000001440000000000011166650160013317 5ustar pajasusersXML-CompactTree-0.03/Changes0000644000175000001440000000021111120034213014565 0ustar pajasusersRevision history for XML-CompactTree-XS 0.01 Fri Nov 14 13:53:52 CET 2008 First version, released on an unsuspecting world. XML-CompactTree-0.03/CompactTree.pm0000644000175000001440000003372511166650137016101 0ustar pajasuserspackage XML::CompactTree; use warnings; use strict; =head1 NAME XML::CompactTree - builder of compact tree structures from XML documents =head1 VERSION Version 0.03 =cut our $VERSION = '0.03'; use base qw(Exporter); use vars qw( @EXPORT @EXPORT_OK %EXPORT_TAGS ); use XML::LibXML::Reader; # XCT_USE_QNAMES /* not yet implemented */ # XCT_TEXT_AS_STRING /* not yet implemented */ # XCT_PRESERVE_PARENT /* not yet implemented */ # XCT_MERGE_TEXT_NODES /* not yet implemented */ use constant do { my @flags = (qw( XCT_IGNORE_WS XCT_IGNORE_SIGNIFICANT_WS XCT_IGNORE_PROCESSING_INSTRUCTIONS XCT_IGNORE_COMMENTS XCT_USE_QNAMES XCT_KEEP_NS_DECLS XCT_TEXT_AS_STRING XCT_ATTRIBUTE_ARRAY XCT_PRESERVE_PARENT XCT_MERGE_TEXT_NODES XCT_LINE_NUMBERS XCT_DOCUMENT_ROOT )); $EXPORT_TAGS{flags} = \@flags; my %c = map { ($flags[$_] => (1 << $_)) } 0..$#flags; \%c }; BEGIN { @EXPORT = (map @$_, values %EXPORT_TAGS); @EXPORT_OK = @EXPORT; $EXPORT_TAGS{all}=\@EXPORT_OK; } =head1 SYNOPSIS use XML::CompactTree; use XML::LibXML::Reader; my $reader = XML::LibXML::Reader->new(location => $url); ... my $tree = XML::CompactTree::readSubtreeToPerl($reader); ... =head1 DESCRIPTION This module provides functions that use XML::LibXML::Reader to parse an XML document into a parse tree formed of nested arrays (and hashes). It aims to be fast in doing that and to presreve all relevant information from the XML (including namespaces, document order, mixed content, etc.). It sacrifices user friendliness for speed. IMPORTANT: There is an even more efficient XS implementation of this module called XML::CompactTree::XS with 100% equivalent functionality. =head1 PURPOSE I wrote this module because I noticed that repeated calls to methods implemented in C (XS) were very expensive in Perl. Therefore traversing a large DOM tree using XML::LibXML or iterating over an XML stream using XML::LibXML::Reader was much slower than traversing similarly large and structured native Perl data structures. This module allows the user to build a document parse tree consisting of native Perl data structures (arrays and optionally hashes) using XML::LibXML::Reader with minimal number of XS calls. (Note that there XML::CompactTree::XS is 100% equivalent of this module that manages the same with just one XS call.) It does not provide full DOM navigation but attempts to provide maximum amount of information. Its memory footprint should be somewhat smaller than that of a corresponding XML::LibXML DOM tree. =head1 EXPORT By default, the following constants are exported (C<:flags> export tag) to be used as flags for the tree builder: XCT_IGNORE_WS XCT_IGNORE_SIGNIFICANT_WS XCT_IGNORE_PROCESSING_INSTRUCTIONS XCT_IGNORE_COMMENTS XCT_USE_QNAMES /* not yet implemented */ XCT_KEEP_NS_DECLS XCT_TEXT_AS_STRING /* not yet implemented */ XCT_ATTRIBUTE_ARRAY XCT_PRESERVE_PARENT /* not yet implemented */ XCT_MERGE_TEXT_NODES /* not yet implemented */ XCT_DOCUMENT_ROOT =head1 FUNCTIONS =head2 readSubtreeToPerl( $reader, $flags, \my %ns ) Uses a given XML::LibXML::Reader parser objects to parse a subtree at the current reader position to build a tree formed of nested arrays (see L). =over 4 =item reader A XML::LibXML::Reader object to use as the reader. While building the tree, the reader moves to the next node on the current or higher level. =item flags An integer consisting of 1 bit flags (see constants in the EXPORT section). Use binary or (|) to combine individual flags. The following flags are NOT implemented yet: XCT_USE_QNAMES, XCT_TEXT_AS_STRING, XCT_PRESERVE_PARENT, XCT_MERGE_TEXT_NODES =item ns You may pass an empty hash reference that will be populated by a namespace_uri to namespace_index map, that can be used to decode namespace indexes in the resulting data structure (see L). =back =cut sub readSubtreeToPerl { my ($reader,$flags,$ns)=@_; $ns||={}; $ns->{''}=0; my $ret = _readSubtreeToPerl($reader,$flags,$ns,1,0); return $ret->[0]; } =head2 readLevelToPerl( $reader, $flags, $ns ) Like C, but reads the subtree at the current reader position and all its following siblings. It returns an array reference of representations of these subtrees as in the format described in L. =cut sub readLevelToPerl { my ($reader,$flags,$ns)=@_; $ns||={}; $ns->{''}=0; my $ret = _readSubtreeToPerl($reader,$flags,$ns,1,1); return $ret; } sub _readSubtreeToPerl { my ($reader, $flags, $ns_map, $free_ns_index, $read_siblings) = @_; my @parents; my ($av,$prev,$kids,$ret,$type,$name); my $cur_depth=$reader->depth(); my $start_depth = $cur_depth; my $prev_depth = $start_depth; my $top = []; if ($reader->nodeType()==0) { return if $reader->read()!=1; if ($flags & XCT_DOCUMENT_ROOT) { $prev = [ XML_READER_TYPE_DOCUMENT, $reader->encoding, ]; $start_depth --; $prev_depth --; push @$top, $prev; push @parents, $prev; } } do {{ $type = $reader->nodeType(); # warn("$type, $cur_depth, ".$reader->name."\n"); if ($type == XML_READER_TYPE_NONE or $type == XML_READER_TYPE_ATTRIBUTE or $type == XML_READER_TYPE_DOCUMENT_TYPE or $type == XML_READER_TYPE_END_ELEMENT or $type == XML_READER_TYPE_ENTITY or $type == XML_READER_TYPE_END_ENTITY or $type == XML_READER_TYPE_XML_DECLARATION) { $ret = $reader->read(); } else { if (($flags & (XCT_IGNORE_WS|XCT_IGNORE_SIGNIFICANT_WS)) and $type == XML_READER_TYPE_WHITESPACE or ($flags & XCT_IGNORE_SIGNIFICANT_WS) and $type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE or ($flags & XCT_IGNORE_COMMENTS) and $type == XML_READER_TYPE_COMMENT or ($flags & XCT_IGNORE_PROCESSING_INSTRUCTIONS and $type == XML_READER_TYPE_PROCESSING_INSTRUCTION)) { $ret = $reader->read(); } else { my @av=(); $av=\@av; push @av, $type; if ($type == XML_READER_TYPE_ELEMENT) { # warn(" element\n"); push @av, $reader->localName(); $name = $reader->namespaceURI(); if ($name) { if (exists($ns_map->{$name})) { push(@av, $ns_map->{$name} || 0); } else { # warn("storing namespace $name as $free_ns_index)"; push(@av, $free_ns_index); $ns_map->{$name}=$free_ns_index; $free_ns_index++; } } else { push(@av, 0); # no namespace } if ($reader->hasAttributes() && $reader->moveToFirstAttribute()==1) { if ($flags & XCT_ATTRIBUTE_ARRAY) { my @attrs; do { $name = $reader->name(); if (($flags & XCT_KEEP_NS_DECLS) || substr($name,0,5) ne 'xmlns' ) { push(@attrs, $name); push(@attrs, $reader->value()); } } while ($reader->moveToNextAttribute()==1); # $reader->moveToElement(); push(@av, \@attrs); } else { my %attrs; do { $name = $reader->name(); if (($flags & XCT_KEEP_NS_DECLS) || substr($name,0,5) ne 'xmlns' ) { $attrs{$name}=$reader->value(); } } while ($reader->moveToNextAttribute()==1); $reader->moveToElement(); push(@av, \%attrs); } } else { push(@av, undef); # no attributes } if ($flags & XCT_LINE_NUMBERS) { push(@av, $reader->lineNumber()); } } elsif ($type == XML_READER_TYPE_TEXT or $type == XML_READER_TYPE_CDATA or $type == XML_READER_TYPE_COMMENT or $type == XML_READER_TYPE_WHITESPACE or $type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE) { push(@av, $reader->value()); } elsif ($type == XML_READER_TYPE_ENTITY_REFERENCE or $type == XML_READER_TYPE_PROCESSING_INSTRUCTION or $type == XML_READER_TYPE_NOTATION) { push(@av, $reader->localName()); push(@av, $reader->value()); } elsif ($type == XML_READER_TYPE_DOCUMENT or $type == XML_READER_TYPE_DOCUMENT_FRAGMENT) { push(@av, $reader->encoding()); } if ($cur_depth==$start_depth) { push(@$top, $av); $prev_depth = $cur_depth; $kids = undef; } elsif ($cur_depth > $prev_depth) { $kids=[]; push(@$prev, $kids); push(@$kids, $av); push(@parents, $prev); $prev_depth = $cur_depth; } elsif ($cur_depth == $prev_depth) { push(@$kids, $av) if $kids; } else { do { $prev_depth--; pop(@parents); } while ($cur_depth < $prev_depth); my $p = $parents[-1]; if ($p) { $prev = $p; $p = $prev->[-1]; if ($p) { $kids = $p; push(@$kids, $av); } } } $prev = $av; $ret = $reader->read(); } } # print STDERR "$cur_depth, ",$reader->depth(),"\n"; }} while ($ret == 1 && ($cur_depth = $reader->depth()) > ($start_depth - ($read_siblings ? 1 : 0))); if ($ret == 1) { if ($reader->depth() == $start_depth && $reader->nodeType() == XML_READER_TYPE_END_ELEMENT) { $reader->read(); } } return $top; } =head1 OUTPUT FORMAT The result of parsing a subtree is a Perl array reference C<$node> contains a node type followed by node data whose interpretation on further positions in $node depends on the node type, as described below: =head2 Any Node =over 5 =item * $node->[0] is an integer representing the node type. Use XML::LibXML::Reader node-tye constants, e.g. XML_READER_TYPE_ELEMENT for an element node, XML_READER_TYPE_TEXT for text node, etc. =back =head2 Document or Document Fragment Nodes =over 5 =item * $node->[1] contains the document encoding =item * $node->[2] is an array reference containing similar represention of all the child nodes of the document (fragment). =back Note: XML::LibXML::Reader does not document node by default, which means that calling readSubtreeToPerl on a reader object in its initial state only parses the first node in the document (which can be the root element, but also a comment or a processing instruction). Use XCT_DOCUMENT_ROOT flag to force creating a document node in such case. =head2 Element nodes =over 5 =item * $node->[1] is the local name (UTF-8 encoded character string) =item * $node->[2] is the namespace index (see L below) =item * $node->[3] is undef if the element has no attributes. Otherwise if XCT_ATTRIBUTE_ARRAY flag was used, $node->[3] is an array reference of the form C<[ name1, value1, name2, value2, ....]> of attribute names and corresponding values. If XCT_ATTRIBUTE_ARRAY flag was not used, then $node->[3] is a hash reference mapping attribute names to the corresponding attribute values C<{ name1=>value1, name2=>value2...}> The flag XCT_KEEP_NS_DECLS controls whether namespace declarations (xmlns=... or xmlns:prefix=...) are included along with normal attributes or not. Note: there is no support for namespaced attributes yet, but the attribute names are stored as QNames, so one can always use XCT_KEEP_NS_DECLS to keep track of namespace prefix declarations and do the resolving manually. Support for namespaced attributes is planned. =item * If XTC_LINE_NUMBERS flag was used, $node->[4] contains the line number of the element and $node->[5] contains an array reference containing similar representions of the child nodes of the current node. =item * If XTC_LINE_NUMBERS flag was NOT used, $node->[4] contains an array reference of similar representations of the child nodes of the current node. =back =head2 Text, CDATA, Comment and White-Space Nodes =over 5 =item * $node->[1] contains the node value (UTF-8 encoded character string) =back =head2 Unparsed Entity, Processing-Instruction, and Notation Nodes =over 5 =item * $node->[1] contains the local name (there is no support for namespaces on these types of nodes yet) =item * $node->[2] contains the node value =back =head2 Skipping Less-Significant Nodes White-space (non-significant or significant), processing-instruction and comment nodes can be completely skipped, using the following flags: XCT_IGNORE_WS XCT_IGNORE_SIGNIFICANT_WS XCT_IGNORE_PROCESSING_INSTRUCTIONS XCT_IGNORE_COMMENTS =head1 NAMESPACES Namespaces of element nodes are stored in the element node as an integer. 0 always represents nodes without namespace, all other namespaces are assigned unique numbers in an increasing order as they appear. You can pass an empty hash reference to the parsing functions to obtain the mapping. =head2 Example use XML::CompactTree; use XML::LibXML::Reader; my $reader = XML::LibXML::Reader->new(location => $ARGV[0]); my %ns; my $data = XML::CompactTree::readSubtreeToPerl( $reader, XCT_DOCUMENT_ROOT, \%ns ); $ns_map[$ns{$_}]=$_ for keys %ns; my @nodes = ($data); while (@nodes) { my $node = shift @nodes; my $type = $node->[0]; if ($type == XML_READER_TYPE_ELEMENT) { print "element $node->[1] is from ns $node->[2] '$ns_map[$node->[2]]'\n"; push @nodes, @{$node->[4]}; # queue children } elsif ($type == XML_READER_TYPE_DOCUMENT) { push @nodes, @{$node->[2]}; # queue children } } =head1 PLANNED FEATURES Planned flags: XCT_USE_QNAMES - use QNames instead of local names for all nodes XCT_TEXT_AS_STRING - put text nodes into the tree as plain scalars XCT_PRESERVE_PARENT - add a slot with a weak reference to the parent node XCT_MERGE_TEXT_NODES - merge adjacent text/cdata nodes together Features: allow blessing the array refs to default or user-specified classes; the default classes would provide a very small subset of DOM methods to retrieve node information, manipulate the tree, and possibly serialize the parse tree back to XML. =head1 AUTHOR Petr Pajas, 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 & LICENSE Copyright 2008-2009 Petr Pajas, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO XML::CompactTree::XS XML::LibXML::Reader =cut 1; # End of XML::CompactTree XML-CompactTree-0.03/MANIFEST0000644000175000001440000000032411166650160014447 0ustar pajasusersMakefile.PL Changes MANIFEST README CompactTree.pm t/00-load.t t/01-object.t t/02-feature.t t/boilerplate.t t/pod-coverage.t t/pod.t META.yml Module meta-data (added by MakeMaker) XML-CompactTree-0.03/META.yml0000664000175000001440000000076011166650160014575 0ustar pajasusers--- #YAML:1.0 name: XML-CompactTree version: 0.03 abstract: Fast parser of XML document into nested arrays license: ~ author: - Petr Pajas generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: Test::More: 0 XML::LibXML: 1.68 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 XML-CompactTree-0.03/Makefile.PL0000644000175000001440000000077011120034213015256 0ustar pajasusersBEGIN { if ($] < 5.006_001) { warn "\nSorry, at least Perl 5.6.1 is required for this module!\n\n"; exit; } } use ExtUtils::MakeMaker; use Config; $|=0; my %meta = ( NAME => 'XML::CompactTree', ABSTRACT => 'Fast parser of XML document into nested arrays', AUTHOR => 'Petr Pajas ', VERSION_FROM => 'CompactTree.pm', PREREQ_PM => { 'Test::More' => 0, 'XML::LibXML' => 1.68, }, ); WriteMakefile( %meta ); XML-CompactTree-0.03/README0000644000175000001440000000303511120034213014161 0ustar pajasusersXML-CompactTree-XS This module provides functions that use XML::LibXML::Reader to parse an XML document into a tree formed of nested arrays (and hashes). It aims to be very fast in doing that and to presreve all relevant information from the XML (including namespaces, document order, mixed content, etc.). INSTALLATION The module requires libxml2 library and header files to be installed (e.g. libxml2 and libxml2-devel packages on most Linux distributions). Build.PL attempts to obtain the compiler and linker flags for linking against this library by calling xml2-config --cflags --libs. If this tool does not come with your libxml2 installation, you may specify the flags by hand, by setting the CFLAGS and LD_FLAGS environment variables accordingly. To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc XML::CompactTree::XS You can also look for information at: Search CPAN http://search.cpan.org/dist/XML-CompactTree-XS CPAN Request Tracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-CompactTree-XS AnnoCPAN, annotated CPAN documentation: http://annocpan.org/dist/XML-CompactTree-XS CPAN Ratings: http://cpanratings.perl.org/d/XML-CompactTree-XS COPYRIGHT AND LICENCE Copyright (C) 2008 Petr Pajas This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. XML-CompactTree-0.03/t/0000755000175000001440000000000011166650160013562 5ustar pajasusersXML-CompactTree-0.03/t/00-load.t0000644000175000001440000000023611120034212015064 0ustar pajasusers#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'XML::CompactTree' ); } diag( "Testing XML::CompactTree $XML::CompactTree::VERSION, Perl $], $^X" ); XML-CompactTree-0.03/t/01-object.t0000644000175000001440000000017711120034212015420 0ustar pajasusers use Test::More tests => 2; use strict; use warnings; BEGIN { use_ok( 'XML::CompactTree' ); use_ok( 'XML::LibXML::Reader' ); } XML-CompactTree-0.03/t/02-feature.t0000644000175000001440000001145011166621031015615 0ustar pajasusers use Test::More tests => 2 + 4*13 + 4*20 + 4*13; use strict; use warnings; BEGIN { use_ok( 'XML::CompactTree' ); use_ok( 'XML::LibXML::Reader' ); import XML::CompactTree; } my $xml = < ab EOF print "block 1\n"; for my $flags ( XCT_IGNORE_SIGNIFICANT_WS, XCT_IGNORE_SIGNIFICANT_WS | XCT_KEEP_NS_DECLS, XCT_IGNORE_SIGNIFICANT_WS | XCT_ATTRIBUTE_ARRAY, XCT_IGNORE_SIGNIFICANT_WS | XCT_ATTRIBUTE_ARRAY | XCT_KEEP_NS_DECLS, ) { print "flags: $flags\n"; my $reader; my %ns; ok( $reader = XML::LibXML::Reader->new(string => $xml), "reader ok"); isa_ok($reader,"XML::LibXML::Reader"); is( $reader->nextElement, 1, "first element ok"); my $result; ok( $result = XML::CompactTree::readSubtreeToPerl($reader,$flags,\%ns), "result ok" ); #use Data::Dumper; #print Dumper($result,\%ns); isa_ok( $result, 'ARRAY', "result not an array" ); is( $result->[0], XML_READER_TYPE_ELEMENT, "node type" ); is( $result->[1], 'foo', "node name" ); my ($foo_ns,$a_ns); ok( ($a_ns = $ns{'http://a.bar.baz'}), "namespace 1 found" ); is( $result->[2], $a_ns, "node namespace ok" ); if ($flags & XCT_ATTRIBUTE_ARRAY) { ok( ref($result->[3]) eq 'ARRAY', "attributes are an array" ); my %a = @{$result->[3]}; ok( $a{bar} eq "baz", "attributes ok" ); } else { ok( ref($result->[3]) eq 'HASH', "attributes are a hash" ); ok( $result->[3]->{bar} eq "baz", "attributes ok" ); } use Data::Dumper; print Dumper($result); ok( (ref($result->[4]) eq 'ARRAY' and @{$result->[4]} == 2), "children ok" ); ok( ($foo_ns = $ns{'http://foo.bar.baz'}), "namespace 2 found" ); } print "block 2\n"; for my $flags ( XCT_IGNORE_SIGNIFICANT_WS, XCT_IGNORE_SIGNIFICANT_WS | XCT_KEEP_NS_DECLS, XCT_IGNORE_SIGNIFICANT_WS | XCT_ATTRIBUTE_ARRAY, XCT_IGNORE_SIGNIFICANT_WS | XCT_ATTRIBUTE_ARRAY | XCT_KEEP_NS_DECLS, ) { print "flags: $flags\n"; my $reader; my %ns; ok( $reader = XML::LibXML::Reader->new(string => $xml), "reader ok"); $reader->nextElement('bar'); isa_ok($reader,"XML::LibXML::Reader"); my $result; ok( $result = XML::CompactTree::readLevelToPerl($reader,$flags,\%ns), "result ok" ); isa_ok( $result, 'ARRAY', "result not an array" ); is( scalar(@$result), 2, "number of results ok" ); test_bar($result->[0],$flags,\%ns); test_x($result->[1],$flags,\%ns); #use Data::Dumper; #print Dumper($result,\%ns); } print "block 3\n"; for my $flags ( XCT_IGNORE_SIGNIFICANT_WS, XCT_IGNORE_SIGNIFICANT_WS | XCT_KEEP_NS_DECLS, XCT_IGNORE_SIGNIFICANT_WS | XCT_ATTRIBUTE_ARRAY, XCT_IGNORE_SIGNIFICANT_WS | XCT_ATTRIBUTE_ARRAY | XCT_KEEP_NS_DECLS| XCT_LINE_NUMBERS, ) { print "flags: $flags\n"; my $reader; my %ns; ok( $reader = XML::LibXML::Reader->new(string => $xml), "reader ok"); $reader->nextElement('bar'); isa_ok($reader,"XML::LibXML::Reader"); my $result; ok( $result = XML::CompactTree::readSubtreeToPerl($reader,$flags,\%ns), "result ok" ); test_bar($result,$flags,\%ns); ok( !exists($ns{'http://foo.bar.baz'}), "no other namespace" ); #use Data::Dumper; #print Dumper($result,\%ns); } sub test_bar { my ($result,$flags,$ns)=@_; is( $result->[0], XML_READER_TYPE_ELEMENT, "node type" ); is( $result->[1], 'bar', "node name" ); my ($a_ns); ok( ($a_ns = $ns->{'http://a.bar.baz'}), "namespace 1 found" ); is( $result->[2], $a_ns, "node namespace ok" ); if ($flags & XCT_ATTRIBUTE_ARRAY) { ok( ref($result->[3]) eq 'ARRAY', "attributes are an array" ); my %a = @{$result->[3]}; ok( $a{x} eq "y", "attributes ok" ); } else { ok( ref($result->[3]) eq 'HASH', "attributes are a hash" ); ok( $result->[3]->{x} eq "y", "attributes ok" ); } my $children_offset = 4 + ($flags & XCT_LINE_NUMBERS ? 1 : 0); isa_ok( $result->[$children_offset], 'ARRAY', "children ok"); is(scalar @{$result->[$children_offset]},3, "children count ok" ); my $line_no; if ($flags & XCT_LINE_NUMBERS) { $line_no = $result->[$children_offset][1][4]; # no way to be sure what XML::LibXML will give here } is_deeply($result->[$children_offset], [ [ XML_READER_TYPE_TEXT, 'a' ], [ XML_READER_TYPE_ELEMENT, 'baz', $ns->{'http://a.bar.baz'}, undef, (($flags & XCT_LINE_NUMBERS) ? $line_no : ()) ], [ XML_READER_TYPE_TEXT, 'b' ], ], "structure ok" ); } sub test_x { my ($result,$flags,$ns)=@_; is( $result->[0], XML_READER_TYPE_ELEMENT, "node type" ); is( $result->[1], 'x', "node name" ); my ($foo_ns); ok( ($foo_ns = $ns->{'http://foo.bar.baz'}), "namespace 2 found" ); is( $result->[2], $foo_ns, "node namespace ok" ); ok( !defined($result->[3]), "no attributes"); my $children_offset = 4 + ($flags & XCT_LINE_NUMBERS ? 1 : 0); ok( !exists($result->[$children_offset]), "no children"); } XML-CompactTree-0.03/t/boilerplate.t0000644000175000001440000000231611120034212016233 0ustar pajasusers#!perl -T use strict; use warnings; use Test::More tests => 3; sub not_in_file_ok { my ($filename, %regex) = @_; open my $fh, "<", $filename or die "couldn't open $filename for reading: $!"; my %violated; while (my $line = <$fh>) { while (my ($desc, $regex) = each %regex) { if ($line =~ $regex) { push @{$violated{$desc}||=[]}, $.; } } } if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } } not_in_file_ok(README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, ); not_in_file_ok(Changes => "placeholder date/time" => qr(Date/time) ); sub module_boilerplate_ok { my ($module) = @_; not_in_file_ok($module => 'the great new $MODULENAME' => qr/ - The great new /, 'boilerplate description' => qr/Quick summary of what the module/, 'stub function definition' => qr/function[12]/, ); } module_boilerplate_ok('CompactTree.pm'); XML-CompactTree-0.03/t/pod-coverage.t0000644000175000001440000000025411120034212016303 0ustar pajasusers#!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-CompactTree-0.03/t/pod.t0000644000175000001440000000021411120034212014506 0ustar pajasusers#!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();