Overriding qx//
Nik Clayton
nik at ngo.org.uk
Thu Apr 13 10:03:32 BST 2006
I've just discovered that I've reimplemented something very similar to
Richard Clamp's Devel::System module (see slides 21-25 of
http://miltonkeynes.pm.org/talks/2006/03/nik_clayton_testing_legacy_code.pdf).
But it looks like both our efforts have the same problem. Namely, they
don't deal with code run through qx// or backticks.
system('echo foo');
is caught,
print `echo foo`;
isn't.
I thought I might be able to use overload::constant to do this, so I
whipped up this test code:
package System;
use overload;
my %handler = (q => sub { print STDERR join(':', @_), "\n";
return $_[1]; } );
sub import {
overload::constant %handler;
}
1;
Unfortunately, for the aforementioned
print `echo foo`;
it gives this on STDERR:
echo foo:echo foo:qq
So, no indication that the quoted string is being used in an execution
context. This matches what the docs say.
Anyone got any insights as to how this might be achieved (short of
grubbing around with XS)?
N
More information about the london.pm
mailing list