Click here to get back home

Cast %INC magic

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Cast %INC magic ifomichev 05-07-2007
Posted by ifomichev on May 7, 2007, 5:11 am
Please log in for more thread options


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 = '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


Similar ThreadsPosted
Image magic problem Use of uninitialized value in numeric gt (>) March 20, 2006, 7:12 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap