File Coverage

blib/lib/OpenTracing/Implementation.pm
Criterion Covered Total %
statement 17 40 42.5
branch 1 10 10.0
condition 0 2 0.0
subroutine 6 11 54.5
pod 3 3 100.0
total 27 66 40.9


line stmt bran cond sub pod time code
1             package OpenTracing::Implementation;
2              
3 2     2   213295 use strict;
  2         15  
  2         49  
4 2     2   9 use warnings;
  2         4  
  2         66  
5              
6             our $VERSION = 'v0.32.0';
7              
8 2     2   774 use OpenTracing::GlobalTracer;
  2         5332  
  2         10  
9              
10 2     2   172 use Carp;
  2         4  
  2         88  
11 2     2   10 use Module::Load;
  2         55  
  2         7  
12              
13             our @CARP_NOT;
14              
15             sub import {
16 2     2   16 my $package = shift;
17 2 50       1422 return unless @_;
18            
19 0           __PACKAGE__->bootstrap_global_tracer( @_ )
20             }
21              
22 0     0 1   sub bootstrap_tracer { shift->_build_tracer( @_ ) }
23              
24 0     0 1   sub bootstrap_default_tracer { shift->_build_tracer( undef, @_ ) }
25              
26             sub bootstrap_global_tracer {
27 0     0 1   my $package = shift;
28 0           my $tracer = $package->_build_tracer( @_ );
29            
30 0           OpenTracing::GlobalTracer->set_global_tracer( $tracer );
31            
32 0           return OpenTracing::GlobalTracer->get_global_tracer
33             }
34              
35             # _build_tracer
36             #
37             # passing undef as implementation name will cause to use the $ENV
38             #
39             sub _build_tracer {
40 0     0     my $package = shift;
41 0           my $implementation_name = shift;
42 0           my @implementation_args = @_;
43            
44 0           my $implementation_class =
45             __PACKAGE__->_get_implementation_class( $implementation_name );
46            
47             carp "Loading implementation $implementation_class"
48 0 0         if $ENV{OPENTRACING_DEBUG};
49            
50 0           load $implementation_class;
51            
52 0           eval { load $implementation_class };
  0            
53 0 0         croak "GlobalTracer can't load implementation [$implementation_class]"
54             if $@;
55            
56 0           my $tracer = $implementation_class->bootstrap_tracer( @implementation_args);
57            
58 0           return $tracer
59             }
60              
61             sub _get_implementation_class {
62 0     0     my $class = shift;
63 0           my $implementation_name = shift;
64            
65 0 0 0       $implementation_name = $ENV{OPENTRACING_IMPLEMENTATION} || 'NoOp'
66             unless defined $implementation_name;
67              
68 0 0         my $implementation_class = substr( $implementation_name, 0, 1) eq '+' ?
69             substr( $implementation_name, 1 )
70             :
71             'OpenTracing::Implementation::' . $implementation_name;
72            
73 0           return $implementation_class
74             }
75              
76             1;