=head scenarioNumberForTableDrivenScenarios Maintains an internal scenario counter for scenarios which iterate over an ARRAY of example data. @PARAM1, String. The operation to perform, 'increment', to increment the scenario counter and return the new scenario number. 'getdata', to get the given HASH of example values. anything else, get the scenario number. =cut sub scenarioNumberForTableDrivenScenarios { my ($C, $operation) = @_; my $scenarioLineNumber = $C->{scenario}->{line}->{number}; #Scenarios line number is a good tell between various scenarios. my $scenario = $C->{stash}->{feature}->{$scenarioLineNumber}; unless (exists $scenario->{currentScenarioRepetition}) { $scenario->{currentScenarioRepetition} = 0; $C->{stash}->{feature}->{$scenarioLineNumber} = $scenario; return $scenario->{currentScenarioRepetition} if ($operation eq 'increment'); #Prevent extra incrementations } if ($operation eq 'increment') { $scenario->{currentScenarioRepetition}++; #keep track of which scenario iteration we are currently at } elsif ($operation eq 'getdata') { #Clone the data HASH, so we don't alter its contents. This might cause some awkward print notifications with pherkin. my %data = %{$C->{scenario}->{data}->[ $scenario->{currentScenarioRepetition}-1 ]}; return \%data; } return $scenario->{currentScenarioRepetition}; #Get the scenario iterations count. }