Hello Bart,

well - your solution is of course very compact. I like it, really.
But on the other hand it is not very robust.

Just think of three files

### file t1.pm
package t1;

require "t2.pm";

1;

### file t2.pm
package t2;

require "t3.pm";

1;

### file t3.pm
package t3;

use Socket;

print "finally we're in package t3\n";

1;
### end

Drop t1.pm onto runtime builder and you get no output from
the preceding solutions.

You have to care for paths within the resulting %MyINC.
e.g.:

AutoLoader.pm => Festplatte:Projekte:MacPerl5.6.1b1:lib:AutoLoader.pm
Festplatte:Projekte:MacPerl5.6.1b1:lib:auto:DynaLoader:dl_findfile.al => 
Festplatte:Projekte:MacPerl5.6.1b1:lib:auto:DynaLoader:dl_findfile.al


Just searching for /^\s*(use|require)\b.*;/ in every module
and eval it doesn't help in cases like

  use module qw( foo
     bar );
  
  # a comment about use of blah

  require "a-module.pm" if $value;
 
That's the reason for the effort I invested.
MacJPerl has additional requirements.

Then think of required modules which use their
own AutoLoader modules. Reality is quite complicated.

Keitarou wrote a nice module Mac::ResFork for clean
adding of ResForks. This is handy too.

Plus I want to finish this little project soon
even or because I fear the dimishing general interest
in MacPerl ...


Best regards,
Axel.



Um 0:33 Uhr +0100 02.11.2001, schrieb Bart Lateur:
>That's pretty much how I did it , too. However: my stuff is pretty
>compact. I wonder if you haven't worked much too hard.  ;-)
>
>Here's it all, the whole BEGIN block, replacing the one that was there.
>
>BEGIN {
>    exit unless @ARGV;
>
>    #suppress warnings about redefining subroutines
>    #by 'eval(use...)':
>    local $^W;
>   
>    print "Checking for imported modules...\n";
># START OF BART'S MODIFICATIONS
>    my @modules = $ARGV[0];
>    my %inc;
>    while(my $source = shift @modules) {
>        open FILE, $source or die "Couldn't open file $source: $!";
>        while (<FILE>) {
>            if(/^\s*(use|require)\b.*;/){
>                eval($_); #read the %INC
>            }
>        }
>        close FILE;
>        foreach my $path (values %INC) {
>            $inc{$path}++ or push @modules, $path;
>        }
>    }
># END OF BART'S MODIFICATIONS
>    %MyINC = %INC;
>    @dynaLoaderModules = @DynaLoader::dl_modules;
>}

Reply via email to