Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
Syntactic Confectionery Delight
 
PerlMonks  

Confused on function call syntax

by dd-b (Monk)
on May 14, 2013 at 04:51 UTC ( #1033404=perlquestion: print w/ replies, xml ) Need Help??
dd-b has asked for the wisdom of the Perl Monks concerning the following question:

I know a bunch of ways of calling perl functions, but this doesn't seem to be one of them. And it's kind of hard to power-search for the relevant entities, so far as I can tell.

my $map = match_maprow_by_hash $self( $first ); is the line of code that confuses me. match_maprow_by_hash is a local helper function -- it's in the .pm file of a moose class, but the code seems to expect to be called as a normal subroutine, not a class method (it doesn't treat its first parameter as class name or self reference).

This call does occur in an instance method, and $self is a reference to the instance. It's the $self($first) that confuses me; I don't know what treating the instance as a function means. $first is a lexical variable referencing a DBIx::Class::Core subclass representing a row in the database.

I've spent quite a while looking at general discussions of function calls and OO and Moose programming, and trying to find ways to search such generic terms (and symbols), but to no avail, so it's back to asking somebody who already knows. Is there a definitive discussion of ALL the ways to call subroutines around somewhere?

Comment on Confused on function call syntax
Select or Download Code
Re: Confused on function call syntax
by NetWallah (Monsignor) on May 14, 2013 at 05:18 UTC
    That code uses the non-preferred "indirect object" notation:
    methodname classname (params);
    where $self represents the classname, because it is blessed into that class.

    The identical process is better accomplished by re-writing that as:

    my $map = $self->match_maprow_by_hash ( $first );
    See "Method Call Variations" and '"indirect object" notation' in "perldoc perlobj".

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs

      Thank you! The more I studied it the more it appeared that was what was actually happening, but I couldn't find any documentation on that syntax, so I needed at least some reassurance; maybe this was a more complicated situation that just looked like method calls in simple cases, or something.
Re: Confused on function call syntax
by kcott (Abbot) on May 14, 2013 at 05:31 UTC

    G'day dd-b,

    That's an indirect subroutine call. You can use this incantation to see how Perl parses your statement:

    $ perl -MO=Deparse,-p -e 'my $map = match_maprow_by_hash $self( $first + );' (my $map = $self->match_maprow_by_hash($first)); -e syntax OK

    Compare that with these lines from perlref:

    $objref = new Doggie( Tail => 'short', Ears => 'long' ); $objref = Doggie->new(Tail => 'short', Ears => 'long');

    perlsub also has information about indirect calls.

    -- Ken

      Thank you! And seeing how careful all the reference docs are to deprecate it, I don't feel so bad for not remembering (or not knowing?) it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-04-18 08:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (464 votes), past polls