Subject: | supply attribute name to builder methods |
Sometimes several builder methods have a common behaviour (for example
fetching a default value from some config); so the same builder method
could serve for several attributes, it just needs to know which
attribute is being built. Therefore I suggest that builder methods
receive the attribute name as argument.
By the way, the same could apply to 'default'.
Example:
has 'aaa' => (is => 'ro', builder => '_from_config');
has 'bbb' => (is => 'ro', builder => '_from_config');
sub _from_config {
my ($self, $attribute_name) = @_;
my $config = ...;
return $config->{$attribute_name};
}