I would probably do this with my own attributes:
has custom_fields => ( traits => [qw( Hash )], isa => 'HashRef', builder => '_build_custom_fields', handles => { custom_field => 'accessor', has_custom_field => 'exists', custom_fields => 'keys', has_custom_fields => 'count', delete_custom_field => 'delete', }, ); sub _build_custom_fields { {} }
On an object, you should use it as follows:
my $val = $obj->custom_field('foo');
A common use case for such things is adding optional introspective data to exception and message classes.
phaylon
source share