tags:

views:

92

answers:

2

I'm still trying to get a hang of Perl's OOP features. I'm confused about something, if I have a subroutine call like:

My::Package::sub_name($param1,$param2)

will this get "My::Package" sent as the first parameter? I'd tend to say no, but I'm not sure.

+8  A: 

Why don't you just try it?

Spoiler alert:

No, the first parameter will not be the package name.

However, when you do:

My::Package->sub_name( $param1, $param2 )

you will get the package/class name as the first parameter.

innaM
I had tried something like that, but I was thinking whether or not it was a general rule.
Geo
+10  A: 

(As Manni says) It's the -> operator that unshifts the invocant to @_ (where the invocant is either a blessed object, or a bare class name). :: in the function name is just used for namespace disambiguation and does not change @_.

Posted as an answer as per Geo's suggestion, although I don't want to be a rep whore :)

It's described more in the docs: perldoc perlboot, perldoc perltoot.

Ether
You deserve the rep :)
Geo
+1 Are you undercover?
Sinan Ünür
Hey I hit 3k, I felt like slowing down for a bit.. :)
Ether
Hmm. I was a bit surprised to be the only one answering that. However, I really expected a lengthy diatribe about indirect object notation upon revisiting this question.
innaM