in reply to locating specific function calls

I'm not sure I understand what you want correctly. Let me restate your problem and propose a solution - I think this solution is not a good solution but I think it would solve the problem as I perceive it:

I think your problem is that you have a printf-like function __x() and want to make sure that wherever you have a call to it all template names in the string are present in the additional parameter list. This is complicated by the fact that people could use @additional_args, or by helper subroutines like __x_err, which is

sub __x_err { my $msg = shift; __x("$msg: {err}", err => $!, @_); };
, so a simple regular expression won't help too much.

I think one tedious solution would be to use Devel::Cover to map out all branches in your code that lead to a call of __x() and then to (manually) generate those parameter conditions that are missing from your test suite to make sure all those branches are actually reached.

I thought of writing a program that generates such conditions automatically, but so far I haven't felt the need - but maybe there is existing prior art. Hence my solution requires lots of manual work just to make sure your calling conventions are always followed. Using a regular expression to fish out all calls to __x() and then verifying that they all match a certain pattern might be saner, but there are always edge cases that might make this infeasible as well, unless you find that all your uses of __x() and __x_err() are simple uses (as they should maybe be, for a simple logging routine).

Now, did I understand your problem well enough to propose a (bad, tedious) solution or did I run off in the wrong direction alltogether? :)

Replies are listed 'Best First'.
Re^2: locating specific function calls
by markov (Scribe) on Apr 11, 2007 at 13:26 UTC

    My implementation will be a module, which does help people with internationalization. I can offer the automatic checks on call correctness, when the users refrain from the use of @additional_args and $msg, as in your example. So that's not really a no-go.

    What certainly is not possible, it to generate all conditions (automatically) to reach all corners of the code.

    I know that the first parameter of the function is a string, and that the other parameters are named. I only have to check wether the names are within the string. As second activity, for each of the strings I like to see that they are used: they must be translatable using gettext().

    Thanks for your ideas so far.