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/Scope.pm ↑ Summary Role/ContextReference.pm »
1 package OpenTracing::Role::ScopeManager;
2  
3 10 our $VERSION = 'v0.80.0-TRIAL_007';
4  
5 10 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use OpenTracing::Types qw/Scope Span assert_Scope/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Role::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Types::Standard qw/Bool CodeRef Dict Maybe/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # The chosen design is to have only 1 active scope and use callback to change
13 # what the 'previous' scope would be when we close a scope.
14 #
15 # An other design could be building a stack, using 'push/pop' to keep track of
16 # which one to activate on close.
17 #
18 10 has active_scope => (
19 is => 'rwp',
20 isa => Scope,
21 init_arg => undef,
22 reader => 'get_active_scope',
23 writer => 'set_active_scope',
24 );
25  
26 sub activate_span {
27 3 ▶ my $self = shift;
Subroutine activate_span: called CC=3 SCAR=11.0
Pod documented
28 3 ▶ my $span = shift or croak "Missing OpenTracing Span";
Branch: 1 branch
BranchTrueFalseTotal
my $span = shift() or croak("Missing OpenTracing Span") 0 3 3
29
30 3 my $options = { @_ };
31
32 my $finish_span_on_close =
33 exists( $options->{ finish_span_on_close } ) ?
34 !! delete $options->{ finish_span_on_close }
35 : !undef
36 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
37
38 3 my $scope = $self->build_scope(
39 span => $span,
40 finish_span_on_close => $finish_span_on_close,
41 %$options,
42 );
43
44 3 $self->set_active_scope( $scope );
45
46 3 return $scope
47 }
48  
49 instance_method build_scope (
50 Span :$span,
51 Bool :$finish_span_on_close
52 10 ▶) :Return ( Scope ) { };
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54  
55  
56 BEGIN {
57 # use Role::Tiny::With;
58 with 'OpenTracing::Interface::ScopeManager'
59 10 ▶ if $ENV{OPENTRACING_INTERFACE};
Subroutine BEGIN: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OPENTRACING_INTERFACE"} 2 8 10
60 }
61  
62 10 1;
« Role/Scope.pm ↑ Summary Role/ContextReference.pm »