in reply to Re^16: How to completely destroy class attributes with Test::Most?
in thread How to completely destroy class attributes with Test::Most?
Ideally, the iterator should need no connection to its parent other than shared data, and I see no reason that File::Collector should be a singleton object, which means that it needs to be an instance variable if it is used at all.
We can avoid that by transferring more data into the newly-constructed iterator. I now see that your application attaches some additional attributes to each file, where I had previously supposed that you care only about the file name. The solution is simple: add a name key to each item in $collector->{files} and change selected_file to:
sub selected_file { (shift)->[0]->{name} }
(also change the return value of next)
When constructing an iterator, pass a list of the relevant entries in ->{files} (which are hashrefs, so the per-category lists should be aliases into the master file set) to new. This even allows another bit of AUTOLOAD magic to provide selected_file_KEY getters that read $self->[0]->{KEY} on an iterator. The explicit selected_file method is therefore an alias for selected_file_name with this approach.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^18: How to completely destroy class attributes with Test::Most?
by nysus (Parson) on Aug 29, 2019 at 23:22 UTC | |
by jcb (Parson) on Aug 29, 2019 at 23:45 UTC | |
by nysus (Parson) on Aug 30, 2019 at 15:11 UTC | |
by jcb (Parson) on Aug 30, 2019 at 23:59 UTC | |
by nysus (Parson) on Aug 30, 2019 at 05:11 UTC | |
by jcb (Parson) on Aug 30, 2019 at 23:54 UTC | |
by nysus (Parson) on Aug 31, 2019 at 06:49 UTC | |
|