Hi,  
  
quoting an old post from Luke (http://xrl.us/ftet): 
> C<tie>ing is going to work quite differently, from what I hear.  
> So it might be possible to overload any function to call a  
> special version when your type of array is used.  You just have  
> to write all the special versions.  
  
So is the following valid?  
  class TiedArray is Array {  
    method push([EMAIL PROTECTED]) {  
      ...;  
    }  
  }  
  
  my TiedArray @array;  
  push @array:    ...; # calls our push  
  unshift @array: ...; # calls Array::unshift  
  # Will push @array, ... DWIM?  
  
How do I define the method/sub responsible for @array.[index]/  
%hash.{key}?  
  class TiedArray is Array {  
    # Possibility #1  
    method *postcircumfix:<'[', ']'>(TiedArray $self, $index) {  
      return new Proxy:  
        FETCH => {...},  
        STORE => {...};  
    }  
  
    # Possibility #2  
    multi sub *postcircumfix:<'[', ']'>(TiedArray $self, $index) {  
      # Body as above  
    }  
  
    # Possibility #3  
    method FETCH($index)       {...}  
    method STORE($index, $val) {...}  
  
    # Possibility #4  
    method GET($index) is rw {  
      # Body as in possibility #1  
    }  
  }  
  
FWIW, I like possibility #4 best.  
  
  
--Ingo  
  
--   
Linux, the choice of a GNU | self-reference, n. - See self-reference    
generation on a dual AMD   |   
Athlon!                    |   

Reply via email to