File Coverage

blib/lib/OpenTracing/Role/Scope.pm
Criterion Covered Total %
statement 29 31 93.5
branch 7 10 70.0
condition 1 2 50.0
subroutine 9 9 100.0
pod 1 2 50.0
total 47 54 87.0


line stmt bran cond sub pod time code
1             package OpenTracing::Role::Scope;
2              
3             our $VERSION = 'v0.86.1';
4              
5 10     10   924715 use Moo::Role;
  10         18503  
  10         65  
6 10     10   6602 use MooX::Should;
  10         26223  
  10         73  
7              
8 10     10   1032 use Carp;
  10         30  
  10         709  
9 10     10   2897 use OpenTracing::Types qw/Span/;
  10         759775  
  10         93  
10 10     10   6743 use Types::Standard qw/Bool CodeRef Maybe/;
  10         43  
  10         94  
11              
12             has span => (
13             is => 'ro',
14             should => Span,
15             reader => 'get_span',
16             );
17              
18             has finish_span_on_close => (
19             is => 'ro',
20             should => Bool,
21             );
22              
23             has closed => (
24             is => 'rwp',
25             should => Bool,
26             init_arg => undef,
27             default => !!undef,
28             );
29              
30             has on_close => (
31             is => 'ro',
32             should => Maybe[CodeRef],
33             predicate => 1,
34             );
35              
36             sub close {
37 7     7 1 23661 my $self = shift;
38            
39 7 100 50     60 carp "Can't close an already closed scope" and return $self
40             if $self->closed;
41            
42 6         119 $self->_set_closed( !undef );
43            
44 6 50       213 $self->get_span->finish
45             if $self->finish_span_on_close;
46            
47 6 100       31 $self->on_close->( $self )
48             if $self->has_on_close;
49            
50             # return $self->get_scope_manager()->deactivate_scope( $self );
51            
52 6         57 return $self
53            
54             };
55              
56             sub DEMOLISH {
57 5     5 0 12440 my $self = shift;
58 5         11 my $in_global_destruction = shift;
59            
60 5 100       48 return if $self->closed;
61            
62 2         39 croak "Scope not programmatically closed before being demolished";
63             #
64             # below might be appreciated behaviour, but you should close yourself
65             #
66 0 0         $self->close( )
67             unless $in_global_destruction;
68            
69             return
70 0           }
71              
72              
73              
74             BEGIN {
75 10     10   32745 use Role::Tiny::With;
  10         1898  
  10         629  
76 10     10   70 with 'OpenTracing::Interface::Scope'
77             }
78              
79              
80              
81             1;