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

In reply to TIoCC :: DRYing the code by princepawn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.