As you wrote it, it's an array of hashes of hashes. Actually it would make more sense to write it as an array of arrays of hashes to be clear about the ordering, otherwise you'd have to sort the keys when retrieving them and the sort order is sometimes not very intuitive---e.g. does "step10" come before or after "step1", or do you have to number the steps starting with "step01" then? The same goes for the parameter lists (and they're so much easier to both write and use if they're arrays already), so I'd make it something like this:
use strict;
use warnings;
use 5.010;
my @tests = (
[ # first testcase
{ # first step
command => 'Launchapplication',
params => [ qw/ executablepath dirpath / ],
},
{ # second step
command => 'SelectMenu',
},
# ...
],
[ # second testcase
{ # first step
command => 'Launchapplication',
params => [ qw/ executablepath dirpath / ],
},
{ # second step
command => 'Dothis',
},
# ...
]
);
my $package = "My::Package";
CASE: for my $ncase (0 .. $#tests) {
my $case = $tests[$ncase];
foreach my $nstep (0 .. $#$case) {
my $step = $case->[$nstep];
if(defined $step->{command}) {
my $ok = 1;
try {
no strict 'refs';
"${package}::$step->{command}"->(@{ $step->{params} //
+ [] });
} catch {
warn sprintf("FAILURE test %d step %d failed, aborting
+", $ncase+1, $nstep+1);
$ok = 0; # can't use "last" here due to try/catch limi
+tation
};
last CASE unless $ok;
} else
{
warn sprintf("BUG: `command' undefined in test %d step %d"
+, $ncase+1, $nstep+1);
last CASE;
}
}
}
Edit: oops, Riales beat me to it :)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.