This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

Extend AUTOLOAD functionality to AUTOGLOB

=head1 VERSION

  Maintainer: David Cantrell <[EMAIL PROTECTED]>
  Date: 26 Sept 2000
  Mailing List: [EMAIL PROTECTED]
  Number: 324
  Version: 1
  Status: Developing
  Co-maintainer: David H. Adler <[EMAIL PROTECTED]>

=head1 ABSTRACT

The functionality of the existing AUTOLOAD should be available for all
datatypes.

=head1 DESCRIPTION

Whilst the current AUTOLOAD is very useful, we do not feel that it goes
far enough.  It only works for subroutines.  We believe this sort of
functionality should be available for anything in the symbol table.  A
sensible name would be AUTOGLOB.

For example: one current use for AUTOLOAD is in the Sub::Approx module.
It is not, however, possible to write Scalar::Approx, Hash::Approx,
Array::Approx, or Filehandle::Approx.  This would allow for catching
common errors such as mis-typing of class fields as well as mis-typing
of class methods.

=head1 IMPLEMENTATION

In the interests of backward compatibility, the existing AUTOLOAD should
be a synonym for AUTOGLOB and only used in the context of an AUTOsub.
It's use should be deprecated and should generate a suitable warning
under -w.

The AUTOGLOB subroutine should expect to take two parameters, the invocant,
and a second parameter specifying what type of item is being AUTOGLOBbed,
followed by - in the case of a sub - the sub's arguments.  We suggest that
the second parameter should be a scalar value - 'scalar' for an AUTOGLOBbed
scalar, 'array' for an AUTOGLOBbed array, and so on.  The $AUTOLOAD
variable should be renamed to $AUTOGLOB (with $AUTOLOAD as a deprecated
synonym as above).

If AUTOGLOB is called as AUTOLOAD, the second parameter should magically
disappear.

For AUTOthings other than subs, we suggest that the AUTOGLOB subroutine
should return a reference to a variable of the appropriate type.  That
will then be dereferenced and used as normal in the calling code.  If it
returns anything other than a reference this should be a fatal error.  In
the case of an AUTOGLOBbed sub, it should return values just like AUTOLOAD
does now.

As AUTOGLOBbing is expected to be a relatively expensive and dangerous
operation, it should be off by default (with the exception of subs), and
should be turned on and off via a new autoglob pragma:

C<use autoglob;                      # turn on all AUTOGLOBbing>

C<use autoglob qw(scalar hash);      # turn it on for scalars and hashes>

C<no autoglob qw(filehandle scalar); # turn it off for ...>

=head1 MIGRATION FROM PERL 5

The second parameter to AUTOGLOB will be removed if it is called as
AUTOLOAD, so no changes are needed in perl code.  However, in a later
release of perl 6 (6.1 and 6.2 perhaps) AUTOLOAD should be removed.
By this time, however, people will have heeded the warnings produced
by -w and migrated their code.

=head1 REFERENCES

None.

Reply via email to