Permalink
Browse files

Merge branch 'exodist/master' into HEAD

This introduces circular::require which will issue warnings if you load
modules that have circular dependencies from within a module that uses
perl5i.

Care has been taken to supress warnings that would issue fourth from
perl5i dependencies themselves which do have circular dependencies
(DateTime).

this fixes #217
  • Loading branch information...
2 parents b572034 + 940b465 commit 6a51af0f6ec0f2d7d3fa2271ff114744efe8f079 @exodist exodist committed Jan 7, 2012
Showing with 20 additions and 3 deletions.
  1. +1 −0 Build.PL
  2. +9 −0 lib/perl5i/2.pm
  3. +3 −1 lib/perl5i/2/DateTime.pm
  4. +7 −2 lib/perl5i/2/RequireMessage.pm
View
1 Build.PL
@@ -50,6 +50,7 @@ my $builder = MyBuild->new(
'true::VERSION' => '0.16',
'Capture::Tiny' => '0.06',
'utf8::all' => '0.002',
+ 'circular::require' => '0.09',
},
build_requires => {
'ExtUtils::CBuilder' => '0.26',
View
9 lib/perl5i/2.pm
@@ -7,6 +7,9 @@ use strict;
use warnings;
#This should come first
+use circular::require;
+
+# A few of the following modules have cycles, so turn off detection for now.
use perl5i::2::RequireMessage;
use IO::Handle;
@@ -31,6 +34,9 @@ use parent 'autovivification';
use parent 'indirect';
use parent 'utf8::all';
+# Enable cycle detection.
+no circular::require;
+
## no critic (Subroutines::RequireArgUnpacking)
sub import {
my $class = shift;
@@ -92,6 +98,9 @@ sub import {
# Current lexically active major version of perl5i.
$^H{perl5i} = 2;
+ # enable cycle detection
+ circular::require->unimport();
+
# autodie needs a bit more convincing
@_ = ( $class, ":all" );
goto &autodie::import;
View
4 lib/perl5i/2/DateTime.pm
@@ -6,6 +6,9 @@ use 5.010;
use strict;
use warnings;
+use circular::require;
+use DateTime;
+
# Determine if we need Time::y2038 and only load if necessary.
# XXX This is a bit of a hack and should go into a config file.
use constant NEEDS_y2038 => (
@@ -29,7 +32,6 @@ sub dt_gmtime (;$) {
$mon++;
$year += 1900;
- require DateTime;
return perl5i::2::DateTime::y2038->new(
year => $year,
month => $mon,
View
9 lib/perl5i/2/RequireMessage.pm
@@ -6,8 +6,13 @@ use warnings;
my $diesub = sub {
my ( $sub, $mod ) = @_;
- my $hints = (caller(0))[10];
- return unless $hints->{perl5i};
+ my @caller;
+ my $count = 0;
+ @caller = caller($count++)
+ while !$caller[0] || $caller[0] eq 'circular::require';
+
+ return unless $caller[10]->{perl5i};
+
die( <<EOT );
Can't locate $mod in your Perl library. You may need to install it
from CPAN or another repository. Your library paths are:

0 comments on commit 6a51af0

Please sign in to comment.