File Coverage

blib/lib/OpenTracing/Role/ScopeManager.pm
Criterion Covered Total %
statement 37 37 100.0
branch 10 14 71.4
condition 1 3 33.3
subroutine 9 9 100.0
pod 1 1 100.0
total 58 64 90.6


line stmt bran cond sub pod time code
1             package OpenTracing::Role::ScopeManager;
2              
3             our $VERSION = 'v0.86.1';
4              
5 12     12   536386 use Moo::Role;
  12         18893  
  12         78  
6 12     12   6026 use MooX::Should;
  12         14802  
  12         109  
7              
8 16     12   1489 use Carp;
  14         57  
  12         776  
9 12     12   1492 use OpenTracing::Types qw/Scope Span assert_Scope/;
  12         317281  
  12         112  
10 12     12   12704 use Role::Declare::Should;
  12         3981  
  12         79  
11 12     12   231802 use Types::Standard qw/Bool CodeRef Dict Maybe/;
  12         41  
  12         99  
12              
13             # The chosen design is to have only 1 active scope and use callback to change
14             # what the 'previous' scope would be when we close a scope.
15             #
16             # An other design could be building a stack, using 'push/pop' to keep track of
17             # which one to activate on close.
18             #
19             has active_scope => (
20             is => 'rwp',
21             should => Scope,
22             init_arg => undef,
23             reader => 'get_active_scope',
24             writer => 'set_active_scope',
25             );
26              
27             sub activate_span {
28 3     3 1 12 my $self = shift;
29 3         14 my $span = shift or croak "Missing OpenTracing Span";
30            
31 3         388 my $options = { @_ };
32            
33             my $finish_span_on_close =
34             exists( $options->{ finish_span_on_close } ) ?
35             !! delete $options->{ finish_span_on_close }
36             : !undef
37 3         140 ; # use 'truthness' of param if provided, or set to 'true' otherwise
38            
39             my $scope = $self->build_scope(
40             span => $span,
41             finish_span_on_close => $finish_span_on_close,
42             %$options,
43             );
44            
45             $self->set_active_scope( $scope );
46            
47             return $scope
48             }
49              
50             instance_method build_scope (
51             Span :$span,
52             Bool :$finish_span_on_close
53 12 50 33 12   41372 ) :Return ( Scope ) { };
  12 50       65  
  12 100       69  
  4 100       9254  
  4 50       22  
  4 50       8  
  4 100       14  
  4         23  
  3         13  
  2         8  
  2         6  
  12         10177  
  3         23883  
  3         14  
54              
55              
56              
57             BEGIN {
58             # use Role::Tiny::With;
59 3     12   8 with 'OpenTracing::Interface::ScopeManager'
60             }
61              
62             1;