X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FOptional%2FDependencies.pm;h=d1d8bbaabd2068795667769c758d5b9c8f3e569d;hb=250d9e55;hp=56f04dcce829553e22033fc2f4e833cb27f473da;hpb=a5741f5cbe12bb98400fe28e41aa6c05c3d50702;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Optional/Dependencies.pm b/lib/DBIx/Class/Optional/Dependencies.pm index 56f04dc..d1d8bba 100644 --- a/lib/DBIx/Class/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Optional/Dependencies.pm @@ -770,7 +770,11 @@ sub req_missing_for { my ($self, $groups) = @_; my $reqs = $self->_groups_to_reqs($groups); - my $mods_missing = $self->modreq_missing_for($groups); + + my $mods_missing = $reqs->{missing_envvars} + ? $self->_list_physically_missing_modules( $reqs->{modreqs} ) + : $self->modreq_missing_for($groups) + ; return '' if ! $mods_missing @@ -1085,7 +1089,7 @@ sub _groups_to_reqs { } -# this method tries to load specified modreqs and returns a hashref of +# this method tries to find/load specified modreqs and returns a hashref of # module/loaderror pairs for anything that failed sub _errorlist_for_modreqs { # args supposedly already went through _groups_to_reqs and are therefore sanitized @@ -1110,6 +1114,36 @@ sub _errorlist_for_modreqs { $ret; } +# Unlike the above DO NOT try to load anything +# This is executed when some needed envvars are not available +# which in turn means a module load will never be reached anyway +# This is important because some modules (especially DBDs) can be +# *really* fickle when a require() is attempted, with pretty confusing +# side-effects (especially on windows) +sub _list_physically_missing_modules { + my ($self, $modreqs) = @_; + + # in case there is a coderef in @INC there is nothing we can definitively prove + # so short circuit directly + return '' if grep { length ref $_ } @INC; + + my @definitely_missing; + for my $mod (keys %$modreqs) { + (my $fn = $mod . '.pm') =~ s|::|/|g; + + push @definitely_missing, $mod unless grep + # this should work on any combination of slashes + { $_ and -d $_ and -f "$_/$fn" and -r "$_/$fn" } + @INC + ; + } + + join ' ', map + { $modreqs->{$_} ? qq("$_~>=$modreqs->{$_}") : $_ } + sort { lc($a) cmp lc($b) } @definitely_missing + ; +} + # This is to be called by the author only (automatically in Makefile.PL) sub _gen_pod {