Gernot,

i have the following package definition:
package Collection;
use overload '@{}' => \&op_deref_array;
:
:
i can not see the 'x' in my output. It seems that the overloading of the
@{} operator doesn't work in TT.

You are absolutely correct: it doesn't work.

I looked into doing a patch for this once, but I never had the time to actually follow through. Patching the Perl stash code seems relatively simple (although there were a few different ways to do it and I thought I'd probably have to do some profiling to see what gave the best performance), but then there's the issue of the XS stash code, which just plain scares me. <g>

What I did as a workaround will only work for getting around the overloaded hash dereferencing not working, and it's not without it's problems even then. For getting around the array dereferencing not working, AFAIK your only hope is to create some function that takes an int and returns that index out of your list. Then you can access that method directly in TT2. It's inelegant, but it would work.


                -- Buddy


PS--My solution for the hash deref problem, for those who care, is below. Its primary problem is that I can't have any hash key which exactly matches a method name. Of course, in TT2, that would have been a problem anyway. But now it's a problem in my Perl code as well. Thus far, it hasn't bitten me. <knocking on wood>

Suggestions for improvement, as always, welcome.

our $AUTOLOAD;
sub AUTOLOAD
{
    my ($method) = $AUTOLOAD =~ /::(\w+)$/;
    # for some reason DESTROY gets called via AUTOLOAD a lot; don't want _that_ 
one to blow up
    return if $method eq 'DESTROY';

    my ($this) = @_;
    debuggit("DataRow::AUTOLOAD: method $AUTOLOAD ($method) with", ref $this) if 
DEBUG >= 4;

    if (ref $this eq 'Geek::SQL::DataRow')
    {
        # not sure why we need to go directly into the hash with this, but the 
overload apparently doesn't work in AUTOLOAD
        return exists $$this->{hash}->{$method} ? $$this->{hash}->{$method} : 
croak("No such method (or column): $method");
    }
    else
    {
        croak("No such class method: $method");
    }
}

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to