List Info

Thread: I want assertion methods!




I want assertion methods!
user name
2007-05-30 07:06:50
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

Re: I want assertion methods!
user name
2007-05-30 07:40:51
On Wednesday 30 May 2007 14:06, Ricardo SIGNES wrote:
> 
> 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. 
>
I think this is one of the reasons people don't use
prototypes much, because 
they don't work on methods, either, unfortunately.  Let's
hope assertions 
_will_ work on methods.

-- 
Richard Foley
Ciao - shorter than aufwiedersehen

http://www.rfi.net/

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )