On Sun, Dec 21, 2003 at 04:55:28AM -0000, PerlDiscuss - Perl Newsgroups and mailing lists wrote: : When the official release of Perl 6 is released and I start to write some : Perl 6 programs using Perl 5 modules, will I get any errors? How will this : be handled? Will all of the Perl 5 modules have to be ported over and : converted to Perl 6 code? Can I have a basic perl6.pl file while using the : standard perl 5 IO::Socket module or whatehaveyou?
Perl 5 code will presumably run under Ponie. The Ponie engine will cooperate with the Perl 6 engine to make cross-platform calls work as seamlessly as possible. From Perl 6's point of view, Perl 5 objects will be supported by delegation. (This may entail introduction of smart references that know how to be different kinds of objects in different contexts. We'll see...) From Perl 5's point of view, Perl 6 objects have only methods, not attributes. That's the story for intermixing whole Perl 5 and Perl 6 modules. However, Perl 6 will also itself provide support for the Perl 5 notion of blessing any data structure orthogonally, in addition to the new Perl 6 opaque objects. So it will be possible to translate Perl 5 modules to Perl 6 without totally abandoning the Perl 5 model. However, it's possible that Perl 6 may enforce a bit more encapsulation by embedding the supplied data structure into an opaque object of its own. So for hash objects, use of the Perl 5 hash notation would not in fact be accessing the blessed object directly, but would be calling in through accessor methods autogenerated from the keys of the hash. When $obj is an object reference, writing $obj{foo} outside the class is in essence a funny way to write $obj.foo(), which is a call into an accessor that knows that $self{foo} is really $self.__ANONHASH__{foo} or some such. That's a speculation on my part. But whether or not we put that level of indirection in, we will certainly be encouraging people to use the pure Perl 6 syntax instead. The Perl 5 syntax might someday be deprecated. It's really there to make the transition easier. The orthogonality of Perl 5's bless is still there in the Perl 6 syntax, but hopefully without the confusion between the inside view of the object and the outside. But maybe I'm hoping for too much--it's hard to imagine how this kind of bless could work in-place to (in effect) annotate a data structure with handler classes. (At least, not without using some kind of smart context-sensitive references, which seem to keep popping up here and there.) Unfortunately, Perl 5 objects have the advantages that go with their disadvantages, and one of those advantages is that you can use the same reference for both the object and the data structure inside the object, and so you can bless the data structure into an object without returning a new reference, which implies that multiple references to the same thing aren't suddenly invalidated by bless. If we auto-encapsulate the blessed hash, array, scalar, or routine into an opaque object, we lose that feature if we're not careful. A bless will have to be able to mutate the "thingie" from a data structure to an object in place, at least from the viewpoint of external references. The header describing the actual data structure may have to be copied to a different address to do that. Larry