| 1 | package OpenTracing::Role::SpanContext; | ||
| 2 | |||
| 3 | 19 | our $VERSION = 'v0.86.1'; | |
| 4 | |||
| 5 | 19 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 19 | ▶ | use MooX::HandlesVia; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 19 | ▶ | use MooX::Should; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 19 | ▶ | use Data::GUID; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 19 | ▶ | use Sub::Trigger::Lock; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 19 | ▶ | use Types::Standard qw/HashRef Str/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | has trace_id => ( | ||
| 14 | is => 'rw', | ||
| 15 | # should => Uuid, # not restraints here, do so when consuming this | ||
| 16 | init_arg => undef, | ||
| 17 | 13 | ▶ | default => sub { Data::GUID->new }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 18 | 19 | trigger => Lock, | |
| 19 | ); | ||
| 20 | |||
| 21 | has span_id => ( | ||
| 22 | is => 'rw', | ||
| 23 | # should => Uuid, # not restraints here, do so when consuming this | ||
| 24 | init_arg => undef, | ||
| 25 | 13 | ▶ | default => sub { Data::GUID->new }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 26 | 19 | trigger => Lock, | |
| 27 | ); | ||
| 28 | |||
| 29 | has baggage_items => ( | ||
| 30 | is => 'rwp', | ||
| 31 | should => HashRef[Str], | ||
| 32 | handles_via => 'Hash', | ||
| 33 | handles => { | ||
| 34 | # get_baggage_item => 'get', | ||
| 35 | get_baggage_items => 'all', | ||
| 36 | }, | ||
| 37 | 4 | ▶ | default => sub{ {} }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 38 | 19 | trigger => Lock, | |
| 39 | ); | ||
| 40 | |||
| 41 | # XXX: trigger and $obj->get_baggage_item( 'foo' ) do not play well together | ||
| 42 | # feels like a bug in Moo or Sub::Trigger::Lock | ||
| 43 | # | ||
| 44 | 6 | ▶ | sub get_baggage_item { |
|
Subroutine
get_baggage_item: called CC=1 SCAR=0.0
Pod
documented
| |||
| 45 | 6 | my $self = shift; | |
| 46 | 6 | my $item_key = shift; | |
| 47 | |||
| 48 | 6 | return { $self->get_baggage_items() }->{ $item_key } | |
| 49 | } | ||
| 50 | |||
| 51 | 3 | ▶ | sub new_clone { |
|
Subroutine
new_clone: called CC=1 SCAR=0.0
Pod
documented
| |||
| 52 | 3 | my $self = shift; | |
| 53 | |||
| 54 | 3 | my $class = ref $self; | |
| 55 | |||
| 56 | 3 | $class->new( %$self ) | |
| 57 | } | ||
| 58 | |||
| 59 | 2 | ▶ | sub with_trace_id { $_[0]->clone_with( trace_id => $_[1] ) } |
|
Subroutine
with_trace_id: called CC=1 SCAR=0.0
Pod
documented
| |||
| 60 | |||
| 61 | 6 | ▶ | sub with_span_id { $_[0]->clone_with( span_id => $_[1] ) } |
|
Subroutine
with_span_id: called CC=1 SCAR=0.0
Pod
documented
| |||
| 62 | |||
| 63 | 1 | ▶ | sub with_baggage_item { |
|
Subroutine
with_baggage_item: called CC=1 SCAR=0.0
Pod
documented
| |||
| 64 | 1 | my ( $self, $key, $value ) = @_; | |
| 65 | |||
| 66 | 1 | $self->clone_with( | |
| 67 | baggage_items => { $self->get_baggage_items(), $key => $value }, | ||
| 68 | ); | ||
| 69 | } | ||
| 70 | |||
| 71 | 3 | ▶ | sub with_baggage_items { |
|
Subroutine
with_baggage_items: called CC=1 SCAR=0.0
Pod
documented
| |||
| 72 | 3 | my ( $self, %args ) = @_; | |
| 73 | |||
| 74 | 3 | $self->clone_with( | |
| 75 | baggage_items => { $self->get_baggage_items(), %args }, | ||
| 76 | ); | ||
| 77 | } | ||
| 78 | |||
| 79 | 12 | ▶ | sub clone_with { |
|
Subroutine
clone_with: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 80 | 12 | my ( $self, @args ) = @_; | |
| 81 | |||
| 82 | 12 | bless { %$self, @args }, ref $self; | |
| 83 | |||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | 19 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 89 | # use Role::Tiny::With; | ||
| 90 | 19 | with 'OpenTracing::Interface::SpanContext' | |
| 91 | } | ||
| 92 | |||
| 93 | 19 | 1; | |