> >However, it also seems that this is getting *really* complicated really
   > >quickly.
   > 
   > I'd agree. I was picturing the file the parser used reading something like:
   > 
   >    socket|Socket|1.0|gt

I think this is the way to go. I'd suggest that the syntax be easier for
humans (or at least JAPHs ;-) to intepret, and that the condition be
fully generalizable. Something like:

        autouse Socket::socket          { $Socket::VERSION >= 1.0 }
        autouse Text::Reform::format    { 1 }
        autouse Power::socket           { $ENV{WIRED} }

Note that under RFC 128, C<autouse> could actually be a vanilla
Perl subroutine defined by the parser:

        my %autousage;
        sub autouse (""qualified_name, &condition) {
                my ($package, $name) = $qualified_name =~ m/(.*)::(.*)/;
                push @{$autousage{$name}},
                        { package => $package, condition => $condition };
        }

Then the parser could just <do> the file to load its autoloading information.

And when it comes time to resolve unknown subroutine calls, it takes the
first candidate for the name whose condition is satisfied:

        UNKNOWN: foreach $sub ( @unknowns ) {
                foreach $possibility ( @{$autousage{$sub}} } {
                        resolve($sub, $possibility->{package}) and next UNKNOWN
                                if $possibility->{check}->();
                }
                push @unresolved, $sub;
        }

Or else it checks all the candidates and resolves only if there is exactly one
whose condition is satisfied, generating an "Ambiguous subroutine..." error 
if more than one condition is fulfilled.

Damian

Reply via email to