| 1 | package OpenTracing::Types; | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | OpenTracing::Types - Type constraints for checking Interfaces | ||
| 8 | |||
| 9 | =cut | ||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | 25 | our $VERSION = 'v0.206.0'; | |
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | use OpenTracing::Types qw/Span/; | ||
| 20 | # | ||
| 21 | # imports the 'Span' Type | ||
| 22 | |||
| 23 | use Types::Standard qw/Maybe/; | ||
| 24 | use Types::Common::Numeric qw/PositiveOrZeroNum/; | ||
| 25 | |||
| 26 | use Function::Parameters; | ||
| 27 | use Function::Return; | ||
| 28 | |||
| 29 | # create a subroutine with some fancy type checks | ||
| 30 | # | ||
| 31 | sub time_gap (Span $span1, Span $span2) :Return Maybe[PositiveOrZeroNum] { | ||
| 32 | return unless $span1->finish_time and $span2->start_time; | ||
| 33 | return $span2->start_time - $span1->finish_time | ||
| 34 | } | ||
| 35 | |||
| 36 | =head1 DESCRIPTION | ||
| 37 | |||
| 38 | This library of L<Type::Tiny> type constraints provide Duck Type checks for all | ||
| 39 | common elements that conform L<OpenTracing::Interface> | ||
| 40 | |||
| 41 | See L<Type::Library/"Export"> about the various ways to import types an related | ||
| 42 | methods. | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | 25 | ▶ | use Type::Library -base; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | 25 | ▶ | use Type::Utils qw/duck_type/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 48 | |||
| 49 | # Dear developer, for the sake of testing, please DO NOT just copy paste the | ||
| 50 | # methods from the `OpenTracing::Types` file. If I wanted to just | ||
| 51 | # check that the `duck_type` utility from `Type::Tiny` would work, I would have | ||
| 52 | # not needed this test. | ||
| 53 | # | ||
| 54 | # This test is to ensure that what is written in the POD files is indeed what | ||
| 55 | # the Types library is doing. | ||
| 56 | # | ||
| 57 | # The OpenTracing::Interface::*.pod files are leading, not the code. | ||
| 58 | # | ||
| 59 | use constant { | ||
| 60 | 25 | REQUIRED_METHODS_FOR_CONTEXT_REFERENCE => [ qw( | |
| 61 | new_child_of | ||
| 62 | new_follows_from | ||
| 63 | get_referenced_context | ||
| 64 | type_is_child_of | ||
| 65 | type_is_follows_from | ||
| 66 | ) ], | ||
| 67 | REQUIRED_METHODS_FOR_SCOPE => [ qw( | ||
| 68 | close | ||
| 69 | get_span | ||
| 70 | ) ], | ||
| 71 | REQUIRED_METHODS_FOR_SCOPE_MANAGER => [ qw( | ||
| 72 | activate_span | ||
| 73 | get_active_scope | ||
| 74 | ) ], | ||
| 75 | REQUIRED_METHODS_FOR_SPAN => [ qw( | ||
| 76 | get_context | ||
| 77 | overwrite_operation_name | ||
| 78 | finish | ||
| 79 | add_tag | ||
| 80 | add_tags | ||
| 81 | get_tags | ||
| 82 | log_data | ||
| 83 | add_baggage_item | ||
| 84 | add_baggage_items | ||
| 85 | get_baggage_item | ||
| 86 | get_baggage_items | ||
| 87 | ) ], | ||
| 88 | REQUIRED_METHODS_FOR_SPAN_CONTEXT => [ qw( | ||
| 89 | get_baggage_item | ||
| 90 | get_baggage_items | ||
| 91 | with_baggage_item | ||
| 92 | with_baggage_items | ||
| 93 | ) ], | ||
| 94 | REQUIRED_METHODS_FOR_TRACER => [ qw( | ||
| 95 | get_scope_manager | ||
| 96 | get_active_span | ||
| 97 | start_active_span | ||
| 98 | start_span | ||
| 99 | inject_context | ||
| 100 | extract_context | ||
| 101 | ) ], | ||
| 102 | 25 | ▶ | }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 103 | |||
| 104 | # XXX DO NOT COPY PASTE FROM CODE, READ THE POD | ||
| 105 | |||
| 106 | 25 | duck_type ContextReference => REQUIRED_METHODS_FOR_CONTEXT_REFERENCE; | |
| 107 | 25 | duck_type Scope => REQUIRED_METHODS_FOR_SCOPE; | |
| 108 | 25 | duck_type ScopeManager => REQUIRED_METHODS_FOR_SCOPE_MANAGER; | |
| 109 | 25 | duck_type Span => REQUIRED_METHODS_FOR_SPAN; | |
| 110 | 25 | duck_type SpanContext => REQUIRED_METHODS_FOR_SPAN_CONTEXT; | |
| 111 | 25 | duck_type Tracer => REQUIRED_METHODS_FOR_TRACER; | |
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | =head1 TYPES | ||
| 116 | |||
| 117 | The following Duck Types are being defined with the mentioned required methods: | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | |||
| 122 | |||
| 123 | =head2 C<< ContextReference >> | ||
| 124 | |||
| 125 | =over | ||
| 126 | |||
| 127 | =item C<< new_child_of >> | ||
| 128 | |||
| 129 | =item C<< new_follows_from >> | ||
| 130 | |||
| 131 | =item C<< get_referenced_context >> | ||
| 132 | |||
| 133 | =item C<< type_is_child_of >> | ||
| 134 | |||
| 135 | =item C<< type_is_follows_from >> | ||
| 136 | |||
| 137 | =back | ||
| 138 | |||
| 139 | See also L<OpenTracing::Interface::ContextReference/"INSTANCE METHODS"> | ||
| 140 | and L<OpenTracing::Interface::ContextReference/"CONSTRUCTOR METHODS">. | ||
| 141 | |||
| 142 | |||
| 143 | |||
| 144 | =head2 C<< Scope >> | ||
| 145 | |||
| 146 | =over | ||
| 147 | |||
| 148 | =item C<< close >> | ||
| 149 | |||
| 150 | =item C<< get_span >> | ||
| 151 | |||
| 152 | =back | ||
| 153 | |||
| 154 | See also L<OpenTracing::Interface::Scope/"INSTANCE METHODS">. | ||
| 155 | |||
| 156 | |||
| 157 | |||
| 158 | =head2 C<< ScopeManager >> | ||
| 159 | |||
| 160 | =over | ||
| 161 | |||
| 162 | =item C<< activate_span >> | ||
| 163 | |||
| 164 | =item C<< get_active_scope >> | ||
| 165 | |||
| 166 | =back | ||
| 167 | |||
| 168 | See also L<OpenTracing::Interface::ScopeManager/"INSTANCE METHODS">. | ||
| 169 | |||
| 170 | |||
| 171 | =head2 C<< Span >> | ||
| 172 | |||
| 173 | =over | ||
| 174 | |||
| 175 | =item C<< get_context >> | ||
| 176 | |||
| 177 | =item C<< overwrite_operation_name >> | ||
| 178 | |||
| 179 | =item C<< finish >> | ||
| 180 | |||
| 181 | =item C<< set_tag >> | ||
| 182 | |||
| 183 | =item C<< log_data >> | ||
| 184 | |||
| 185 | =item C<< add_baggage_item >> | ||
| 186 | |||
| 187 | =item C<< get_baggage_item >> | ||
| 188 | |||
| 189 | =back | ||
| 190 | |||
| 191 | See also L<OpenTracing::Interface::Span/"INSTANCE METHODS">. | ||
| 192 | |||
| 193 | |||
| 194 | |||
| 195 | =head2 C<< SpanContext >> | ||
| 196 | |||
| 197 | =over | ||
| 198 | |||
| 199 | =item C<< get_baggage_item >> | ||
| 200 | |||
| 201 | =item C<< with_baggage_item >> | ||
| 202 | |||
| 203 | =back | ||
| 204 | |||
| 205 | See also L<OpenTracing::Interface::SpanContext/"INSTANCE METHODS">. | ||
| 206 | |||
| 207 | |||
| 208 | |||
| 209 | =head2 C<< Tracer >> | ||
| 210 | |||
| 211 | =over | ||
| 212 | |||
| 213 | =item C<< get_scope_manager >> | ||
| 214 | |||
| 215 | =item C<< get_active_span >> | ||
| 216 | |||
| 217 | =item C<< start_active_span >> | ||
| 218 | |||
| 219 | =item C<< start_span >> | ||
| 220 | |||
| 221 | =item C<< inject_context >> | ||
| 222 | |||
| 223 | =item C<< extract_context >> | ||
| 224 | |||
| 225 | =back | ||
| 226 | |||
| 227 | See also L<OpenTracing::Interface::Tracer/"INSTANCE METHODS">. | ||
| 228 | |||
| 229 | |||
| 230 | |||
| 231 | =cut | ||
| 232 | |||
| 233 | |||
| 234 | |||
| 235 | =head1 AUTHOR | ||
| 236 | |||
| 237 | Theo van Hoesel <tvanhoesel@perceptyx.com> | ||
| 238 | |||
| 239 | =head1 COPYRIGHT AND LICENSE | ||
| 240 | |||
| 241 | 'OpenTracing Types' is Copyright (C) 2020 .. 2021, Perceptyx Inc | ||
| 242 | |||
| 243 | This library is free software; you can redistribute it and/or modify it under | ||
| 244 | the terms of the Artistic License 2.0. | ||
| 245 | |||
| 246 | This library is distributed in the hope that it will be useful, but it is | ||
| 247 | provided "as is" and without any express or implied warranties. | ||
| 248 | |||
| 249 | For details, see the full text of the license in the file LICENSE. | ||