Cast %INC magic

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) = [at] _;

eval <<__EVAL__;
package $package;

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

# make possible to say 'use <$package>'
my $path = $package;
s [at] :: [at] / [at] g, tr [at] ' [at] / [at] 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
ifomichev [ Mo, 07 Mai 2007 11:11 ] [ ID #1706654 ]
Perl » comp.lang.perl.modules » Cast %INC magic

Vorheriges Thema: [ANNOUNCE] Text-CSV_XS 0.25
Nächstes Thema: LWP and socket