Can you post the new method and any other code involved in constructing a FileImporter? You should not need any explicit calls to DESTROY; perl destroys the object when the last reference goes out of scope and your $fi2 is a completely separate object — unless new is doing something funny...

...and the above is not the source of your problem. Your problem is the my $iterator on line 2, which makes get_next_file a closure. If it is supposed to be per-object, it needs to be an instance variable ($s->{_iterator}) instead of a lexical ($iterator). You would probably be better off getting rid of the closures entirely and just stashing a reference to @files in an instance variable ($s->{_file_queue}) and changing that whole block to: (obviously untested)

sub get_next_file { my $s = shift; if (!$s->{_selected_file}) { my @files = @_ ? @_ : $s->get_files; $s->{_file_queue} = \@files; } my $next_file = shift @{$s->{_file_queue}}; $s->{_selected_file} = $next_file; return $next_file; }

You might even be able to globally replace $s->{_selected_file} with $s->{_file_queue}[0] if eliminating an instance variable is helpful.

As for destroying the value of $iterator... how do you reach into another scope's lexicals? Some kind of XS magic, obviously, but what does the debugger use for this?


In reply to Re: How to completely destroy class attributes with Test::Most? by jcb
in thread How to completely destroy class attributes with Test::Most? 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.