Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

$what->Does::This::mean( $anyway )

by maard (Pilgrim)
on Mar 15, 2012 at 06:17 UTC ( [id://959725]=perlquestion: print w/replies, xml ) Need Help??

maard has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, today i run into code which made me muse about diversity of this life.

$object->Some:Class::method(@args);

What does this mean and why would someone need to do such call?

Looks like this is the same as Some::Class::method($object, @args), but with respect to inheritance.

Another thing came to mind is $self->SUPER::new, which i always understood as "Call the new method of the superclass of $self's class". Is the SUPER some kind of magic (any relation to UNIVERSAL? e.g. each class in addition to isa and can has SUPER?)

Please point me to docs.

Replies are listed 'Best First'.
Re: $what->Does::This::mean( $anyway )
by tobyink (Canon) on Mar 15, 2012 at 08:40 UTC

    It's not quite the same as Some::Class::method($object, @args). If Some::Class::method does not exist, $object->Some::Class::method(@args) will walk Some::Class's superclasses (which may not be the same as $object's superclasses) trying to find method.

    SUPER is not especially similar to can and isa, in that SUPER is not a method name, it's a pseudo-class. (See also NEXT, which is another pseudo-class, available since Perl 5.8.)

    Things which are similar to can and isa are VERSION and DOES. (See UNIVERSAL.)

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: $what->Does::This::mean( $anyway )
by kcott (Archbishop) on Mar 15, 2012 at 07:10 UTC

    $what could be an object or a class - see below.

    SUPER is the superclass of the current package not the superclass of the object's class - see below also.

    Please point me to docs.

    -- Ken

Re: $what->Does::This::mean( $anyway )
by nemesdani (Friar) on Mar 15, 2012 at 06:43 UTC
    SUPER looks in the current package's @ISA for the respective method, invoking the first one found.
Re: $what->Does::This::mean( $anyway )
by trwww (Priest) on Mar 15, 2012 at 07:11 UTC

    I'm pretty sure its functionally equivalent to Some::Class::method($object, @args) as you mentioned.

    I've used this syntax to do mixins when I need a cheap/easy way to share code between two otherwise unrelated objects.

Re: $what->Does::This::mean( $anyway )
by Khen1950fx (Canon) on Mar 15, 2012 at 08:18 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://959725]
Approved by Old_Gray_Bear
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-04-23 14:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found