Role/Scope.pm

filter: Statementstmt 94.1% 32 / 34 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 87.5% 49 / 56 CC 7 SCAR 9.4
CC
7
Cov
89%
close
4.0
DEMOLISH
3.6
BEGIN
2.0
CRAP 2.6
« Role/Tracer.pm ↑ Summary Role/Span.pm »
1 package OpenTracing::Role::Scope;
2  
3 =head1 NAME
4  
5 OpenTracing::Role::Scope - Role for OpenTracing implementations.
6  
7 =head1 SYNOPSIS
8  
9 package OpenTracing::Implementation::MyBackendService::Scope;
10
11 use Moo;
12
13 with 'OpenTracing::Role::Scope'
14
15 sub close => { ... }
16
17 1;
18  
19 =cut
20  
21  
22  
23 10 our $VERSION = '0.08_003';
24  
25  
26  
27 10 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 10 ▶use OpenTracing::Types qw/Span/;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 10 ▶use Types::Standard qw/Bool CodeRef Maybe/;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34  
35  
36 =head1 DESCRIPTION
37  
38 This is a Role for OpenTracing implenetations that are compliant with the
39 L<OpenTracing::Interface>.
40  
41 =cut
42  
43  
44  
45 10 has span => (
46 is => 'ro',
47 isa => Span,
48 reader => 'get_span',
49 );
50  
51  
52  
53 10 has finish_span_on_close => (
54 is => 'ro',
55 isa => Bool,
56 );
57  
58  
59  
60 10 has closed => (
61 is => 'rwp',
62 isa => Bool,
63 init_arg => undef,
64 default => !!undef,
65 );
66  
67  
68  
69 10 has on_close => (
70 is => 'ro',
71 isa => Maybe[CodeRef],
72 predicate => 1,
73 );
74  
75  
76  
77 sub close {
78 7 ▶ my $self = shift;
Subroutine close: called CC=4 SCAR=13.9
Pod undocumented
79
80 7 ▶ croak "Can't close an already closed scope"
Branch: 1 branch
BranchTrueFalseTotal
if $self->closed 1 6 7
81 if $self->closed;
82
83 6 $self->_set_closed( !undef );
84
85 6 ▶ $self->get_span->finish
Branch: 1 branch
BranchTrueFalseTotal
if $self->finish_span_on_close 0 6 6
86 if $self->finish_span_on_close;
87
88 6 ▶ $self->on_close->( $self ) # we do like to have $self as invocant
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_on_close 1 5 6
89 if $self->has_on_close;
90
91 # return $self->get_scope_manager()->deactivate_scope( $self );
92
93 6 return $self
94
95 };
96  
97  
98  
99 sub DEMOLISH {
100 5 ▶ my $self = shift;
Subroutine DEMOLISH: called CC=3 SCAR=12.7
Pod undocumented
101 5 my $in_global_destruction = shift;
102
103 5 ▶ return if $self->closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->closed 3 2 5
104
105 2 croak "Scope not programmatically closed before being demolished";
106 #
107 # below might be appreciated behaviour, but you should close yourself
108 #
109 0 ▶ $self->close( )
Branch: 1 branch
BranchTrueFalseTotal
unless $in_global_destruction 0 0 0
110 unless $in_global_destruction;
111
112 return
113 0 }
114  
115  
116  
117 BEGIN {
118 10 ▶ use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 with 'OpenTracing::Interface::Scope'
120 10 ▶ if $ENV{OPENTRACING_INTERFACE};
Subroutine BEGIN: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OPENTRACING_INTERFACE"} 3 7 10
121 }
122  
123  
124  
125 10 1;
« Role/Tracer.pm ↑ Summary Role/Span.pm »