Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Remove bless reference or class/package name from method arguments

by duelafn (Parson)
on May 20, 2009 at 10:29 UTC ( [id://765174]=note: print w/replies, xml ) Need Help??


in reply to Remove bless reference or class/package name from method arguments

For these particular examples, argument counting would be sufficient.

sub pow { shift if @_ > 2; return $_[0] ** $_[1]; }

If the number of arguments is unknown (e.g., sum), I do not know how (and do not believe that it is possible) to determine how the sub was invoked.

Good Day,
    Dean

  • Comment on Re: Remove bless reference or class/package name from method arguments
  • Download Code

Replies are listed 'Best First'.
Re^2: Remove bless reference or class/package name from method arguments
by ikegami (Patriarch) on May 20, 2009 at 14:48 UTC
    Or just
    sub pow { return $_[-2] ** $_[-1]; }

    Approaches that rely on the number of arguments rather than the type of arguments are going to be more resilient.

Re^2: Remove bless reference or class/package name from method arguments
by binf-jw (Monk) on May 20, 2009 at 10:38 UTC
    Thank you Dean,

    For most of the implementations I can use argument counting, infact I commonly pass multiple arguments as a HASH reference which kind of solves the problem. Variable size lists can even pass as an ARRAY reference:
    $obj->staticMethod( [ $arg1, $arg2, $arg3 ] );

    I was hoping there was some funky way of getting how it was invoked just for curiousity.

    John,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://765174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-24 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found