summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-01-13 01:17:40 -0600
committerJesse Luehrs <doy@tozt.net>2011-01-13 01:17:40 -0600
commitb7e4e8e25e10d97446650b2c2298088e093e6890 (patch)
tree68c4dc74951d9fb8c3df4f2591735dac492a9315
parentc1d96ea5ce0260890f0e496438ab762728877154 (diff)
downloaddist-checkconflicts-b7e4e8e25e10d97446650b2c2298088e093e6890.tar.gz
dist-checkconflicts-b7e4e8e25e10d97446650b2c2298088e093e6890.zip
only use one @INC hook
-rw-r--r--lib/Dist/CheckConflicts.pm36
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/Dist/CheckConflicts.pm b/lib/Dist/CheckConflicts.pm
index f802c10..cb89a0d 100644
--- a/lib/Dist/CheckConflicts.pm
+++ b/lib/Dist/CheckConflicts.pm
@@ -90,6 +90,7 @@ my $import = Sub::Exporter::build_exporter({
});
my %CONFLICTS;
+my %HAS_CONFLICTS;
my %DISTS;
sub import {
@@ -120,17 +121,24 @@ sub import {
$CONFLICTS{$for} = \%conflicts;
$DISTS{$for} = $dist || $for;
+ for my $conflict (keys %conflicts) {
+ $HAS_CONFLICTS{$conflict} ||= [];
+ push @{ $HAS_CONFLICTS{$conflict} }, $for;
+ }
# warn for already loaded things...
for my $conflict (keys %conflicts) {
(my $file = $conflict) =~ s{::}{/}g;
$file .= '.pm';
if (exists $INC{$file}) {
- _check_version($for, $conflict, $conflicts{$conflict});
+ _check_version([$for], $conflict);
}
}
# and warn for subsequently loaded things...
+ @INC = grep {
+ !(ref($_) eq 'ARRAY' && @$_ > 1 && $_->[1] == \%CONFLICTS)
+ } @INC;
unshift @INC, [
sub {
my ($sub, $file) = @_;
@@ -139,21 +147,19 @@ sub import {
$mod =~ s{/}{::}g;
return unless $mod =~ /[\w:]+/;
- return unless defined $CONFLICTS{$for}
- && defined $CONFLICTS{$for}{$mod};
+ return unless defined $HAS_CONFLICTS{$mod};
{
- local $CONFLICTS{$for}{$mod};
+ local $HAS_CONFLICTS{$mod};
require $file;
}
- _check_version($for, $mod, $conflicts{$mod});
+ _check_version($HAS_CONFLICTS{$mod}, $mod);
my $i = 1;
return sub { $_ = $i-- }; # the previous require already handled it
},
\%CONFLICTS, # arbitrary but unique, see above
- $for, # debugging
];
goto $import;
@@ -173,18 +179,22 @@ sub _strip_opt {
}
sub _check_version {
- my ($for, $mod, $conflict_ver) = @_;
+ my ($fors, $mod) = @_;
- my $version = do {
- no strict 'refs';
- ${ ${ $mod . '::' }{VERSION} };
- };
+ for my $for (@$fors) {
+ my $conflict_ver = $CONFLICTS{$for}{$mod};
+ my $version = do {
+ no strict 'refs';
+ ${ ${ $mod . '::' }{VERSION} };
+ };
- if ($version le $conflict_ver) {
- warn <<EOF;
+ if ($version le $conflict_ver) {
+ warn <<EOF;
Conflict detected for $DISTS{$for}:
$mod is version $version, but must be greater than version $conflict_ver
EOF
+ return;
+ }
}
}