develooper Front page | perl.perl6.language | Postings from February 2001

Re: Really auto autoloaded modules

Thread Previous | Thread Next
From:
Damian Conway
Date:
February 2, 2001 15:04
Subject:
Re: Really auto autoloaded modules
Message ID:
200102022304.KAA20652@indy05.csse.monash.edu.au

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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About