summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-06-21 10:04:21 -0400
committerJesse Luehrs <doy@tozt.net>2013-06-21 10:04:21 -0400
commit6e012ee749903e4b5b49004e12b30a69be5bf911 (patch)
treedc4b76e1bc7d23f95d41f31875b5e6d0784c8e37
parent789a4672cc0225d01973250305982c0f8565accf (diff)
downloaddist-checkconflicts-6e012ee749903e4b5b49004e12b30a69be5bf911.tar.gz
dist-checkconflicts-6e012ee749903e4b5b49004e12b30a69be5bf911.zip
make runtime warnings optional
-rw-r--r--lib/Dist/CheckConflicts.pm85
-rw-r--r--t/02-conflicts.t28
-rw-r--r--t/03-dist.t28
-rw-r--r--t/lib/06/Bar/Conflicts.pm1
-rw-r--r--t/lib/06/Foo/Conflicts.pm1
5 files changed, 50 insertions, 93 deletions
diff --git a/lib/Dist/CheckConflicts.pm b/lib/Dist/CheckConflicts.pm
index a3746d3..1fea9e2 100644
--- a/lib/Dist/CheckConflicts.pm
+++ b/lib/Dist/CheckConflicts.pm
@@ -120,52 +120,55 @@ 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);
+ if (grep { $_ eq ':runtime' } @_) {
+ for my $conflict (keys %conflicts) {
+ $HAS_CONFLICTS{$conflict} ||= [];
+ push @{ $HAS_CONFLICTS{$conflict} }, $for;
}
- }
-
- # and warn for subsequently loaded things...
- @INC = grep {
- !(ref($_) eq 'ARRAY' && @$_ > 1 && $_->[1] == \%CONFLICTS)
- } @INC;
- unshift @INC, [
- sub {
- my ($sub, $file) = @_;
-
- (my $mod = $file) =~ s{\.pm$}{};
- $mod =~ s{/}{::}g;
- return unless $mod =~ /[\w:]+/;
- return unless defined $HAS_CONFLICTS{$mod};
-
- {
- local $HAS_CONFLICTS{$mod};
- require $file;
+ # 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);
}
+ }
- _check_version($HAS_CONFLICTS{$mod}, $mod);
-
- # the previous require already handled it
- my $called;
- return sub {
- return 0 if $called;
- $_ = "1;";
- $called = 1;
- return 1;
- };
- },
- \%CONFLICTS, # arbitrary but unique, see above
- ];
+ # and warn for subsequently loaded things...
+ @INC = grep {
+ !(ref($_) eq 'ARRAY' && @$_ > 1 && $_->[1] == \%CONFLICTS)
+ } @INC;
+ unshift @INC, [
+ sub {
+ my ($sub, $file) = @_;
+
+ (my $mod = $file) =~ s{\.pm$}{};
+ $mod =~ s{/}{::}g;
+ return unless $mod =~ /[\w:]+/;
+
+ return unless defined $HAS_CONFLICTS{$mod};
+
+ {
+ local $HAS_CONFLICTS{$mod};
+ require $file;
+ }
+
+ _check_version($HAS_CONFLICTS{$mod}, $mod);
+
+ # the previous require already handled it
+ my $called;
+ return sub {
+ return 0 if $called;
+ $_ = "1;";
+ $called = 1;
+ return 1;
+ };
+ },
+ \%CONFLICTS, # arbitrary but unique, see above
+ ];
+ }
$pkg->export_to_level(1, @_);
}
diff --git a/t/02-conflicts.t b/t/02-conflicts.t
index 663b1e8..3d288a2 100644
--- a/t/02-conflicts.t
+++ b/t/02-conflicts.t
@@ -5,21 +5,6 @@ use Test::More;
use Test::Fatal;
use lib 't/lib/02';
-sub use_ok_warnings {
- my ($class, @conflicts) = @_;
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- @conflicts = sort map { "Conflict detected for $_->[0]:\n $_->[1] is version $_->[2], but must be greater than version $_->[3]\n" } @conflicts;
-
- my @warnings;
- {
- local $SIG{__WARN__} = sub { push @warnings, $_[0] };
- use_ok($class);
- }
- @warnings = sort @warnings;
-
- is_deeply(\@warnings, \@conflicts, "correct runtime warnings for $class");
-}
-
{
use_ok('Foo::Conflicts::Good');
is_deeply(
@@ -35,11 +20,7 @@ sub use_ok_warnings {
}
{
- use_ok_warnings(
- 'Foo::Conflicts::Bad',
- ['Foo::Conflicts::Bad', 'Foo::Two', '0.02', '0.02'],
- ['Foo::Conflicts::Bad', 'Foo', '0.02', '0.03'],
- );
+ use_ok('Foo::Conflicts::Bad');
is_deeply(
[ Foo::Conflicts::Bad->calculate_conflicts ],
@@ -71,12 +52,7 @@ sub use_ok_warnings {
}
{
- use_ok_warnings(
- 'Bar::Conflicts::Bad',
- ['Bar::Conflicts::Bad2', 'Bar::Two', '0.02', '0.02'],
- ['Bar::Conflicts::Bad', 'Bar::Two', '0.02', '0.02'],
- ['Bar::Conflicts::Bad', 'Bar', '0.02', '0.03'],
- );
+ use_ok('Bar::Conflicts::Bad');
is_deeply(
[ Bar::Conflicts::Bad->calculate_conflicts ],
diff --git a/t/03-dist.t b/t/03-dist.t
index 277ccfd..c40e22c 100644
--- a/t/03-dist.t
+++ b/t/03-dist.t
@@ -5,21 +5,6 @@ use Test::More;
use Test::Fatal;
use lib 't/lib/03';
-sub use_ok_warnings {
- my ($class, @conflicts) = @_;
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- @conflicts = sort map { "Conflict detected for $_->[0]:\n $_->[1] is version $_->[2], but must be greater than version $_->[3]\n" } @conflicts;
-
- my @warnings;
- {
- local $SIG{__WARN__} = sub { push @warnings, $_[0] };
- use_ok($class);
- }
- @warnings = sort @warnings;
-
- is_deeply(\@warnings, \@conflicts, "correct runtime warnings for $class");
-}
-
{
use_ok('Foo::Conflicts::Good');
is_deeply(
@@ -36,11 +21,7 @@ sub use_ok_warnings {
}
{
- use_ok_warnings(
- 'Foo::Conflicts::Bad',
- ['Foo', 'Foo::Two', '0.02', '0.02'],
- ['Foo', 'Foo', '0.02', '0.03'],
- );
+ use_ok('Foo::Conflicts::Bad');
is_deeply(
[ Foo::Conflicts::Bad->calculate_conflicts ],
@@ -74,12 +55,7 @@ sub use_ok_warnings {
}
{
- use_ok_warnings(
- 'Bar::Conflicts::Bad',
- ['Bar', 'Bar::Two', '0.02', '0.02'],
- ['Bar', 'Bar::Two', '0.02', '0.02'],
- ['Bar', 'Bar', '0.02', '0.03'],
- );
+ use_ok('Bar::Conflicts::Bad');
is_deeply(
[ Bar::Conflicts::Bad->calculate_conflicts ],
diff --git a/t/lib/06/Bar/Conflicts.pm b/t/lib/06/Bar/Conflicts.pm
index ce47d43..c9c6f3d 100644
--- a/t/lib/06/Bar/Conflicts.pm
+++ b/t/lib/06/Bar/Conflicts.pm
@@ -3,6 +3,7 @@ use strict;
use warnings;
use Dist::CheckConflicts
+ ':runtime',
-conflicts => {
'Bar::Foo' => 0.01,
'Bar::Foo::Good' => 0.01,
diff --git a/t/lib/06/Foo/Conflicts.pm b/t/lib/06/Foo/Conflicts.pm
index 15e50e7..34ea4b0 100644
--- a/t/lib/06/Foo/Conflicts.pm
+++ b/t/lib/06/Foo/Conflicts.pm
@@ -3,6 +3,7 @@ use strict;
use warnings;
use Dist::CheckConflicts
+ ':runtime',
-conflicts => {
'Foo::Foo' => 0.01,
'Foo::Bar' => 0.01,