Mango.pm

filter: Statementstmt 98.9% 197 / 199 Branchbran 78.1% 75 / 96 Conditioncond 64.5% 31 / 48 MC/DCmcdc 29.6% 8 / 27 Subroutinesub 100% 43 / 43 Podpod 66.6% 2 / 3 totaltotal 85.5% 356 / 416 CC 72 SCAR 16.9
CC
72
Cov
88%
__ANON__
15.5
_command_extract
10.3
_plain
6.1
CRAP 5.4
↑ Summary Mango/TestSuiteInjection.pm »
1 package OpenTelemetry::Instrumentation::Mango;
2 # ABSTRACT: OpenTelemetry instrumentation for Mango
3  
4 3 our $VERSION = '0.01';
5  
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Class::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Class::Method::Modifiers 'install_modifier';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use OpenTelemetry::Constants qw(SPAN_KIND_CLIENT SPAN_STATUS_ERROR SPAN_STATUS_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use OpenTelemetry::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use OpenTelemetry::Trace;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use OpenTelemetry;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Syntax::Keyword::Dynamically;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use parent 'OpenTelemetry::Instrumentation';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶sub dependencies {'Mango'}
Subroutine dependencies: called CC=1 SCAR=0.0
Pod documented
25  
26 3 my (%ORIGINAL, $loaded);
27  
28 # Commands whose first key names the targeted collection
29 3 my %COMMAND_WITH_COLLECTION = map {$_ => 1} qw(
30 aggregate collstats count create createIndexes delete distinct drop
31 dropIndexes find findAndModify insert listIndexes mapReduce mapreduce
32 rename update
33 );
34  
35 # Methods on Test::Mock::Mango::Collection that represent one operation each
36 3 my @COLLECTION_METHODS = qw(
37 aggregate create drop find_and_modify find_one insert remove update
38 );
39  
40 3 my $JSON = JSON::PP->new->canonical->allow_blessed;
41  
42 2 ▶sub uninstall($class) {
Subroutine uninstall: called CC=3 SCAR=11.0
Pod undocumented
43 2 ▶ return unless $loaded;
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 1 1 2
44 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 for my $key (keys %ORIGINAL) {
47 16 my ($package, $method) = $key =~ /^(.+)::(\w+)$/;
48 16 delete $Class::Method::Modifiers::MODIFIER_CACHE{$package}{$method};
49 16 *{"$package\::$method"} = delete $ORIGINAL{$key};
50 }
51 1 undef $loaded;
52 1 return;
53 }
54  
55 3 ▶sub install($class, %options) {
Subroutine install: called CC=5 SCAR=16.2
Pod documented
56 3 ▶ return if $loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $loaded 1 2 3
57 2 ▶ return unless Class::Inspector->loaded('Mango');
Branch: 1 branch
BranchTrueFalseTotal
unless "Class::Inspector"->loaded("Mango") 0 2 2
58 2 for my $target ($class->_targets) {
59 32 my ($package, $method, $extract) = @$target;
60 32 ▶ my $original = $package->can($method) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $original = $package->can($method) or next 32 0 32
61 32 $ORIGINAL{"$package\::$method"} = $original;
62 32 install_modifier $package, around => $method, _wrapper($extract);
63 }
64 2 return $loaded = 1;
65 }
66  
67 30 ▶sub _plain($data, $depth = 0) {
Subroutine _plain: called CC=6 SCAR=18.0
68 30 ▶ return '...' if $depth > 9;
Branch: 1 branch
BranchTrueFalseTotal
if $depth > 9 0 30 30
69 30 ▶ return "$data" if blessed $data;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($data) 0 30 30
70 30 ▶ return [ map {_plain($_, $depth + 1)} @$data ] if ref $data eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "ARRAY" 1 29 30
71 29 ▶ return { map {$_ => _plain($data->{$_}, $depth + 1)} keys %$data }
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "HASH" 13 16 29
72 if ref $data eq 'HASH';
73 16 return $data;
74 }
75  
76 12 ▶sub _statement($doc) {
Subroutine _statement: called CC=4 SCAR=13.9
77 12 ▶ return undef unless ref $doc eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $doc eq "HASH" 1 11 12
78 11 ▶ my $json = eval {$JSON->encode(_plain($doc))} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $json = eval { do { $JSON->encode(_plain($doc)) } } or return undef 11 0 11
79 11 ▶ return length $json > 512 ? substr($json, 0, 509) . '...' : $json;
Branch: 1 branch
BranchTrueFalseTotal
length $json > 512 ? : 1 10 11
80 }
81  
82 # Read an attribute from either a real Mojo::Base object or a
83 # Test::Mock::Mango hashref. Attributes are stored in hash slots in both
84 # cases, so we never call user-facing methods (some, like
85 # Mango::Database::collection, build objects as a side effect).
86 254 ▶sub _attr($invokant, $name) {
Subroutine _attr: called CC=3 SCAR=11.1
87 254 ▶ return undef unless defined $invokant && ref $invokant;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $invokant and ref $invokant 53 201 254
Condition66%2/3
defined $invokant and ref $invokant
!ll&&!rl&&r
530201
MC/DC50%1/2
defined $invokant and ref $invokant
defined $invokant ref $invokant
Truth table66%2/3
A and B
A= defined $invokantB= ref $invokant
ABresult
0X0
100
111
88 201 return $invokant->{$name};
89 }
90  
91 27 ▶sub _db_name($invokant) {
Subroutine _db_name: called CC=3 SCAR=11.0
92 27 ▶ my $db = _attr($invokant, 'db')
Condition83%5/6
(_attr($invokant, "db") // _attr(_attr($invokant, "collection"), "db")) // $invokant
l!l&&r!l&&!r
12150
_attr($invokant, "db") // _attr(_attr($invokant, "collection"), "db")
l!l&&r!l&&!r
11115
MC/DC0%0/3
(_attr($invokant, "db") // _attr(_attr($invokant, "collection"), "db")) // $invokant
_attr($invokant, "db") _attr(_attr($invokant, "collection"), "db") $invokant
Truth table75%3/4
A // B // C
A= _attr($invokant, "db")B= _attr(_attr($invokant, "collection"), "db")C= $invokant
ABCresult
1XX1
01X1
0011
0000
93 // _attr(_attr($invokant, 'collection'), 'db')
94 // $invokant;
95 27 return _attr($db, 'name');
96 }
97  
98 16 ▶sub _collection_name($invokant) {
Subroutine _collection_name: called CC=3 SCAR=11.0
99 16 my $collection = _attr($invokant, 'collection');
100 16 ▶ return _attr($collection, 'name') if defined $collection;
Branch: 1 branch
BranchTrueFalseTotal
if defined $collection 1 15 16
101 15 ▶ return _attr($invokant, 'name') if defined _attr($invokant, 'db');
Branch: 1 branch
BranchTrueFalseTotal
if defined _attr($invokant, "db") 11 4 15
102 4 return undef;
103 }
104  
105 27 ▶sub _mango_of($invokant) {
Subroutine _mango_of: called CC=3 SCAR=11.1
106 27 ▶ return _attr($invokant, 'mango')
Condition83%5/6
(_attr($invokant, "mango") // _attr(_attr($invokant, "db"), "mango")) // _attr(_attr(_attr($invokant, "collection"), "db"), "mango")
l!l&&r!l&&!r
10116
_attr($invokant, "mango") // _attr(_attr($invokant, "db"), "mango")
l!l&&r!l&&!r
10017
MC/DC66%2/3
(_attr($invokant, "mango") // _attr(_attr($invokant, "db"), "mango")) // _attr(_attr(_attr($invokant, "collection"), "db"), "mango")
_attr($invokant, "mango") _attr(_attr($invokant, "db"), "mango") _attr(_attr(_attr($invokant, "collection"), "db"), "mango")
Truth table75%3/4
A // B // C
A= _attr($invokant, "mango")B= _attr(_attr($invokant, "db"), "mango")C= _attr(_attr(_attr($invokant, "collection"), "db"), "mango")
ABCresult
1XX1
01X1
0011
0000
107 // _attr(_attr($invokant, 'db'), 'mango')
108 // _attr(_attr(_attr($invokant, 'collection'), 'db'), 'mango');
109 }
110  
111 13 ▶sub _host_port($mango) {
Subroutine _host_port: called CC=5 SCAR=17.5
112 13 ▶ my $hosts = _attr($mango, 'hosts') or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $hosts = _attr($mango, "hosts") or return () 13 0 13
113 13 ▶ my $first = $hosts->[0] or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $first = $hosts->[0] or return () 13 0 13
114 13 ▶ return () unless ref $first eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $first eq "ARRAY" 0 13 13
115 13 my ($host, $port) = @$first;
116 13 ▶ return ($host, $port // 27017);
Condition50%1/2
$port // 27017
l!l
130
MC/DC0%0/1
$port // 27017
$port
Truth table50%1/2
A
A= $port
Aresult
11
00
117 }
118  
119 29 ▶sub _cb_idx(@args) {
Subroutine _cb_idx: called CC=3 SCAR=11.0
120 29 ▶ return undef unless @args && ref $args[-1] eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless @args and ref $args[-1] eq "CODE" 23 6 29
Condition100%3/3
@args and ref $args[-1] eq "CODE"
!ll&&!rl&&r
6176
MC/DC100%2/2
@args and ref $args[-1] eq "CODE"
@args ref $args[-1] eq "CODE"
Truth table100%3/3
A and B
A= @argsB= ref $args[-1] eq "CODE"
ABresult
0X0
100
111
121 6 return $#args;
122 }
123  
124 4 ▶sub _describe($text) {
Subroutine _describe: called CC=4 SCAR=16.1
125 4 my ($description) = split /\n/, $text =~ s/^\s+|\s+$//gr, 2;
126 4 ▶ $description =~ s/ at \S+ line \d+\.$//a if defined $description;
Branch: 1 branch
BranchTrueFalseTotal
if defined $description 4 0 4
127 4 ▶ return defined $description && length $description ? $description : 'error';
Branch: 1 branch
BranchTrueFalseTotal
defined $description && length $description ? : 4 0 4
Condition33%1/3
defined $description and length $description
!ll&&!rl&&r
004
MC/DC0%0/2
defined $description and length $description
defined $description length $description
Truth table33%1/3
A and B
A= defined $descriptionB= length $description
ABresult
0X0
100
111
128 }
129  
130 # Attributes shared by every operation: db/collection names when known,
131 # plus server info when the Mango object is reachable
132 27 ▶sub _common_attrs($invokant, $db_name, $collection) {
Subroutine _common_attrs: called CC=6 SCAR=18.0
133 27 my %attrs;
134 27 ▶ $attrs{'db.namespace'} = $db_name if defined $db_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $db_name 23 4 27
135 27 ▶ $attrs{'db.collection.name'} = $collection if defined $collection;
Branch: 1 branch
BranchTrueFalseTotal
if defined $collection 14 13 27
136  
137 27 ▶ if (my $mango = _mango_of($invokant)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mango = _mango_of($invokant)) 11 16 27
138 11 my ($host, $port) = _host_port($mango);
139 11 ▶ $attrs{'server.address'} = $host if defined $host;
Branch: 1 branch
BranchTrueFalseTotal
if defined $host 11 0 11
140 11 ▶ $attrs{'server.port'} = $port if defined $port;
Branch: 1 branch
BranchTrueFalseTotal
if defined $port 11 0 11
141 }
142  
143 27 return %attrs;
144 }
145  
146 27 ▶sub _span_name($operation, $db_name, $collection) {
Subroutine _span_name: called CC=2 SCAR=6.9
147 27 my $target = join '.', grep {defined} $db_name, $collection;
148 27 ▶ my $name = $target ? "$operation $target" : $operation;
Branch: 1 branch
BranchTrueFalseTotal
$target ? : 23 4 27
149 27 return substr($name, 0, 100);
150 }
151  
152 11 ▶sub _command_extract($invokant, @args) {
Subroutine _command_extract: called CC=10 SCAR=23.3
153 11 my $command = $args[0];
154 11 my ($operation, $collection);
155  
156 11 ▶ if (!ref $command) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $command) { } 1 10 11
elsif (ref $command eq 'HASH') { } 10 0 10
157 1 $operation = $command;
158 } elsif (ref $command eq 'HASH') {
159 10 for my $key (keys %$command) {
160 12 ▶ next unless $COMMAND_WITH_COLLECTION{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $COMMAND_WITH_COLLECTION{$key} 10 2 12
161 2 ($operation, $collection) = ($key, $command->{$key});
162 2 last;
163 }
164 # Real Mango command docs are bson_doc (insertion-ordered), so the
165 # first key is the command name
166 10 ▶ ($operation) = keys %$command unless defined $operation;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $operation 8 2 10
167 10 ▶ undef $collection
Branch: 1 branch
BranchTrueFalseTotal
if not defined $collection or ref $collection or $collection =~ /\./ 0 2 2
Condition66%4/6
not defined $collection or ref $collection or $collection =~ /\./
l!l&&r!l&&!r
802
not defined $collection or ref $collection
l!l&&r!l&&!r
802
MC/DC33%1/3
not defined $collection or ref $collection or $collection =~ /\./
not defined $collection ref $collection $collection =~ /\./
Truth table50%2/4
not(A) or B or C
A= not defined $collectionB= ref $collectionC= $collection =~ /\./
ABCresult
1XX1
01X1
0011
0000
168 if !defined $collection || ref $collection || $collection =~ /\./;
169 } else {
170 0 $operation = 'command';
171 }
172  
173 11 my $db_name = _db_name($invokant);
174  
175 11 my %attrs = (
176 'db.system.name' => 'mongodb',
177 'db.operation.name' => $operation,
178 _common_attrs($invokant, $db_name, $collection),
179 );
180  
181 11 my $statement = _statement($command);
182 11 ▶ $attrs{'db.statement'} = $statement if defined $statement;
Branch: 1 branch
BranchTrueFalseTotal
if defined $statement 10 1 11
183  
184 11 return (_span_name($operation, $db_name, $collection), \%attrs, _cb_idx(@args));
185 }
186  
187 1 ▶sub _build_query($invokant) {
Subroutine _build_query: called CC=3 SCAR=15.4
188 1 ▶ return $invokant->build_query if blessed $invokant && $invokant->can('build_query');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($invokant) and $invokant->can("build_query") 1 0 1
Condition33%1/3
builtin::blessed($invokant) and $invokant->can("build_query")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($invokant) and $invokant->can("build_query")
builtin::blessed($invokant) $invokant->can("build_query")
Truth table33%1/3
A and B
A= builtin::blessed($invokant)B= $invokant->can("build_query")
ABresult
0X0
100
111
189 0 return $invokant->{query};
190 }
191  
192 1 ▶sub _find_extract($invokant, @args) {
Subroutine _find_extract: called CC=2 SCAR=7.0
193 1 my $db_name = _db_name($invokant);
194 1 my $collection = _collection_name($invokant);
195  
196 1 my %attrs = (
197 'db.system.name' => 'mongodb',
198 'db.operation.name' => 'find',
199 _common_attrs($invokant, $db_name, $collection),
200 );
201  
202 1 my $statement = _statement(_build_query($invokant));
203 1 ▶ $attrs{'db.statement'} = $statement if defined $statement;
Branch: 1 branch
BranchTrueFalseTotal
if defined $statement 1 0 1
204  
205 1 return (_span_name('find', $db_name, $collection), \%attrs, _cb_idx(@args));
206 }
207  
208 4 ▶sub _wire_extract($operation, $with_ns = 1) {
Subroutine _wire_extract: called CC=2 SCAR=7.2
209 2 ▶ sub($invokant, @args) {
Subroutine __ANON__: called CC=13 SCAR=27.4
210 2 my ($db_name, $collection, $label) = (undef, undef, '');
211  
212 2 ▶ if ($with_ns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($with_ns) { } 1 1 2
213 1 ▶ $label = $args[0] // '';
Condition50%1/2
$args[0] // ""
l!l
10
MC/DC0%0/1
$args[0] // ""
$args[0]
Truth table50%1/2
A
A= $args[0]
Aresult
11
00
214 1 ($db_name, $collection) = split /\./, $label, 2;
215 1 ▶ $db_name = undef if defined $db_name && !length $db_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $db_name and not length $db_name 0 1 1
Condition33%1/3
defined $db_name and not length $db_name
!ll&&!rl&&r
010
MC/DC0%0/2
defined $db_name and not length $db_name
defined $db_name not length $db_name
Truth table33%1/3
A and not(B)
A= defined $db_nameB= not length $db_name
ABresult
0X0
100
111
216 } else {
217 # Mango::kill_cursors receives a cursor id, not a namespace:
218 # keep the id in the span name, but not in the db attributes
219 1 ▶ $label = $args[0] // '';
Condition50%1/2
$args[0] // ""
l!l
10
MC/DC0%0/1
$args[0] // ""
$args[0]
Truth table50%1/2
A
A= $args[0]
Aresult
11
00
220 }
221  
222 2 my %attrs = (
223 'db.system.name' => 'mongodb',
224 'db.operation.name' => $operation,
225 );
226 2 ▶ $attrs{'db.namespace'} = $db_name if defined $db_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $db_name 1 1 2
227 2 ▶ $attrs{'db.collection.name'} = $collection
Branch: 1 branch
BranchTrueFalseTotal
if defined $collection and length $collection and not $collection =~ /^\$cmd/ 1 1 2
Condition66%4/6
defined $collection and length $collection and not $collection =~ /^\$cmd/
!ll&&!rl&&r
101
defined $collection and length $collection
!ll&&!rl&&r
101
MC/DC33%1/3
defined $collection and length $collection and not $collection =~ /^\$cmd/
defined $collection length $collection not $collection =~ /^\$cmd/
Truth table50%2/4
A and B and not(C)
A= defined $collectionB= length $collectionC= not $collection =~ /^\$cmd/
ABCresult
0XX0
10X0
1100
1111
228 if defined $collection && length $collection && $collection !~ /^\$cmd/;
229  
230 2 my ($host, $port) = _host_port($invokant);
231 2 ▶ $attrs{'server.address'} = $host if defined $host;
Branch: 1 branch
BranchTrueFalseTotal
if defined $host 2 0 2
232 2 ▶ $attrs{'server.port'} = $port if defined $port;
Branch: 1 branch
BranchTrueFalseTotal
if defined $port 2 0 2
233  
234 2 ▶ my $name = length $label ? "$operation $label" : $operation;
Branch: 1 branch
BranchTrueFalseTotal
length $label ? : 2 0 2
235 2 return (substr($name, 0, 100), \%attrs, _cb_idx(@args));
236 4 };
237 }
238  
239 22 ▶sub _named_extract($operation) {
Subroutine _named_extract: called CC=1 SCAR=0.0
240 15 ▶ sub($invokant, @args) {
Subroutine __ANON__: called CC=1 SCAR=0.0
241 15 my $db_name = _db_name($invokant);
242 15 my $collection = _collection_name($invokant);
243  
244 15 my %attrs = (
245 'db.system.name' => 'mongodb',
246 'db.operation.name' => $operation,
247 _common_attrs($invokant, $db_name, $collection),
248 );
249  
250 15 return (_span_name($operation, $db_name, $collection), \%attrs, _cb_idx(@args));
251 22 };
252 }
253  
254 32 ▶sub _wrapper($extract) {
Subroutine _wrapper: called CC=1 SCAR=0.0
255 29 ▶ sub($orig, $invokant, @args) {
Subroutine __ANON__: called CC=4 SCAR=13.9
256 29 my ($name, $attributes, $cb_idx) = $extract->($invokant, @args);
257  
258 29 my $span = OpenTelemetry->tracer_provider->tracer->create_span(
259 name => $name,
260 kind => SPAN_KIND_CLIENT,
261 attributes => $attributes,
262 );
263  
264 29 my $done;
265 31 ▶ my $finish = sub($description = undef) {
Subroutine __ANON__: called CC=5 SCAR=16.1
266 31 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 2 29 31
267 29 $done = 1;
268  
269 29 ▶ if (defined $description && length $description) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $description and length $description) { } 3 26 29
Condition66%2/3
defined $description and length $description
!ll&&!rl&&r
2603
MC/DC50%1/2
defined $description and length $description
defined $description length $description
Truth table66%2/3
A and B
A= defined $descriptionB= length $description
ABresult
0X0
100
111
270 3 $span->set_status(SPAN_STATUS_ERROR, $description);
271 } else {
272 26 $span->set_status(SPAN_STATUS_OK);
273 }
274  
275 29 $span->end;
276 29 return;
277 29 };
278  
279 29 my $out;
280 29 try {
281 29 ▶ if (defined $cb_idx) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cb_idx) { } 6 23 29
282 6 my $cb = $args[$cb_idx];
283 6 my $ctx = OpenTelemetry::Trace->context_with_span($span);
284 6 my @copied = @args;
285 6 ▶ $copied[$cb_idx] = sub(@reply) {
Subroutine __ANON__: called CC=2 SCAR=6.9
286 6 try {
287 6 dynamically OpenTelemetry::Context->current = $ctx;
288 6 ▶ $finish->(
Branch: 1 branch
BranchTrueFalseTotal
defined $reply[1] ? : 2 4 6
289 defined $reply[1] ? _describe("$reply[1]") : undef
290 );
291 6 $cb->(@reply);
292 } catch ($error) {
293 1 die $error;
294 }
295 6 };
296 6 $out = [ $invokant->$orig(@copied) ];
297 } else {
298 23 dynamically OpenTelemetry::Context->current
299 = OpenTelemetry::Trace->context_with_span($span);
300  
301 23 $out = [ $invokant->$orig(@args) ];
302 }
303 } catch ( $error ) {
304 2 ▶ $span->record_exception($error) unless $done;
Branch: 1 branch
BranchTrueFalseTotal
unless $done 1 1 2
305 2 $finish->(_describe("$error"));
306 2 die $error;
307 } finally {
308 # Blocking calls finish here; non-blocking calls finish in the callback
309 29 ▶ $finish->() unless defined $cb_idx;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cb_idx 23 6 29
310 }
311  
312 # Every wrapped Mango method returns a single value; the arrayref
313 # merely carries it out of the try block
314 27 return $out->[0];
315 32 };
316 }
317  
318 2 ▶sub _targets($class) {
Subroutine _targets: called CC=2 SCAR=7.1
319 return (
320 [ 'Mango::Database', 'command', \&_command_extract ],
321 [ 'Mango::Cursor::Query', '_start', \&_find_extract ],
322 [ 'Mango', 'get_more', _wire_extract('get_more') ],
323 [ 'Mango', 'kill_cursors', _wire_extract('kill_cursors', 0) ],
324 Class::Inspector->loaded('Test::Mock::Mango') ? (
325 [ 'Test::Mock::Mango::DB', 'command', \&_command_extract ],
326 16 (map {[ 'Test::Mock::Mango::Collection', $_, _named_extract($_) ]}
327 @COLLECTION_METHODS),
328 2 ▶ (map {[ 'Test::Mock::Mango::Cursor', $_, _named_extract('find') ]}
Branch: 1 branch
BranchTrueFalseTotal
'Class::Inspector'->loaded('Test::Mock::Mango') ? : 2 0 2
329 qw(all next)),
330 [ 'Test::Mock::Mango::Cursor', 'count', _named_extract('count') ],
331 ) : (),
332 );
333 }
334  
335 3 1;
↑ Summary Mango/TestSuiteInjection.pm »