blib/lib/XML/ED/NodeSet.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 71 CC 9 SCAR 36.9
CC
9
Cov
0%
to_xml
72.0
_attributes
6.0
child
2.0
CRAP 39.9
1 package XML::ED::NodeSet;
2 use strict;
3 use warnings;
4  
5 =over 4
6  
7 =item child
8  
9 Return a NodeSet of all of the children of this node set
10  
11 =cut
12  
13 sub child
14 {
15 my $self = shift;
16  
17 return bless [ map({ @{$_->child() || []} } @$self) ], __PACKAGE__;
18 }
19  
20 =over 4
21  
22 =item to_string
23  
24 render the nodeset as a string
25  
26 =cut
27  
28 sub to_string
29 {
30 use Data::Dumper;
31  
32 Dumper [ 'bob', @_ ];
33  
34 }
35  
36 sub _attributes
37 {
38 my $object = shift;
39  
40 my @keys = grep {!/^_/} keys %$object;
41  
42 return @keys ? ' ' . join(' ', map({ sprintf(qq($_="%s"), $object->{$_}->{value}) } sort @keys)) : '';
43 }
44  
45 =item to_xml
46  
47 render the nodeset as an xml string
48  
49 =cut
50  
51 sub to_xml
52 {
53 my $object = shift;
54  
55 my @data = ();
56 for my $obj (@$object) {
57 if ($obj->{_type} == 0) {
58 push @data, to_xml($obj->{_data});
59 } elsif ($obj->{_type} == 1) {
60 if (defined $obj->{_data}) {
61 push @data, sprintf("<%s%s>", $obj->{_name}, _attributes( $obj )), to_xml($obj->{_data}), sprintf("</%s>", $obj->{_name});
62 } else {
63 push @data, sprintf("<%s%s/>", $obj->{_name}, _attributes( $obj ));
64 }
65 } elsif ($obj->{_type} == 5) {
66 push @data, $obj->{_value} || '';
67 } elsif ($obj->{_type} == 12) {
68 push @data, sprintf("<!--%s-->", $obj->{_value});
69 } elsif ($obj->{_type} == 10) {
70 push @data, sprintf("<!%s>", $obj->{_value});
71 } elsif ($obj->{_type} == 2) {
72 push @data, sprintf("<?%s%s?>", $obj->{_name}, _attributes( $obj ));
73 } else {
74 warn "x";
75 push @data, $obj->{_type};
76 }
77 }
78 return join('', @data);
79 }
80  
81 1;
82  
83 =back
84  
85 http://www.w3.org/TR/xpath20/