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             package Net::Amazon::S3::Request::Role::XML::Content;
2             # ABSTRACT: Role providing XML content
3             $Net::Amazon::S3::Request::Role::XML::Content::VERSION = '0.98';
4 96     96   73056 use Moose::Role;
  96         291  
  96         993  
5              
6             with 'Net::Amazon::S3::Request::Role::HTTP::Header::Content_length';
7             with 'Net::Amazon::S3::Request::Role::HTTP::Header::Content_type' => { content_type => 'application/xml' };
8              
9             sub _build_xml {
10 39     39   169 my ($self, $root_name, $root_content) = @_;
11              
12 39         501 my $ns = Net::Amazon::S3::Constants->S3_NAMESPACE_URI;
13              
14 39         711 my $xml_doc = XML::LibXML::Document->new ('1.0','UTF-8');
15 39         747 my $root_element = $xml_doc->createElementNS ($ns, $root_name);
16 39         308 $xml_doc->setDocumentElement ($root_element);
17              
18 39         886 my @queue = ([ $root_element, $root_content ]);
19 39         192 while (my $node = shift @queue) {
20 117         1717 my ($parent, $content) = @$node;
21              
22 117         273 for my $tag (@$content) {
23 195         1513 my ($tag_name, $tag_content) = %$tag;
24 195         1030 my $tag_node = $parent->addNewChild ($ns, $tag_name);
25              
26 195 100       515 if (ref $tag_content) {
27 78         214 push @queue, [$tag_node, $tag_content];
28 78         366 next;
29             }
30              
31 117 50 33     540 if (defined $tag_content && length $tag_content) {
32 117         1043 $tag_node->addChild ($xml_doc->createTextNode ($tag_content));
33 117         575 next;
34             }
35             }
36             }
37              
38 39         1144 $xml_doc->toString;
39             }
40              
41             1;
42              
43             __END__
44              
45             =pod
46              
47             =encoding UTF-8
48              
49             =head1 NAME
50              
51             Net::Amazon::S3::Request::Role::XML::Content - Role providing XML content
52              
53             =head1 VERSION
54              
55             version 0.98
56              
57             =head1 AUTHOR
58              
59             Branislav Zahradník <barney@cpan.org>
60              
61             =head1 COPYRIGHT AND LICENSE
62              
63             This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník.
64              
65             This is free software; you can redistribute it and/or modify it under
66             the same terms as the Perl 5 programming language system itself.
67              
68             =cut