| 1 | package OpenTracing::Implementation::DataDog::ScopeManager; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | OpenTracing::Implementation::DataDog::ScopeManager - Keep track of active scopes | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | duno | ||||||||||
| 10 | |||||||||||
| 11 | =cut | ||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | # with 'OpenTracing::Role::ScopeManager'; | ||||||||||
| 16 | # | ||||||||||
| 17 | # moved to the bottom, so Moo can install methods that are required | ||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use OpenTracing::Implementation::DataDog::Scope; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 1 | ▶ | use Types::Interface qw/ObjectDoesInterface/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | ▶ | use Types::Standard qw/Maybe/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | has _active_scope => ( | ||||||||||
| 28 | is => 'rwp', | ||||||||||
| 29 | isa => Maybe[ObjectDoesInterface['OpenTracing::Role::Scope']], | ||||||||||
| 30 | reader => 'get_active_scope', | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | sub activate_span { | ||||||||||
| 36 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
activate_span: not called CC=3 SCAR=24.8
| |||||||||||
| 37 | 0 | ▶ | my $span = shift or croak "Missing OpenTracing Span"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | 0 | my $options = { @_ }; | |||||||||
| 40 | |||||||||||
| 41 | # remove the `finish_span_on_close` option, which is for this method only! | ||||||||||
| 42 | my $finish_span_on_close = | ||||||||||
| 43 | exists( $options->{ finish_span_on_close } ) ? | ||||||||||
| 44 | !! delete $options->{ finish_span_on_close } | ||||||||||
| 45 | : !undef | ||||||||||
| 46 | 0 | ▶ | ; # use 'truthness' of param if provided, or set to 'true' otherwise | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | my $scope = $self->_build_scope( $span, | |||||||||
| 49 | finish_span_on_close => $finish_span_on_close | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 0 | $self->_set__active_scope( $scope ); | |||||||||
| 53 | |||||||||||
| 54 | 0 | return $scope | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | sub _build_scope { | ||||||||||
| 60 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_scope: not called CC=2 SCAR=17.9
| |||||||||||
| 61 | 0 | my $span = shift; | |||||||||
| 62 | 0 | my $options = { @_ }; | |||||||||
| 63 | |||||||||||
| 64 | # remove the `finish_span_on_close` option, which is for this method only! | ||||||||||
| 65 | my $finish_span_on_close = | ||||||||||
| 66 | exists( $options->{ finish_span_on_close } ) ? | ||||||||||
| 67 | !! delete $options->{ finish_span_on_close } | ||||||||||
| 68 | : !undef | ||||||||||
| 69 | 0 | ▶ | ; # use 'truthness' of param if provided, or set to 'true' otherwise | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 0 | my $current_scope = $self->get_active_scope; | |||||||||
| 72 | |||||||||||
| 73 | my $scope = OpenTracing::Implementation::DataDog::Scope->new( | ||||||||||
| 74 | span => $span, | ||||||||||
| 75 | finish_span_on_close => $finish_span_on_close, | ||||||||||
| 76 | after_close => sub { | ||||||||||
| 77 | 0 | ▶ | $self->_set__active_scope( $current_scope ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 78 | } | ||||||||||
| 79 | 0 | ); | |||||||||
| 80 | |||||||||||
| 81 | 0 | return $scope | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | with 'OpenTracing::Role::ScopeManager'; | ||||||||||
| 86 | |||||||||||
| 87 | 1; | ||||||||||