Cast %INC magic

Cast %INC magic

am 07.05.2007 11:11:23 von ifomichev

Greetings, colleagues!

I've got a need to 'use' autogenerated packages, <<'__AS_HERE__'
#!/usr/bin/perl
use strict;
use warnings;

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

eval <<__EVAL__;
package $package;

sub import {
print "$package\n";
}
__EVAL__

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

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

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

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?

Regards,
Ivan