So here's some revelations I'd like to share with you when I put this
problem to the Fun With Perl mailing list.
------ Forwarded message from <[EMAIL PROTECTED]> -----------
From: Rick Delaney <[EMAIL PROTECTED]>
To: Michael G Schwern <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Subject: Re: [FWP] Stumper
Michael G Schwern wrote:
>
> I'm stumped. I want to know how many times a certain function is
> called inside a lexical block without actually running that block of
> code. For example:
>
> foo {
> bar();
> bar();
> bar();
> };
I *think* this should work.
use B::Deparse;
sub foo (&) {
my $code = shift;
my $deparse = B::Deparse->new("-p");
scalar(() = $deparse->coderef2text($code) =~ /\bbar\(/g);
}
This would confuse random_package::bar with package_you_want::bar but
that shouldn't be too hard to take care of.
I can't think of any other ambiguities offhand that Deparse doesn't
already disambiguate.
------------ End forwarded message --------------------
Ok, that's great. But then Piers Cawley cried out "HALTING PROBLEM!"
from the front row (and get your feet off the stage).
------------ Forwarded message from <[EMAIL PROTECTED] ------------
From: Piers Cawley <[EMAIL PROTECTED]>
To: Michael G Schwern <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Subject: Re: [FWP] Stumper
Isn't this a halting problem issue?
foo { bar() if bar() && bar() };
How many times does bar get run?
------------- End forwarded message ----------------------
To which my reply is basically, "Oh crap."
To put it into something a bit more sensible:
skip {
foreach my $meth (qw(some meths to test)) {
ok( $obj->can($meth) );
}
}
There's no way you can know how many tests are in there. :( So I guess
skip and todo will have to take a number saying how many tests are in the
block.
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl6 Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
What is a super race? A super race is the race which I have just created, "the
Immortal Race".
--Alex Chiu, Immortality Guy