From f2dc99005ab12f416a17f16a76c6f8abd024e6fc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 12 Jan 2011 23:58:43 -0600 Subject: runtime conflict checks --- lib/Dist/CheckConflicts.pm | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lib/Dist/CheckConflicts.pm b/lib/Dist/CheckConflicts.pm index 0c2907f..b5e2a1c 100644 --- a/lib/Dist/CheckConflicts.pm +++ b/lib/Dist/CheckConflicts.pm @@ -117,6 +117,43 @@ sub import { $CONFLICTS{$for} = \%conflicts; $DISTS{$for} = $dist || $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}); + } + } + + # and warn for subsequently loaded things... + unshift @INC, [ + sub { + my ($sub, $file) = @_; + + (my $mod = $file) =~ s{\.pm$}{}; + $mod =~ s{/}{::}g; + return unless $mod =~ /[\w:]+/; + + return unless exists $conflicts{$mod}; + + { + local @INC = grep { + !(ref($_) eq 'ARRAY' && @$_ > 1 && $_->[1] == \%CONFLICTS) + } @INC; + + require $file; + } + + _check_version($for, $mod, $conflicts{$mod}); + + my $i = 1; + return sub { $_ = $i-- }; # the previous require already handled it + }, + \%CONFLICTS, # arbitrary but unique, see above + $for, # debugging + ]; + goto $import; } @@ -133,6 +170,22 @@ sub _strip_opt { return ( $val, @_ ); } +sub _check_version { + my ($for, $mod, $conflict_ver) = @_; + + my $version = do { + no strict 'refs'; + ${ ${ $mod . '::' }{VERSION} }; + }; + + if ($version le $conflict_ver) { + warn < parameter to -- cgit v1.2.3-54-g00ecf