I'm sure I've recently seen a test that used something like this:

my $expect = {
   name => qr/porky/,
   value => sub { $_[0] >= 0 && $_[0] < 10 },
   spigot_state => 'active',
};

my $value = {
   name => 'My name is porky',
   value => 11,                              # <-- fails here
   spigot_state => 'active',
};

is_magically( $value, $expect, 'Whoopee!');

Where is_magically() tests a data structure against an 'active' data structure that can contain constant values, REs and code references. Everything compares literally unless it's a coderef or regexp - they are applied to the value under test.

Did I imagine it?

--
Andy Armstrong, hexten.net

Reply via email to