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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |