in reply to Re^20: How to completely destroy class attributes with Test::Most?
in thread How to completely destroy class attributes with Test::Most?

For a general-purpose File::Collector, I would expect support for multiple iterators even over the same category. ...

And it just dawned on me: since Iterators are now circular (and presumably the empty string is not a valid file name, although it could be replaced with undef if someone tries this on a platform where it is valid and complains), all you need to support independent iterators for applications that want them is a ->clone method on iterators:

sub clone { my $self = shift; bless [@$self], ref $self; }

And you have made a change that is going to bite your users with infinite loops: the AUTOLOAD for ::Iterator::All should advance the iterator itself: $$self->$method(@_) while ($$self->next); or $$self->method(@) while (defined $$self->next); if you choose to make the end-of-set marker undef instead of an empty string. The method called by invoking ->do should not advance the iterator itself, but only use $self->selected_file.

Replies are listed 'Best First'.
Re^22: How to completely destroy class attributes with Test::Most?
by nysus (Parson) on Aug 31, 2019 at 06:49 UTC

    A problem with $$self->$method(@_) while ($$self->next); is that the first value gets thrown away. My change was a workaround to that until I figure out something better.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      The solution for that in Perl is just like C: do { $$self->$method(@_) } while ($$self->next);

        The module is getting mature. I'm about halfway through writing up documentation for it.

        I modified the Processor class so that it contains references back the files in the Collector class using some attributes. I also created a new File::Collector::Base which contains methods that can be used by both File::Collector and File::Collector::Processor.

        Here is link to the GitHub repo.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

        Ah, yes. Of course. Thanks.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks