2009
01.27

So I have been keeping up to date with the Perl6 Spec via the auto-mailer on svn commits. Usually, there are minor changes or feature changes that I don’t yet understand. Yesterday, I saw a commit that raised my eyebrows and I figured I’d share it here:

Modified: docs/Perl6/Spec/S02-bits.pod
===================================================================
— docs/Perl6/Spec/S02-bits.pod 2009-01-26 16:12:14 UTC (rev 25043)
+++ docs/Perl6/Spec/S02-bits.pod 2009-01-26 19:11:42 UTC (rev 25044)
@@ -12,9 +12,9 @@

Maintainer: Larry Wall
Date: 10 Aug 2004
- Last Modified: 8 Jan 2009
+ Last Modified: 26 Jan 2009
Number: 2
- Version: 148
+ Version: 149

This document summarizes Apocalypse 2, which covers small-scale
lexical items and typological issues. (These Synopses also contain
@@ -1413,7 +1413,12 @@
Like the C module in Perl 5, the C< .perl> method will put
quotes around strings, square brackets around list values, curlies around
hash values, constructors around objects, etc., so that Perl can evaluate
-the result back to the same object.
+the result back to the same object. The C< .perl> method will return
+a representation of the object on the assumption that, if the code is
+reparsed at some point, it will be used to regenerate the object as a
+scalar in item context. If you wish to interpolate the regenerated
+object in a list context, it may be necessary to use C< >>
+to force interpolation.

=item *

In case you didn’t catch that, calling .perl on any Perl6 object and catching the result in a scalar will give you something that can be used to reconstruct the object that it was called against. Here’s a neat scenario that I can imagine:


my Sub $internal = sub func { ... };
$internal.say;

my %complex;
%complex{'a'} = 'g';
%complex{'sub'} = $internal;
%complex.perl.say;

my $cached = %complex.perl;

#other stuff that causes a rollback

%restore = |$cached;

Now those are just silly off-the-top-of-my-head examples that I came up with. If you can write it out, you can read it in and reconstruct the %complex hash just the same. This is very similar to the Tie::Persistant and Storable‘s freeze/thaw functionality available to perl5.

Call me crazy, but the possibilities of having a freeze/thaw functionality built into every object strikes me as an amazing power that no other language provides. JBoss has formed a business trying to give that power to Java developers and it will be semi-trivial in Perl6.

No Comment.

Add Your Comment