OpenTracing/Integration.pm

filter: Statementstmt 68.7% 33 / 48 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 68.2% 43 / 63 CC 5 SCAR 23.7
CC
5
Cov
63%
import
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 10.7
« OpenTracing/Integration/System.pm ↑ Summary OpenTracing/Integration/HTTP/Tiny.pm »
1 package OpenTracing::Integration;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '1.006'; # VERSION
7 3 our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8  
9 3 ▶no indirect;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =encoding utf8
13  
14 =head1 NAME
15  
16 OpenTracing::Integration - top-level class for integrating OpenTracing
17 with other Perl modules
18  
19 =head1 SYNOPSIS
20  
21 # Apply tracing for specific modules
22 use OpenTracing::Integration qw(HTTP::Tiny DBI);
23  
24 # Trace every module we know about
25 use OpenTracing::Integration qw(:all);
26  
27 =head1 DESCRIPTION
28  
29 This is the base rĂ´le for handling tracing integration with other CPAN modules.
30  
31 It provides functionality for loading available integrations
32 via the import list on a C<use> statement:
33  
34 =over 4
35  
36 =item * with C<:all>, any module that supports OpenTracing will be pulled in, if the module-to-be-traced is already loaded
37  
38 =item * with a specific list of modules, these will be applied unconditionally, loading the modules-to-be-traced as required
39  
40 =back
41  
42 This means that you can expect L<HTTP::Tiny> to be traced
43 if you do this:
44  
45 use OpenTracing::Integration qw(HTTP::Tiny);
46  
47 or this:
48  
49 use HTTP::Tiny;
50 use OpenTracing::Integration qw(:all);
51  
52 but it will B<not> be traced if you do this:
53  
54 use OpenTracing::Integration qw(:all);
55 use HTTP::Tiny;
56  
57 The reason for this inconsistent behaviour is simple:
58 with a large install, C<:all> might pull in a lot of
59 unwanted modules. Instead, you'd do this at the end
60 of your module imports, and any functionality that
61 you're actively using in the code would gain tracing,
62 if available.
63  
64 =cut
65  
66 3 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 3 ▶use Module::Pluggable;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 3 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
69 3 ▶use List::Util qw(uniqstr);
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 3 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 3 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 0 ▶sub import {
Subroutine import: not called CC=5 SCAR=34.0
76 0 my ($class, @args) = @_;
77 0 ▶ return unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 0 0
78  
79 # If we have an explicit list, then we load
80 # dependencies - this is turned off by :all tag
81 0 my $load_deps = 1;
82  
83 0 my @modules;
84 0 for my $target (@args) {
85 # Try to load *all* available integrations
86 0 ▶ if($target eq ':all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq ':all') { } 0 0 0
87 0 push @modules, $class->plugins;
88 0 $load_deps = 0;
89 } else {
90 0 push @modules, __PACKAGE__ . '::' . $target;
91 }
92 }
93  
94 0 for my $module (uniqstr @modules) {
95 try {
96 0 $log->tracef('Loading [%s]', $module);
97 0 Module::Load::load($module);
98 0 $module->load($load_deps);
99 0 } catch {
100 # Just a warning, if we're loading everything then
101 # we shouldn't cause chaos just because something
102 # doesn't happen to be available.
103 0 $log->warnf('Unable to loading OpenTracing integration %s - %s', $module, $@);
104 }
105 }
106 }
107  
108 3 1;
109  
110 __END__
« OpenTracing/Integration/System.pm ↑ Summary OpenTracing/Integration/HTTP/Tiny.pm »