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.0';
4              
5 10     10   880694 use Moo::Role;
  10         17561  
  10         69  
6 10     10   6542 use MooX::Should;
  10         25032  
  10         71  
7              
8 10     10   1049 use Carp;
  10         26  
  10         601  
9 10     10   2802 use OpenTracing::Types qw/Span/;
  10         331029  
  10         74  
10 10     10   8750 use Types::Standard qw/Bool CodeRef Maybe/;
  10         375678  
  10         104  
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 22316 my $self = shift;
38            
39 7 100 50     50 carp "Can't close an already closed scope" and return $self
40             if $self->closed;
41            
42 6         117 $self->_set_closed( !undef );
43            
44 6 50       197 $self->get_span->finish
45             if $self->finish_span_on_close;
46            
47 6 100       29 $self->on_close->( $self )
48             if $self->has_on_close;
49            
50             # return $self->get_scope_manager()->deactivate_scope( $self );
51            
52 6         59 return $self
53            
54             };
55              
56             sub DEMOLISH {
57 5     5 0 11630 my $self = shift;
58 5         13 my $in_global_destruction = shift;
59            
60 5 100       47 return if $self->closed;
61            
62 2         28 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   32139 use Role::Tiny::With;
  10         1732  
  10         570  
76 10     10   63 with 'OpenTracing::Interface::Scope'
77             }
78              
79              
80              
81             1;