Perl6 Object Oriented Cookbook (v0.2.1)  
Section 6: Context and Transformation  
 
Recipe 6.3: Transforming Objects into Different Types
Last Updated: Sep 8, 2003
Status: Draft
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
5.00 Rating, 1 Vote  

How acceptable is the proposed solution?
  (Login to Vote)
0.00 Rating, 0 Votes  

Problem:  

You want to convert an object into a different type. For example, you want to turn a simple string into a URI object.

Solution:  

Use the transformation operators, from and as:

$uri = URI.new($my_string);     # uses the default constructor
$uri = URI from $my_string;     # uses the 'string' transformation
$uri = $my_string as URI;       # same thing

Discussion:


Log In to Comment


Login / Edit User Info -- Copyright © 2002 Cognitivity -- Previous Page   Next Page