|Problems? Is your data what you think it is?|
Remove bless reference or class/package name from method argumentsby binf-jw (Monk)
|on May 20, 2009 at 10:04 UTC||Need Help??|
binf-jw has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a method which removes the first argument of @_ if it is the blessed reference to the package or the class name / package, thus allowing several call syntaxes to be used for static methods (Not requiring any instance variables). I've had a quick super search but couldn't find anything.
Method example: ( Classic pow example ):
I can quite happily call this method like so:
or exported ( With some code added to the module):
I thought it would be nice to call such method as any of the following:
To accomplish this I wrote a method which filters the arguments:
or the one line equivalent to use inline:
Which is called as follows.
The only draw back to my approach I can see is if the arguments contain the object reference which the method has been declared in at $_:
Calling this as:
would remove $num1 from @_
Is there any way to just check just the left argument of the infix dereference operator "->"?