I've been writing a series of mini-articles for ABE.pm
explaining what cool new
features in 5.10 will benefit the mostly-non-hardcore
readership. Today I was
writing about assertions, which I hadn't used yet. Once I
worked out how they
worked (I hope to submit some doc patches when this thread
is done), I realized
that I didn't want to use them, because they don't work on
methods. Here's a
little test:
sub everything_is_fine : assertion {
my ($self) = _;
print "not ok 1 - you should never see this 'fine'
subn";
}
{
use assertions 'foo';
everything_is_fine;
}
Objekt->check;
package Objekt;
sub everything_is_ok : assertion {
my ($self) = _;
print "not ok 2 - you should never see this 'okay'
methodn";
}
sub check {
use assertions 'foo';
(shift)->everything_is_ok;
}
Without -A=foo, I expect no output, but I see "not ok
2". My assumption is
that assertions are optimized away based on bound-at-compile
routines, and
that's why methods are left out in the cold. On #p5p,
Rafael said:
< rgs> there's a different op for calling subs and
for calling methods
< rgs> so that could be solved probably by patching
Perl_ck_method in the
optree builder
< rgs> but then you'll have the same problem with
$obj->$method() (which
is yet another op)
This is beyond my ability to easily solve, but it seems like
it would be a
massive improvement. I'm much more likely to use assertions
if I can write
them as methods, even if this is a performance hit, because
of the improved
maintainability.
--
rjbs
|