Skip to content

Commit

Permalink
Use CPAN's isa to support 5.30
Browse files Browse the repository at this point in the history
  • Loading branch information
jjatria committed Dec 19, 2024
1 parent 24d0d55 commit cf43866
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

# All supported Perl versions except latest.
perl: [
'5.32', '5.34', '5.36',
'5.30', '5.32', '5.34', '5.36',
]

# Variants of the latest Perl.
Expand Down
2 changes: 1 addition & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings;


use v5.32.0;
use v5.30.0;
use Module::Build::Tiny 0.034;
Build_PL();

4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Revision history for OpenTelemetry
{{$NEXT}}

* Fixed some minor nits in the documentation
* Add 'isa' as a dependency and reduce the minimum supported Perl
version to 5.30. If you are running 5.30 please consider installing
Type::Tiny::XS which should improve the performance of these 'isa'
checks.

0.026 2024-12-16 09:02:42+00:00 Europe/London

Expand Down
7 changes: 4 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"configure" : {
"requires" : {
"Module::Build::Tiny" : "0.034",
"perl" : "v5.32.0"
"perl" : "v5.30.0"
}
},
"develop" : {
Expand Down Expand Up @@ -61,7 +61,8 @@
"URL::Encode" : "0",
"UUID::URandom" : "0",
"X::Tiny" : "0",
"perl" : "v5.32.0"
"isa" : "0",
"perl" : "v5.30.0"
}
},
"test" : {
Expand All @@ -75,7 +76,7 @@
"Metrics::Any" : "0",
"Test2::V0" : "0",
"Test::More" : "0",
"perl" : "v5.32.0"
"perl" : "v5.30.0"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requires 'isa'; # To support perls older than 5.32
requires 'Bytes::Random::Secure';
requires 'Class::Method::Modifiers';
requires 'Exporter::Tiny', '0.044'; # For -as => CODE support
Expand Down
2 changes: 2 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Release_Commit.commit_msg = Release v%V%t
RewriteVersion.global = 1

[MinimumPerl]
perl = v5.30.0

[Prereqs::FromCPANfile]

[Repository]
Expand Down
11 changes: 8 additions & 3 deletions lib/OpenTelemetry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package OpenTelemetry;

use strict;
use warnings;
use experimental qw( isa signatures );
use experimental qw( signatures );

our $VERSION = '0.027';

Expand All @@ -18,6 +18,11 @@ use Scalar::Util 'refaddr';
use Ref::Util 'is_coderef';
use Sentinel;

use isa qw(
OpenTelemetry::Logs::LoggerProvider
OpenTelemetry::Trace::TracerProvider
);

use Log::Any;

use Exporter::Shiny qw(
Expand Down Expand Up @@ -45,7 +50,7 @@ sub _generate_otel_logger { \&logger }
my $set = sub ( $new ) {
die OpenTelemetry::X->create(
Invalid => 'Global tracer provider must be a subclass of OpenTelemetry::Trace::TracerProvider, got instead ' . ( ref $new || 'a plain scalar' ),
) unless $new isa OpenTelemetry::Trace::TracerProvider;
) unless isa_OpenTelemetry_Trace_TracerProvider $new;

$lock->enter( sub { $instance = $new });
};
Expand Down Expand Up @@ -77,7 +82,7 @@ sub _generate_otel_logger { \&logger }
my $set = sub ( $new ) {
die OpenTelemetry::X->create(
Invalid => 'Global logger provider must be a subclass of OpenTelemetry::Logs::LoggerProvider, got instead ' . ( ref $new || 'a plain scalar' ),
) unless $new isa OpenTelemetry::Logs::LoggerProvider;
) unless isa_OpenTelemetry_Logs_LoggerProvider $new;

$lock->enter( sub { $instance = $new });
};
Expand Down
14 changes: 8 additions & 6 deletions lib/OpenTelemetry/Context.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ sub key ( $, $name ) {

class OpenTelemetry::Context {
use OpenTelemetry::X;
use experimental 'isa';

use isa 'OpenTelemetry::Context::Key';

field $data :param = {};

Expand All @@ -34,23 +35,23 @@ class OpenTelemetry::Context {
method get ( $key ) {
die OpenTelemetry::X->create(
Invalid => 'Keys in a context object must be instances of OpenTelemetry::Context::Key',
) unless $key isa OpenTelemetry::Context::Key;
) unless isa_OpenTelemetry_Context_Key $key;

$data->{ $key->string };
}

method set ( $key, $value ) {
die OpenTelemetry::X->create(
Invalid => 'Keys in a context object must be instances of OpenTelemetry::Context::Key',
) unless $key isa OpenTelemetry::Context::Key;
) unless isa_OpenTelemetry_Context_Key $key;

OpenTelemetry::Context->new( %$data, $key->string, $value )
}

method delete ( $key ) {
die OpenTelemetry::X->create(
Invalid => 'Keys in a context object must be instances of OpenTelemetry::Context::Key',
) unless $key isa OpenTelemetry::Context::Key;
) unless isa_OpenTelemetry_Context_Key $key;

my %copy = %$data;
delete $copy{$key->string};
Expand All @@ -61,17 +62,18 @@ class OpenTelemetry::Context {

# Context management
{
use experimental 'isa';
use Sentinel;

use isa 'OpenTelemetry::Context';

my $current = OpenTelemetry::Context->new;
sub current :lvalue {
sentinel(
get => sub { $current },
set => sub {
die OpenTelemetry::X->create(
Invalid => 'Current context must be an instance of OpenTelemetry::Context, received instead ' . ref $_[0],
) unless $_[0] isa OpenTelemetry::Context;
) unless isa_OpenTelemetry_Context $_[0];

$current = $_[0];
},
Expand Down
6 changes: 3 additions & 3 deletions lib/OpenTelemetry/Propagator/Baggage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OpenTelemetry::Propagator::Baggage :does(OpenTelemetry::Propagator) {
use OpenTelemetry::Propagator::TextMap;
use URL::Encode qw( url_decode_utf8 url_encode_utf8 );

use experimental 'isa';
use isa 'OpenTelemetry::X';

my $KEY = 'baggage';
my $MAX_ENTRIES = 180;
Expand Down Expand Up @@ -68,7 +68,7 @@ class OpenTelemetry::Propagator::Baggage :does(OpenTelemetry::Propagator) {
$setter->( $carrier, $KEY, $encoded ) if $encoded;
}
catch($e) {
if ( $e isa OpenTelemetry::X ) { $logger->warn($e->get_message) }
if ( isa_OpenTelemetry_X $e ) { $logger->warn($e->get_message) }
else {
OpenTelemetry->handle_error(
exception => $e,
Expand Down Expand Up @@ -102,7 +102,7 @@ class OpenTelemetry::Propagator::Baggage :does(OpenTelemetry::Propagator) {
$builder->build($context);
}
catch($e) {
if ( $e isa OpenTelemetry::X ) { $logger->warn($e->get_message) }
if ( isa_OpenTelemetry_X $e ) { $logger->warn($e->get_message) }
else {
OpenTelemetry->handle_error(
exception => $e,
Expand Down
6 changes: 3 additions & 3 deletions lib/OpenTelemetry/Propagator/TraceContext.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package OpenTelemetry::Propagator::TraceContext;
our $VERSION = '0.027';

class OpenTelemetry::Propagator::TraceContext :does(OpenTelemetry::Propagator) {
use experimental 'isa';
use isa 'OpenTelemetry::X';

use Feature::Compat::Try;
use URL::Encode qw( url_decode_utf8 url_encode_utf8 );
Expand Down Expand Up @@ -46,7 +46,7 @@ class OpenTelemetry::Propagator::TraceContext :does(OpenTelemetry::Propagator) {
$setter->( $carrier, $TRACE_STATE_KEY, $span_context->trace_state->to_string );
}
catch($e) {
if ( $e isa OpenTelemetry::X ) { $logger->warn($e->get_message) }
if ( isa_OpenTelemetry_X $e ) { $logger->warn($e->get_message) }
else {
OpenTelemetry->handle_error(
exception => $e,
Expand Down Expand Up @@ -89,7 +89,7 @@ class OpenTelemetry::Propagator::TraceContext :does(OpenTelemetry::Propagator) {
return OpenTelemetry::Trace->context_with_span( $span, $context );
}
catch ($e) {
if ( $e isa OpenTelemetry::X ) { $logger->warn($e->get_message) }
if ( isa_OpenTelemetry_X $e ) { $logger->warn($e->get_message) }
else {
OpenTelemetry->handle_error(
exception => $e,
Expand Down
6 changes: 3 additions & 3 deletions lib/OpenTelemetry/Trace/Link.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package OpenTelemetry::Trace::Link;
our $VERSION = '0.027';

class OpenTelemetry::Trace::Link :does(OpenTelemetry::Attributes) {
use experimental 'isa';

use OpenTelemetry::X;

use isa 'OpenTelemetry::Trace::SpanContext';

field $context :param :reader;

ADJUST {
die OpenTelemetry::X->create(
Invalid => "Required parameter 'context' must be a span context"
) unless $context isa OpenTelemetry::Trace::SpanContext;
) unless isa_OpenTelemetry_Trace_SpanContext $context;
}
}

0 comments on commit cf43866

Please sign in to comment.