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


In reply to Re: How to use @INC coderef hooks by Zaxo
in thread How to use @INC coderef hooks by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.