File Coverage

blib/lib/OpenTracing/Implementation.pm
Criterion Covered Total %
statement 40 41 97.5
branch 11 18 61.1
condition 2 3 66.6
subroutine 14 14 100.0
pod 4 6 66.6
total 71 82 86.5


line stmt bran cond sub pod time code
1             package OpenTracing::Implementation;
2              
3 3     3   366181 use strict;
  3         24  
  3         89  
4 3     3   16 use warnings;
  3         5  
  3         426  
5              
6             our $VERSION = 'v0.33.0';
7              
8             sub OT_IMPLEMENTATION_NAME {
9             exists $ENV{ PERL_OPENTRACING_IMPLEMENTATION } ?
10             $ENV{ PERL_OPENTRACING_IMPLEMENTATION } :
11             exists $ENV{ OPENTRACING_IMPLEMENTATION } ?
12             $ENV{ OPENTRACING_IMPLEMENTATION } :
13 3 100   3 0 17 'NoOp'
    50          
14             }
15              
16             sub OT_DEBUG {
17             exists $ENV{ PERL_OPENTRACING_DEBUG } ?
18             $ENV{ PERL_OPENTRACING_DEBUG } :
19             exists $ENV{ OPENTRACING_DEBUG } ?
20             $ENV{ OPENTRACING_DEBUG } :
21             exists $ENV{ DEBUG } ?
22             $ENV{ DEBUG } :
23             undef
24 5 50   5 0 25 }
    50          
    50          
25             #
26             # it was meant to be a constant, but during test, these seem to be dynamic
27              
28              
29              
30 3     3   1306 use OpenTracing::GlobalTracer;
  3         32940  
  3         16  
31              
32 3     3   221 use Carp;
  3         6  
  3         156  
33 3     3   30 use Module::Load;
  3         7  
  3         17  
34              
35             our @CARP_NOT;
36              
37             sub import {
38 3     3   28 my $package = shift;
39 3 50       1638 return unless @_;
40            
41 0         0 __PACKAGE__->bootstrap_global_tracer( @_ )
42             }
43              
44 1     1 1 1804 sub bootstrap_tracer { shift->_build_tracer( @_ ) }
45              
46 2     2 1 17394 sub bootstrap_default_tracer { shift->_build_tracer( undef, @_ ) }
47              
48             sub bootstrap_global_tracer {
49 1     1 1 4677 OpenTracing::GlobalTracer->set_global_tracer( shift->_build_tracer( @_ ) );
50 1         14 return OpenTracing::GlobalTracer->get_global_tracer
51             }
52              
53             sub bootstrap_global_default_tracer {
54 1     1 1 4656 OpenTracing::GlobalTracer->set_global_tracer( shift->_build_tracer( undef, @_ ) );
55 1         13 return OpenTracing::GlobalTracer->get_global_tracer
56             }
57              
58             # _build_tracer
59             #
60             # passing undef as implementation name will cause to use the $ENV
61             #
62             sub _build_tracer {
63 5     5   10 my $package = shift;
64 5         12 my $implementation_name = shift;
65 5         26 my @implementation_args = @_;
66            
67 5         14 my $implementation_class =
68             __PACKAGE__->_get_implementation_class( $implementation_name );
69            
70 5 50       12 carp "Loading implementation $implementation_class"
71             if OT_DEBUG;
72            
73 5         19 load $implementation_class;
74            
75 5         505 eval { load $implementation_class };
  5         13  
76 5 50       394 croak "GlobalTracer can't load implementation [$implementation_class]"
77             if $@;
78            
79 5         152 my $tracer = $implementation_class->bootstrap_tracer( @implementation_args);
80            
81 5         485 return $tracer
82             }
83              
84             sub _get_implementation_class {
85 5     5   10 my $class = shift;
86 5   66     22 my $implementation_name = shift // OT_IMPLEMENTATION_NAME;
87            
88 5 100       24 my $implementation_class = substr( $implementation_name, 0, 1) eq '+' ?
89             substr( $implementation_name, 1 )
90             :
91             'OpenTracing::Implementation::' . $implementation_name;
92            
93 5         10 return $implementation_class
94             }
95              
96             1;