File Coverage

blib/lib/Net/Amazon/S3/Request/Role/XML/Content.pm
Criterion Covered Total %
statement 21 21 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 2 2 100.0
pod n/a
total 27 30 90.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Role providing XML content
2             $Net::Amazon::S3::Request::Role::XML::Content::VERSION = '0.991';
3             use Moose::Role;
4 99     99   54225  
  99         247  
  99         825  
5             with 'Net::Amazon::S3::Request::Role::HTTP::Header::Content_length';
6             with 'Net::Amazon::S3::Request::Role::HTTP::Header::Content_type' => { content_type => 'application/xml' };
7              
8             my ($self, $root_name, $root_content) = @_;
9              
10 39     39   139 my $ns = Net::Amazon::S3::Constants->S3_NAMESPACE_URI;
11              
12 39         284 my $xml_doc = XML::LibXML::Document->new ('1.0','UTF-8');
13             my $root_element = $xml_doc->createElementNS ($ns, $root_name);
14 39         461 $xml_doc->setDocumentElement ($root_element);
15 39         486  
16 39         201 my @queue = ([ $root_element, $root_content ]);
17             while (my $node = shift @queue) {
18 39         698 my ($parent, $content) = @$node;
19 39         160  
20 117         1293 for my $tag (@$content) {
21             my ($tag_name, $tag_content) = %$tag;
22 117         207 my $tag_node = $parent->addNewChild ($ns, $tag_name);
23 195         1016  
24 195         831 if (ref $tag_content) {
25             push @queue, [$tag_node, $tag_content];
26 195 100       424 next;
27 78         177 }
28 78         280  
29             if (defined $tag_content && length $tag_content) {
30             $tag_node->addChild ($xml_doc->createTextNode ($tag_content));
31 117 50 33     397 next;
32 117         762 }
33 117         516 }
34             }
35              
36             $xml_doc->toString;
37             }
38 39         910  
39             1;
40              
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             Net::Amazon::S3::Request::Role::XML::Content - Role providing XML content
49              
50             =head1 VERSION
51              
52             version 0.991
53              
54             =head1 AUTHOR
55              
56             Branislav Zahradník <barney@cpan.org>
57              
58             =head1 COPYRIGHT AND LICENSE
59              
60             This software is copyright (c) 2022 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník.
61              
62             This is free software; you can redistribute it and/or modify it under
63             the same terms as the Perl 5 programming language system itself.
64              
65             =cut