in reply to OO Perl and AUTOLOAD

In the code you provided, you never directly look in the %_attribute_properties. It appears that your accessor only knows the type of the thing being accessed, because you have set the value with the mutator. If you modify the accessor so that it checks if the attribute exists, and if not, find the type of the attribute from the %attribute_properties, then the proper type should be returned.

As a nitpick, why not return references to the array and hash attributes, then you dont need to play dereferencing games, let the caller, because they need to know the type already...unless of course you want to return deep copies.

Replies are listed 'Best First'.
Re^2: OO Perl and AUTOLOAD
by tucano (Scribe) on Apr 14, 2005 at 11:48 UTC
    The next chapter of the story:
    # locations _locations => [ ['????'] , 'read.write.noinit.array' + ], _refseqposition => [ { } , 'read.write.noinit.hash' + ], # licrinfo _licr_info => [ ['????'] , 'read.write.noinit.array' + ],
    And type handler
    # Added Type handler sub _check_type { my ($self,$attribute,$type) = @_; $_attribute_properties{$attribute}[1] =~ /$type/; }
    Now AUTOLOAD works good from the caller! THANKS TO ALL!