in reply to Re: Controlling the start and endings of method calls
in thread Controlling the start and endings of method calls

sub _has_params { return @_ > 1 ? scalar(@_) - 1 : 0; }

How 'bout

sub _has_params { @_ - 1 }

?

It would also check if it is called as a sub with no arguments... oh, well, and it wouldn't catch a call like a sub with exactly one argument...

Replies are listed 'Best First'.
Re^3: Controlling the start and endings of method calls
by davido (Cardinal) on Feb 02, 2006 at 16:34 UTC

    But then if the 'method' was invoked as a sub from within the class it could potentially have no params, leading to a return value of -1, which would give a false positive.


    Dave

      Indeed. Just to make sure: I was more brainstorming than stating claims! However this directly leads us to discuss whether it is generally (i.e. with the exclusion of possible corner cases) a good practice to call a method like a sub even from within the same class, which at first sight IMHO is not by any means, but that would bring us too far away and in this moment I'm far too tired to even try to think of it...