Author: autrijus
Date: Sat Apr  1 20:46:57 2006
New Revision: 8533


* S13: specify type casting in the form of
    multi submethod *infix:<as>
  which usually only cares about the class of its second invocant.

Modified: doc/trunk/design/syn/S13.pod
--- doc/trunk/design/syn/S13.pod        (original)
+++ doc/trunk/design/syn/S13.pod        Sat Apr  1 20:46:57 2006
@@ -116,3 +116,17 @@
 this hash over a lexical scope, so you could have different policies
 on magical autogeneration.  The default mappings correspond to the
 standard fallback mappings of Perl 5 overloading.
+=head1 Type Casting
+A class can use the C<< *infix:<as> >> submethod to declare that its objects
+can be casted to some other class:
+    multi submethod *infix:<as> (IO)  { $*OUT }
+    multi submethod *infix:<as> (Int) { 1 }
+    multi submethod *infix:<as> (Str) { "Hello" }
+With the above declaration, C<$obj as "foo"> is equivalent to C<$obj as Str>,
+because the multi dispatch cares only about the class.

Reply via email to