Skip to content

Commit

Permalink
revert commit 114f948 (gh #54)
Browse files Browse the repository at this point in the history
The existing code falls back to URI::urn and already caches the implementor after it's done. It therefore can never try to load one twice if it previously failed.
  • Loading branch information
Matthew Chae authored and oalders committed Jan 27, 2024
1 parent ebb0b5d commit b183b02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 0 additions & 4 deletions lib/URI/urn.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use parent 'URI';
use Carp qw(carp);

my %implementor;
my %require_attempted;

sub _init {
my $class = shift;
Expand All @@ -30,21 +29,18 @@ sub _init {
$impclass = "URI::urn::$id";
no strict 'refs';
unless (@{"${impclass}::ISA"}) {
if (not exists $require_attempted{$impclass}) {
# Try to load it
my $_old_error = $@;
eval "require $impclass";
die $@ if $@ && $@ !~ /Can\'t locate.*in \@INC/;
$@ = $_old_error;
}
$impclass = "URI::urn" unless @{"${impclass}::ISA"};
}
}
else {
carp("Illegal namespace identifier '$nid' for URN '$self'") if $^W;
}
$implementor{$nid} = $impclass;

return $impclass->_urn_init($self, $nid);
}

Expand Down
19 changes: 19 additions & 0 deletions t/urn-scheme-exceptions.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use strict;
use warnings;

use Test::More;
use URI::urn;

plan tests => 6;

{
require URI::_foreign; # load this before disabling @INC
my $count = 0;
local @INC = sub { $count++; return };
for ( 0 .. 1 ) {
my $uri = URI->new('urn:asdfasdf:1.2.3.4.5.6.7.8.9.10');
is( $count, 1, 'only attempt to load the scheme package once' );
is( $@, '', 'no exception when trying to load a scheme handler class' );
ok( $uri->isa('URI'), 'but URI still instantiated as foreign' );
}
}

0 comments on commit b183b02

Please sign in to comment.