[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

RE: __DIE__ and exception hooks




Redford, John writes:
| There is also a much better option. Better is the sense of being a more
| general solution to a broader set of problems.
| 
| Make it possible for objects and other reference types to define their own
| string representations.
| 
| I don't really care how this is done, it should be obvious how useful and
| sorely lacking it is. One idea is as follows:
| 
| For non-blessed references, pick a few more Perl special-variables & let
| people store code-refs in them, and use them for conversion of simple
| references to strings. Perhaps just use one variable & force the author to
| figure out if a ref is SCALAR, HASH, or what.
| 
| For objects, define 'PRINT' as a special function which Perl calls to get a
| printable string representation of an object, and define (internally)
| PRINT_ADDR as a method of all objects to get the string that is returned
| presently.

Alternatively, we could consider some sort of general mechanism to
handle conversions such as to numeric, to string, etc., and also to
provide operator overloading.  It could work as a pragma, and drop in to 
the existingsystem without further ado.

I suggest as a syntax, something like:

use overload
  '""'	=> 'to_string';

where to_string could be a subr, or a string as above, which is to be
interpreted as a method.

It could even have a manpage --- something like 'man overload' ought to
do the trick.  But to help people find this, we should put a note in the 
perlop manpage, too.

Ilya, I think you're the man for this job.  Perhaps you could look into
it.

Mx.


References to:
"Redford, John" <John.Redford@fmr.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]