Cast %INC magic

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Greetings, colleagues!

I've got a need to 'use' autogenerated packages, <<'__AS_HERE__'
use strict;
use warnings;

sub make_package {
    my ($package) = @_;

    eval <<__EVAL__;
package $package;

sub import {
    print "$package\n";

    # make possible to say 'use <$package>'
    my $path = $package;
    s@::@/@g, tr@'@/@ for $path;
    $path .= '.pm';
    $INC = 'autogenerated with make_package';

BEGIN { make_package('My::Package'); }

use My::Package; # prints "My::Package"

The question is: is it OK to set %INC value to something different
from a filename? It is not forbidden, as one can learn from perlvar
(see '%INC') and perlfunc (see 'require'), but are there any strong
arguments against this magic? E. g. there may be some commonly used
modules, which presume, that all %INC values are filenames, are there?

And an extra question: if this magic is no crime, do you think a plain
message is quite enough? Perhaps, one should rather use a reference to
anything (e. g., a scalarref to the very message) in order not to
confuse it with a filename, what do you think? Are there any
conventions what to place in %INC in such cases?


Site Timeline