| 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.202.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 | log_data | ||
| 82 | add_baggage_item | ||
| 83 | add_baggage_items | ||
| 84 | get_baggage_item | ||
| 85 | get_baggage_items | ||
| 86 | ) ], | ||
| 87 | REQUIRED_METHODS_FOR_SPAN_CONTEXT => [ qw( | ||
| 88 | get_baggage_item | ||
| 89 | get_baggage_items | ||
| 90 | with_baggage_item | ||
| 91 | with_baggage_items | ||
| 92 | ) ], | ||
| 93 | REQUIRED_METHODS_FOR_TRACER => [ qw( | ||
| 94 | get_scope_manager | ||
| 95 | get_active_span | ||
| 96 | start_active_span | ||
| 97 | start_span | ||
| 98 | inject_context | ||
| 99 | extract_context | ||
| 100 | ) ], | ||
| 101 | 25 | ▶ | }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 102 | |||
| 103 | # XXX DO NOT COPY PASTE FROM CODE, READ THE POD | ||
| 104 | |||
| 105 | 25 | duck_type ContextReference => REQUIRED_METHODS_FOR_CONTEXT_REFERENCE; | |
| 106 | 25 | duck_type Scope => REQUIRED_METHODS_FOR_SCOPE; | |
| 107 | 25 | duck_type ScopeManager => REQUIRED_METHODS_FOR_SCOPE_MANAGER; | |
| 108 | 25 | duck_type Span => REQUIRED_METHODS_FOR_SPAN; | |
| 109 | 25 | duck_type SpanContext => REQUIRED_METHODS_FOR_SPAN_CONTEXT; | |
| 110 | 25 | duck_type Tracer => REQUIRED_METHODS_FOR_TRACER; | |
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | =head1 TYPES | ||
| 115 | |||
| 116 | The following Duck Types are being defined with the mentioned required methods: | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | |||
| 121 | |||
| 122 | =head2 C<< ContextReference >> | ||
| 123 | |||
| 124 | =over | ||
| 125 | |||
| 126 | =item C<< new_child_of >> | ||
| 127 | |||
| 128 | =item C<< new_follows_from >> | ||
| 129 | |||
| 130 | =item C<< get_referenced_context >> | ||
| 131 | |||
| 132 | =item C<< type_is_child_of >> | ||
| 133 | |||
| 134 | =item C<< type_is_follows_from >> | ||
| 135 | |||
| 136 | =back | ||
| 137 | |||
| 138 | See also L<OpenTracing::Interface::ContextReference/"INSTANCE METHODS"> | ||
| 139 | and L<OpenTracing::Interface::ContextReference/"CONSTRUCTOR METHODS">. | ||
| 140 | |||
| 141 | |||
| 142 | |||
| 143 | =head2 C<< Scope >> | ||
| 144 | |||
| 145 | =over | ||
| 146 | |||
| 147 | =item C<< close >> | ||
| 148 | |||
| 149 | =item C<< get_span >> | ||
| 150 | |||
| 151 | =back | ||
| 152 | |||
| 153 | See also L<OpenTracing::Interface::Scope/"INSTANCE METHODS">. | ||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | =head2 C<< ScopeManager >> | ||
| 158 | |||
| 159 | =over | ||
| 160 | |||
| 161 | =item C<< activate_span >> | ||
| 162 | |||
| 163 | =item C<< get_active_scope >> | ||
| 164 | |||
| 165 | =back | ||
| 166 | |||
| 167 | See also L<OpenTracing::Interface::ScopeManager/"INSTANCE METHODS">. | ||
| 168 | |||
| 169 | |||
| 170 | =head2 C<< Span >> | ||
| 171 | |||
| 172 | =over | ||
| 173 | |||
| 174 | =item C<< get_context >> | ||
| 175 | |||
| 176 | =item C<< overwrite_operation_name >> | ||
| 177 | |||
| 178 | =item C<< finish >> | ||
| 179 | |||
| 180 | =item C<< set_tag >> | ||
| 181 | |||
| 182 | =item C<< log_data >> | ||
| 183 | |||
| 184 | =item C<< add_baggage_item >> | ||
| 185 | |||
| 186 | =item C<< get_baggage_item >> | ||
| 187 | |||
| 188 | =back | ||
| 189 | |||
| 190 | See also L<OpenTracing::Interface::Span/"INSTANCE METHODS">. | ||
| 191 | |||
| 192 | |||
| 193 | |||
| 194 | =head2 C<< SpanContext >> | ||
| 195 | |||
| 196 | =over | ||
| 197 | |||
| 198 | =item C<< get_baggage_item >> | ||
| 199 | |||
| 200 | =item C<< with_baggage_item >> | ||
| 201 | |||
| 202 | =back | ||
| 203 | |||
| 204 | See also L<OpenTracing::Interface::SpanContext/"INSTANCE METHODS">. | ||
| 205 | |||
| 206 | |||
| 207 | |||
| 208 | =head2 C<< Tracer >> | ||
| 209 | |||
| 210 | =over | ||
| 211 | |||
| 212 | =item C<< get_scope_manager >> | ||
| 213 | |||
| 214 | =item C<< get_active_span >> | ||
| 215 | |||
| 216 | =item C<< start_active_span >> | ||
| 217 | |||
| 218 | =item C<< start_span >> | ||
| 219 | |||
| 220 | =item C<< inject_context >> | ||
| 221 | |||
| 222 | =item C<< extract_context >> | ||
| 223 | |||
| 224 | =back | ||
| 225 | |||
| 226 | See also L<OpenTracing::Interface::Tracer/"INSTANCE METHODS">. | ||
| 227 | |||
| 228 | |||
| 229 | |||
| 230 | =cut | ||
| 231 | |||
| 232 | |||
| 233 | |||
| 234 | =head1 AUTHOR | ||
| 235 | |||
| 236 | Theo van Hoesel <tvanhoesel@perceptyx.com> | ||
| 237 | |||
| 238 | =head1 COPYRIGHT AND LICENSE | ||
| 239 | |||
| 240 | 'OpenTracing Types' is Copyright (C) 2020, Perceptyx Inc | ||
| 241 | |||
| 242 | This library is free software; you can redistribute it and/or modify it under | ||
| 243 | the terms of the Artistic License 2.0. | ||
| 244 | |||
| 245 | This library is distributed in the hope that it will be useful, but it is | ||
| 246 | provided "as is" and without any express or implied warranties. | ||
| 247 | |||
| 248 | For details, see the full text of the license in the file LICENSE. | ||