I'm not sure if this of any help, but it's a function I'm using in Filter::Simple to 
locate modules much like 'require' or 'use' might.

  use vars '%INC';
  sub find_module_file {
    my $pkg = $_[0];

    my($file, @dirs) = reverse split '::' => $pkg;
    my $path = catfile reverse(@dirs), "$file.pm";

    return $INC{$path}
      if exists $INC{$path} and defined $INC{$path};

    my $lib;
    
    for(@INC) {
      ## do references in @INC magic here ...
      if(ref $_) {
        my $ret = ( ref($_) eq 'CODE' ?
          $_->( $_, $path )
        : 
          ref($_) eq 'ARRAY' ?
            $_->[0]->( $_, $path )
          : 
            UNIVERSAL::can($_, 'INC') ?
              $_->INC( $path )
            : 
              croak("Filter::Include - invalid reference $_")
        ) ;
        
        next
          unless defined $ret;

        croak("Filter::Handle - invalid [EMAIL PROTECTED] subroutine return $ret")
          unless _isfh($ret);

        return $ret;
      }
      
      $lib = $_ and last
        if -f catfile($_, $path);

    }
    
    croak("Filter::Include - Can't locate $path in [EMAIL PROTECTED]"
          . "([EMAIL PROTECTED] contains: @INC")                                       
                                                                    
      unless defined $lib;

    $INC{$path} = catfile $lib, $path;
  }

  sub _isfh {
    no strict 'refs';
    return !!( ref $_[0] and (
         ( ref $_[0] eq 'GLOB' and defined *{$_[0]}{IO} )
      or ( UNIVERSAL::isa($_[0] => 'IO::Handle')        )
      or ( UNIVERSAL::can($_[0] => 'getlines')          )
    ) );
  }

The only there thing that probably would need to be tweaked '_isfh()' which is just 
sufficient for my needs.

So that should solve any problems with coderefs in @INC.

Dan

Reply via email to