| 1 | 3 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use feature 'class'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | no warnings 'experimental::class'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | class Azure::SDK::Storage::Queues::Serializer { | |||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use bytes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use XML::LibXML (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Azure::SDK::Storage::Queues::Message; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Azure::SDK::Storage::Queues::QueueItem; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Azure::SDK::Storage::Queues::QueuePage; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use constant DEFAULT_MAX_BYTES => 8 * 1024 * 1024; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use constant MAX_MESSAGE_BYTES => 64 * 1024; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | field $max_bytes :param :reader = DEFAULT_MAX_BYTES; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | field $parser = undef; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 27 | ▶ | ADJUST { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 27 | ▶ | croak 'Azure::SDK::Storage::Queues::Serializer max_bytes must be a positive integer' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $max_bytes and $max_bytes =~ /\A[0-9]+\z/u and $max_bytes > 0
defined $max_bytes and $max_bytes =~ /\A[0-9]+\z/u
MC/DC0%0/3
defined $max_bytes and $max_bytes =~ /\A[0-9]+\z/u and $max_bytes > 0
defined $max_bytes
$max_bytes =~ /\A[0-9]+\z/u
$max_bytes > 0
Truth table25%1/4
A and B and C
A= defined $max_bytesB= $max_bytes =~ /\A[0-9]+\z/uC= $max_bytes > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | unless defined $max_bytes && $max_bytes =~ /\A[0-9]+\z/ && $max_bytes > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 27 | $parser = XML::LibXML->new( | |||||||||||||||||||||||||||||||||||||||||
| 24 | no_network => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | load_ext_dtd => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | expand_entities => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | huge => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | recover => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | no_blanks => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | $parser->set_option(ext_ent_handler => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | croak 'Refusing to resolve an external entity in a Queue response'; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 27 | }); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | ▶ | method serialize_message ($message_text) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize_message: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | croak 'Queue message text is required' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $message_text and not ref $message_text
MC/DC0%0/2
defined $message_text and not ref $message_text
defined $message_text
not ref $message_text
Truth table33%1/3
A and not(B)
A= defined $message_textB= not ref $message_text
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | unless defined $message_text && !ref $message_text; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | utf8::upgrade($message_text); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | croak 'Queue message text contains a character not permitted by XML 1.0' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | if $message_text =~ /[^\x09\x0a\x0d\x20-\x{d7ff}\x{e000}-\x{fffd}\x{10000}-\x{10ffff}]/; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | my $text_bytes = $message_text; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | utf8::encode($text_bytes); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | croak 'Queue message text exceeds ' . MAX_MESSAGE_BYTES . ' bytes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | if bytes::length($text_bytes) > MAX_MESSAGE_BYTES; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | my $document = XML::LibXML::Document->new('1.0', 'UTF-8'); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | my $root = $document->createElement('QueueMessage'); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | my $text = $document->createElement('MessageText'); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | $text->appendText($message_text); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | $root->appendChild($text); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | $document->setDocumentElement($root); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | my $xml = $document->toString(0); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | utf8::encode($xml) if utf8::is_utf8($xml); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 11 | ▶ | method parse_queue_list ($xml) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_queue_list: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 11 | my $document = $self->_parse($xml); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 10 | my ($root) = $document->findnodes('/*[local-name()="EnumerationResults"]'); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 10 | ▶ | croak 'Queue listing response is not an EnumerationResults document' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | unless $root; | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | my @items; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 9 | for my $node ($root->findnodes('./*[local-name()="Queues"]/*[local-name()="Queue"]')) { | |||||||||||||||||||||||||||||||||||||||||
| 68 | 10 | push @items, Azure::SDK::Storage::Queues::QueueItem->new( | |||||||||||||||||||||||||||||||||||||||||
| 69 | name => _required_child_text($node, 'Name'), | ||||||||||||||||||||||||||||||||||||||||||
| 70 | metadata => _metadata($node), | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | ▶ | return Azure::SDK::Storage::Queues::QueuePage->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | items => \@items, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | continuation_token => _child_text($root, 'NextMarker'), | ||||||||||||||||||||||||||||||||||||||||||
| 77 | service_endpoint => $root->hasAttribute('ServiceEndpoint') | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ? $root->getAttribute('ServiceEndpoint') | ||||||||||||||||||||||||||||||||||||||||||
| 79 | : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | prefix => _child_text($root, 'Prefix'), | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 11 | ▶ | method parse_messages ($xml) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_messages: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 11 | my $document = $self->_parse($xml); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 10 | my ($root) = $document->findnodes('/*[local-name()="QueueMessagesList"]'); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | ▶ | croak 'Queue messages response is not a QueueMessagesList document' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | unless $root; | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 9 | my @messages; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 9 | for my $node ($root->findnodes('./*[local-name()="QueueMessage"]')) { | |||||||||||||||||||||||||||||||||||||||||
| 92 | 9 | push @messages, Azure::SDK::Storage::Queues::Message->new( | |||||||||||||||||||||||||||||||||||||||||
| 93 | message_id => _required_child_text($node, 'MessageId'), | ||||||||||||||||||||||||||||||||||||||||||
| 94 | message_text => _child_text($node, 'MessageText', 1), | ||||||||||||||||||||||||||||||||||||||||||
| 95 | pop_receipt => _child_text($node, 'PopReceipt'), | ||||||||||||||||||||||||||||||||||||||||||
| 96 | insertion_time => _child_text($node, 'InsertionTime'), | ||||||||||||||||||||||||||||||||||||||||||
| 97 | expiration_time => _child_text($node, 'ExpirationTime'), | ||||||||||||||||||||||||||||||||||||||||||
| 98 | time_next_visible => _child_text($node, 'TimeNextVisible'), | ||||||||||||||||||||||||||||||||||||||||||
| 99 | dequeue_count => _child_text($node, 'DequeueCount'), | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 7 | return \@messages; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 22 | ▶ | method _parse ($xml) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 22 | ▶ | croak 'Queue response body is empty' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $xml and length $xml
MC/DC0%0/2
defined $xml and length $xml
defined $xml
length $xml
Truth table33%1/3
A and B
A= defined $xmlB= length $xml
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | unless defined $xml && length $xml; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 22 | ▶ | croak 'Queue response body exceeds ' . $max_bytes . ' bytes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | if bytes::length($xml) > $max_bytes; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 21 | my $document = $parser->load_xml(string => $xml); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 21 | ▶ | croak 'Queue response body must not contain a document type declaration' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $document->internalSubset or defined $document->externalSubset
MC/DC50%1/2
defined $document->internalSubset or defined $document->externalSubset
defined $document->internalSubset
defined $document->externalSubset
Truth table66%2/3
A or B
A= defined $document->internalSubsetB= defined $document->externalSubset
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | if defined $document->internalSubset || defined $document->externalSubset; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 20 | return $document; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 9 | ▶ | sub _metadata ($queue_node) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_metadata: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | my ($metadata_node) = $queue_node->findnodes('./*[local-name()="Metadata"]'); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | ▶ | return {} unless $metadata_node; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | my %metadata; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | for my $child ($metadata_node->childNodes) { | |||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | ▶ | next unless $child->nodeType == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | my $name = lc $child->nodeName; | |||||||||||||||||||||||||||||||||||||||||
| 125 | croak "Queue metadata repeats '$name'" | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | if exists $metadata{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | $metadata{$name} = $child->textContent; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | return \%metadata; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 19 | ▶ | sub _required_child_text ($node, $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_required_child_text: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 19 | my $value = _child_text($node, $name); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 19 | ▶ | croak "Queue response is missing required $name" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 17 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 81 | ▶ | sub _child_text ( $node, $name, $preserve_empty = 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_child_text: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 81 | my ($child) = $node->findnodes('./*[local-name()="' . $name . '"]'); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 81 | ▶ | return undef unless $child; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 60 | my $text = $child->textContent; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 60 | ▶ | return $text if $preserve_empty || length $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$preserve_empty or length $text
MC/DC100%2/2
$preserve_empty or length $text
$preserve_empty
length $text
Truth table100%3/3
A or B
A= $preserve_emptyB= length $text
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||||||||||||||||||||||||