Based on our previous conversations, I will guess that you want to call every implementation of a method in the inheritance tree instead of only the most-specific?

There is probably a module on CPAN somewhere for this, and perhaps another monk will be able to cite it, but I do not know. I suggest trying: (untested)

sub _run_chain { my $s = shift; my $sub = shift; for my $r ( @{ $s->{_classes} } ) { $s->($r.'::'.$sub) if $s->can($r.'::'.$sub); } }

This will override the method search to directly call each method. Because Perl is a highly dynamic language, I have removed the no strict and expect that this will not contain a symref.

Your problem was not in this code at all — it was looking up $sub as a class method for each $r and then, finding that a sub by that name does indeed exist in that package, invoking it as a class method even though it is written as an instance method. You have been actually calling into File::Collector::Date::Classifie...::$sub and that is where the error is occurring. I think that running your code under the debugger would give you a nice backtrace showing the successful call and the unsuccessful dereference. (Simply run the script with perl -d and type c at the prompt to let the program run.)

And another comment on OO design: subclass relationships and the package hierarchy are independent in Perl. It might make more sense to have a File::Collector::Sorter::Date::ByMonth mixin class that groups files by month, or your sorting classes may all make more sense somewhere in your application's local package hierarchy.


In reply to Re: Unable to turn off strict refs by jcb
in thread Unable to turn off strict refs by nysus

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.