in reply to use and BEGIN
He says that he read somewhere that if "use" is called twice on the same module, then the BEGIN blocks of that module are executed twiceNope, just the import sub is called. The actual file being included isn't even touched on the second use as its existence has already been noted in %INC so that further proves that the BEGIN blocks are not touched. If written in pure perl use would look something like this
Of course it's missing the code references in %INC implementation, and it's totally untested, but it should give you some idea of how use actually works.use File::Spec::Functions; sub use { my($pkg, @args) = @_; my(@dirs, $file) = split '::', $pkg; my $path = catfile @dirs, "$file.pm"; return if exists $INC{$path}; my $fullpath = catfile( (grep { -f cafile($_, $path) } @INC)[0], $path ); my $code = IO::File->new($fullpath) or die "$!"; $INC{$path} = $fullpath; eval $code->getlines; $file->import(@args); }
_________
broquaint
|
|---|