Improvement to "Cool hack: annotating compatibility in test"

ChrisDolan on 2007-11-18T18:49:11

In my last journal entry, I described a trick using subroutine attributes to annotate the compatibility version of a test in a test suite. I discovered that my trick didn't work for subclasses. This is a correction to make it work in that scenario.

sub Introduced : ATTR(CODE) { my ($class, $symbol, $code_ref, $attr, $introduced_version) = @_; # Wrap the sub in a version test no warnings 'redefine'; *{$symbol} = sub { no strict 'refs'; local ${$class.'::TODO'} = $_[0]->_compatible($introduced_version); $code_ref->(@_); }; }