On Tue, Jul 12, 2005 at 12:15:30PM +0000, Ingo Blechschmidt wrote:
> In Perl 5, %INC maps the partial path names of the modules   
> loaded to their absolute ones. What should the keys and values   
> of %*INC be in Perl 6?   

Conceptually, the Perl 5 %INC maps from what to which. It also imposes
a coupling with the filesystem which makes things like require $module
awkward. The hook mechanism in values breaks consistency, unless you
think of string values as shorthand for sub { slurp "path" }.

I propose to throw away the filesystem coupling, and map from a more
general name of the bit of code we are requiring to a more general
description of which instance of it we actually got. Once modules return
interesting values, it might be useful to keep a copy of that value
somewhere on the value side of %*INC: or else turn it inside out and
stipulate that a standard field in the Module object is where you got
this particular module. Probably, %*INC values should be weak references.

On the key side, I think we should allow more than just strings.
`use Bar` and `require Bar` invoke the module loader on a
ModuleName.new("Bar"). Passing a straight string performs this promotion
automatically. Path separators and '.pm' need never seen outside the
module loader. You can also ask to use/require a File or a URI, but
those requests are only honored if you have appropriate entries in the
module search path. In the case of URIs we could allow, for example,
only modules from a particular domain or even under a particular path.


%*INC = (
                             # weak references
    ModuleName.new("Bar") => Module.new(name    => "Bar",
                                        version => "0.0.7",
                                        author  => "BarCom",
                                        path    => "/usr/lib/perl6/Bar.pm",
                                        loaded_classes =>
                                             (::Bar, ::Bar::Internals),

    URI.new("http://codeIZus.com/perl/randommodule.cgi";) =>
                             Module.new(name    => "Acme::emcA", ...),

    $an_open_file         => ...

@*INC = ("/usr/local/lib/perl6",
         URI.new("http://";), # this would mean allow loading code from ANYWHERE.


Reply via email to