develooper Front page | perl.perl5.porters | Postings from May 2007

I want assertion methods!

Thread Next
Ricardo SIGNES
May 30, 2007 05:08
I want assertion methods!
Message ID:

I've been writing a series of mini-articles for 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' sub\n";

    use assertions 'foo';


  package Objekt;

  sub everything_is_ok : assertion {
    my ($self) = @_;

    print "not ok 2 - you should never see this 'okay' method\n";

  sub check {
    use assertions 'foo';

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


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About