Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Question about __PACKAGE__

by ikegami (Patriarch)
on Jan 22, 2010 at 07:20 UTC ( [id://818906]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Question about __PACKAGE__
in thread Question about __PACKAGE__

My understaning is that Foo->hello & hello are basically the same except the former is calling class method and passing 'Foo' to hello as the first arg, but the later is calling a subroutine and will not pass 'Foo'. How do you think?

I think you understand, but your wording leaves to be desired. The same sub is called in both cases; the difference is in how it's called:

Foo->hello & hello are basically the same except the former is calling hello as a class method and passing 'Foo' (or whatever's left of the arrow) as the first arg, but the latter is calling hello as a subroutine and will not pass 'Foo'.

One difference that wasn't mentioned is that inheritance will come into play when hello is called as a method.

{ package Foo; sub hello { ... } } { package Bar; our @ISA = 'Foo'; } Foo->hello('world'); # Foo::hello('Foo', 'world') Bar->hello('world'); # Foo::hello('Bar', 'world') Foo::hello('world'); # Foo::hello('world') Bar::hello('world'); # hello not found in Bar

I think the purpose of these class method calls is to initialize some class variables

And maybe even create subs, yes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found