Role/ScopeManager.pm

filter: Statementstmt 100% 30 / 30 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 97.7% 44 / 45 CC 4 SCAR 5.5
CC
4
Cov
97%
activate_span
3.0
BEGIN
2.0
BEGIN
1.0
CRAP 1.7
« Role/Span.pm ↑ Summary Role/SpanContext.pm »
1 package OpenTracing::Role::ScopeManager;
2  
3 =head1 NAME
4  
5 OpenTracing::Role::ScopeManager - Role for OpenTracing implementations.
6  
7 =head1 SYNOPSIS
8  
9 package OpenTracing::Implementation::MyBackendService::ScopeManager;
10
11 use Moo;
12
13 with 'OpenTracing::Role::ScopeManager'
14
15 1;
16  
17 =cut
18  
19  
20  
21 10 our $VERSION = '0.08_003';
22  
23  
24  
25 10 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 10 ▶use Types::Standard qw/Bool CodeRef Dict Maybe/;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 10 ▶use OpenTracing::Types qw/Scope Span assert_Scope/;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 10 ▶use Role::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33  
34  
35 =head1 DESCRIPTION
36  
37 This is a role for OpenTracing implenetations that are compliant with the
38 L<OpenTracing::Interface>.
39  
40 =cut
41  
42 # The chosen design is to have only 1 active scope and use callback to change
43 # what the 'previous' scope would be when we close a scope.
44 #
45 # An other design could be building a stack, using 'push/pop' to keep track of
46 # which one to activate on close.
47 #
48 10 has _active_scope => (
49 is => 'rwp',
50 isa => Scope,
51 init_arg => undef,
52 reader => 'get_active_scope',
53 writer => 'set_active_scope',
54 );
55  
56  
57  
58 =head1 REQUIRED METHODS
59  
60  
61  
62 =head2 C<build_scope>
63  
64 This method should return a C<Scope>
65  
66 =head3 Expected Named Parameters
67  
68 =over
69  
70 =item C<span>
71  
72 A OpenTracing compliant C<Span> object.
73  
74 =item C<finish_span_on_close>
75  
76 A C<Bool> type.
77  
78 =back
79  
80 =head3 Note
81  
82 Unlike the OpenTracing API interface specification, C<build_scope> does not let
83 it up for discusion, C<span> and C<finish_span_on_close> are expected named
84 parameters.
85  
86 =cut
87  
88  
89 instance_method build_scope (
90
91 Span :$span,
92 Bool :$finish_span_on_close
93
94 10 ▶) :Return ( Scope ) { };
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96  
97  
98 =head1 INSTANCE METHODS
99  
100 =cut
101  
102  
103  
104 =head2 activate_span
105  
106 Sets the given C<$span> as being the active span in a newly created C<Scope>.
107  
108 =head3 Required Positional Parameter
109  
110 =over
111  
112 =item C<$span>
113  
114 A OpenTracing compliant C<Span> object.
115  
116 =back
117  
118 =head3 Optional Named Parameter
119  
120 =over
121  
122 =item C<finish_span_on_close>
123  
124 A C<Bool> type, that decides wether or not C<finish> gets called on the C<$span>
125 object. Defaults to 'true'.
126  
127 =back
128  
129 =head3 Note
130  
131 This is part of a proposed API change.
132  
133 =cut
134  
135 sub activate_span {
136 3 ▶ my $self = shift;
Subroutine activate_span: called CC=3 SCAR=11.0
Pod documented
137 3 ▶ my $span = shift or croak "Missing OpenTracing Span";
Branch: 1 branch
BranchTrueFalseTotal
my $span = shift() or croak("Missing OpenTracing Span") 0 3 3
138
139 3 my $options = { @_ };
140
141 my $finish_span_on_close =
142 exists( $options->{ finish_span_on_close } ) ?
143 !! delete $options->{ finish_span_on_close }
144 : !undef
145 3 ▶ ; # use 'truthness' of param if provided, or set to 'true' otherwise
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{'finish_span_on_close'} ? : 1 2 3
146
147 3 my $scope = $self->build_scope(
148 span => $span,
149 finish_span_on_close => $finish_span_on_close,
150 %$options,
151 );
152
153 3 $self->set_active_scope( $scope );
154
155 3 return $scope
156 }
157  
158  
159  
160 BEGIN {
161 # use Role::Tiny::With;
162 with 'OpenTracing::Interface::ScopeManager'
163 10 ▶ if $ENV{OPENTRACING_INTERFACE};
Subroutine BEGIN: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OPENTRACING_INTERFACE"} 2 8 10
164 }
165  
166  
167  
168 10 1;
« Role/Span.pm ↑ Summary Role/SpanContext.pm »