A big issue that still remains with literals is the stringification of
objects and references.  In an effort to get the behaviors hammered
down, here are a few ideas:

First off, references:

By default, references should not stringify to anything "pretty", they
should stringifiy to something useful for debugging.  Heck, even perl5
style should be fine.  Not only is this handy, but also prevents
problems with circular referencing data structures, huge data
structures, etc.  However, all built-in types should have a .repr()
method, which should provide primitive Data::Dumper-ish output

So:

  $var = [1,2,3];
   print "$var";
   print "\n";
   print "$($var.repr)";

Might print something like:

[REF_TO_ARRAY_AT: '0x1245AB']
[
   '1',
   '2',
   '3'
]



Next, objects:

Objects should have an AS_STRING method inherited from UNIVERSAL
defined as follows:

method AS_STRING() {
   return "[CLASS_INSTANCE_OF: '" ~ $self.CLASS() ~ "']";
}

The AS_STRING method is implicitly called when an object is
interpolated within a string.  The AS_STRING method can be
overloaded within the class if the class's author wants nicer
(classier;) output.

so:

   class Normal {}

   class Special {
       method AS_STRING() {
           return qq['one','two',three']
       }
   }

   my Normal  $obj1;
   my Special $obj2;

   print $obj1;
   print "\n";
   print $obj2;

Should print:

[CLASS_INSTANCE_OF: 'Normal']
'one','two',three'

Reply via email to