in reply to How to use @INC coderef hooks

One possible use would be to interpose a PerlIO::via layer or other translation mechanism in reading module files. For instance, suppose we think we can save disk IO time by storing gzipped versions of our modules. A sub to read and unzip the file might be written like this (completely untested):

use Compress::Zlib qw/gzopen gzeof gzread gzclose gzerror/; unshift @INC, sub { my ($cref, $filename) = @_; $filename = "/path/to/compressed/libs/${filename}.gz"; return unless -f $filename; my $text; { my $gz = gzopen( $filename, 'rb') or warn $gz->gzerror() and return; while ( !$gz->gzeof() ) { my $buffer; my $bytes = $gz->gzread($buffer); warn $gz->gzerror() and return if $bytes == -1; $text .= $buffer; } $gz->gzclose(); } require 5.008; open my $fh, '<', \$text or return; $fh; }
I haven't seen an implemented PerlIO::via layer for gzip/gunzip, or I would have used it. That seems to be one that is talked about a lot, but CPAN does not appear to have it.

Other uses come to mind. The sub could check md5sum for the requested module, returning undefined for good ones and dieing for bad. A source filter could be waved over the module. Decryption could be done much like the gzip example.

It might be fun to generate modules on the fly with Template Toolkit.

After Compline,
Zaxo