develooper Front page | perl.perl5.porters | Postings from July 2001

Question about autoloaded constants

Thread Next
From:
Philip Newton
Date:
July 8, 2001 00:15
Subject:
Question about autoloaded constants
Message ID:
972gktkhhha0ptp4q161kmvifspkr8adp1@4ax.com
Hi, in I18N::Langinfo, I saw this bit of (presumably) autogenerated
code:

> +sub AUTOLOAD {
> +    # This AUTOLOAD is used to 'autoload' constants from the constant()
> +    # XS function.
> +
> +    my $constname;
> +    our $AUTOLOAD;
> +    ($constname = $AUTOLOAD) =~ s/.*:://;
> +    croak "&I18N::Langinfo::constant not defined" if $constname eq 'constant';
> +    my ($error, $val) = constant($constname);
> +    if ($error) { croak $error; }
> +    {
> +	no strict 'refs';
> +	# Fixed between 5.005_53 and 5.005_61
> +#XXX	if ($] >= 5.00561) {
> +#XXX	    *$AUTOLOAD = sub () { $val };
> +#XXX	}
> +#XXX	else {
> +	    *$AUTOLOAD = sub { $val };
> +#XXX	}
> +    }
> +    goto &$AUTOLOAD;
> +}

My question is: why are the 'XXX'ed lines so marked? Shouldn't constants
have a prototype of "()" rather than no prototype so that they can be
inlined? Especially since it appears that the bit with () should work
since it was "fixed between 5.005_53 and 5.005_61" -- and since you 'use
5.006;', you've definitely got $] > 5.005_61.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.

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