Continuing my foray through
Class::Component, we see in the source code
(here for your reference)
we see on lines 12-17 this:
for my $name (qw/ config components plugins methods hooks /) {
my $method = "class_component_$name";
no strict 'refs';
*{__PACKAGE__."::$method"} = sub { shift->{"_$method"} };
}
but then in the constructor starting on line 156 we see this:
sub new {
my($class, $c, $args) = @_;
$args ||= {};
my $self = bless {
%{ $args },
_class_component_plugins => [],
_class_component_components => $default_components->{$c},
_class_component_methods => {},
_class_component_hooks => {},
_class_component_config => $args->{config} || {},
_class_component_default_plugins => $default_plugins->{$c},
}, $c;
$self->load_plugins(@{ $default_plugins->{$c} }, @{ $args->{load_p
+lugins} || [] });
$self;
}
And this is fine until you apply the DRY principle. Correct me if I'm wrong, but DRYer code would have applied a recognizer to the
hash of
$self like this:
my @class_component = grep /^class_component_/ keys %$self ;
and then the constructor should have initialized these components like so:
build_accessors(@class_component) unless $build_accessors++;
WHY?
We do not want to do things twice. Thus, we do not want to
list the things for access at the top and then build the accessors later.
Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality