blib/lib/Sentry/Util.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 64 CC 6 SCAR 22.3
CC
6
Cov
0%
around
20.0
truncate
12.0
uuid4
2.0
CRAP 9.3
1 package Sentry::Util;
2 use Mojo::Base -strict, -signatures;
3  
4 use Exporter qw(import);
5 use Mojo::Loader qw(load_class);
6 use Mojo::Util qw(dumper monkey_patch);
7 use UUID::Tiny ':std';
8  
9 our @EXPORT_OK = qw(uuid4 truncate merge around);
10  
11 sub uuid4 {
12 my $uuid = create_uuid_as_string(UUID_V4);
13 $uuid =~ s/-//g;
14 return $uuid;
15 }
16  
17 sub truncate ($string, $max = 0) {
18 return $string if (ref($string) || $max == 0);
19  
20 return length($string) <= $max ? $string : substr($string, 0, $max) . '...';
21 }
22  
23 sub merge ($target, $source, $key) {
24 $target->{$key}
25 = { ($target->{$key} // {})->%*, ($source->{$key} // {})->%* };
26 }
27  
28 my %Patched = ();
29  
30 sub around ($package, $method, $cb) {
31 my $key = $package . '::' . $method;
32 return if $Patched{$key};
33  
34 if (my $e = load_class $package) {
35 die ref $e ? "Exception: $e" : "Module $package not found";
36 }
37  
38 my $orig = $package->can($method);
39  
40 monkey_patch $package, $method => sub { $cb->($orig, @_) };
41  
42 $Patched{$key} = 1;
43  
44 return;
45 }
46  
47 1;