princepawn has asked for the wisdom of the Perl Monks concerning the following question:
but then in the constructor starting on line 156 we see this:for my $name (qw/ config components plugins methods hooks /) { my $method = "class_component_$name"; no strict 'refs'; *{__PACKAGE__."::$method"} = sub { shift->{"_$method"} }; }
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: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 then the constructor should have initialized these components like so:my @class_component = grep /^class_component_/ keys %$self ;
build_accessors(@class_component) unless $build_accessors++;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TIoCC :: DRYing the code
by jdporter (Paladin) on May 14, 2007 at 19:01 UTC | |
|
Re: TIoCC :: DRYing the code
by ysth (Canon) on May 14, 2007 at 19:18 UTC | |
|
Re: TIoCC :: DRYing the code
by Anonymous Monk on May 14, 2007 at 04:56 UTC |