Perl6 Object Oriented Cookbook (v0.2.1)  
Section 2: Attributes and Methods  
 
Recipe 2.13: Calling Methods Indirectly
Last Updated: Sep 8, 2003
Status: Draft
      Previous Page   Next Page

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

How acceptable is the proposed solution?
  (Login to Vote)
5.00 Rating, 2 Votes  

Problem:  

You want to call a method of an object or class, but the name of the method won't be known until runtime.

Solution:  

Use indirect syntax, possibly with a check to CAN to be safe:

my $method = "foo";
$obj.$method if $obj.CAN.$method;

MyClass.$method if MyClass.CAN.$method;

Discussion:

Issue: Any problems with $obj.$foo.$bar?


Log In to Comment


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