in reply to Language design: direct attribute access and postponed mutators (Perl Vs Python)

I am using the "magic tied object" approach with WARC record headers in a library I am building. I wanted the $fields object to look like a native data structure, complete with (limited to valid data) reference autovivification. Thanks to overload, stuff like push @{$record->fields->{WARC_Concurrent_To}}, $new_record->id; actually works, no matter how many concurrent records $record initially has, creating the WARC-Concurrent-To header if necessary. (The ->fields method returns an object that overloads hash dereference to return a tied hash upon demand and that tied hash's FETCH method returns another magic object that is always a tied array, but overloads string conversion to do an implicit ->[0] if there is only one value for that header. There is also a tied array interface to the fields object if you care about the order in which the fields appear.)

I am also generally using accessor methods that perform "get" normally and "set" if given a new value where that makes sense; many objects are effectively read-only since they represent data in an archive file. I have no idea how old this pattern is; I have seen it both in other Perl code and in C++. I am not using Moose or anything like it, only baseline Perl 5 "blessed reference" objects.

The class that provides that fields object ended up being about 1/3 simple API, internals, and POD, and about 2/3 implementation for all the magic it does to make those "easy" interfaces work. It also has the most complex and longest test script (by about a factor of 3) so far. It was the first piece I wrote... and I am not making any more classes that magical in that library.