Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Calling multi functions in a single statement

by akagrawal3 (Beadle)
on Apr 19, 2012 at 12:46 UTC ( #965940=perlquestion: print w/ replies, xml ) Need Help??
akagrawal3 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks, I have a little difficulty in understanding one statement in which two functions called.
139 my $logviewer = CCI::LogViewer->new( 140 { request => $request, 141 start_timestamp => $start_date, 142 end_timestamp => $end_date, 143 filter_string => $filter, 144 lgp_object => 'shortMessage', 145 lgp_subtype => 'eventEndPoints', 146 limit => $limit, 147 sid => $request->get_args()->{'sid'}, 148 } 149 ); 150 $logviewer->get_log_records()->XML_file();
The statement my $logviewer = CCI::LogViewer->new( creates an object in user-defined package LogViewer.pm which is in CCI folder. This package has several functions of which get_log_records and XML_file are two of them. Now after the execution of first statement my $logviewer will be pointing to LogViewer.pm package. So will $logviewer->get_log_records()->XML_file(); just call both the functions or is there any other scenario I am failing to understand. Your help in this regard will be highly appreciated. Thanks

Comment on Calling multi functions in a single statement
Select or Download Code
Re: Calling multi functions in a single statement
by Eliya (Vicar) on Apr 19, 2012 at 12:54 UTC
    So will $logviewer->get_log_records()->XML_file(); just call both the functions

    The first method is being called on an object instance of type CCI::LogViewer, and once it has returned, the second method will be called on whatever object has been returned by the first method (could be an object of a different type (i.e. I haven't checked what it returns)).

      That sounds good. But from what you said I believe that there should be more than one XML_file subroutine so that once an object is returned by get_log_records() it could decide on which Package it should call XML_file(). Now if that is true, I found that the subroutine XML_file is only in one package and not in any other. So does that make any sense in executing  $logviewer->get_log_records()->XML_file(); . It could have rather just been written as
      $logviewer->get_log_records(); $logviewer->XML_file();
        Just because XML_file is in the same class as get_log_records doesn't mean the two statements are equivalent. Perhaps they are. But that depends on what get_log_records returns. And it only depends on what get_log_records returns.
Re: Calling multi functions in a single statement
by Anonymous Monk on Apr 19, 2012 at 12:58 UTC
Re: Calling multi functions in a single statement
by JavaFan (Canon) on Apr 19, 2012 at 13:04 UTC
    So will $logviewer->get_log_records()->XML_file(); just call both the functions or is there any other scenario I am failing to understand.
    Perl calls get_log_records on $logviewer, and it calls XML_file on whatever object is returned by get_log_records. This maybe the same object as $logviewer, but without inspecting what get_log_records does, is something that cannot be answered. It's very well possible methods in different classes are being called.
      Thanks for your response. Could you please take some effort in answering my query which I posted in

      http://perlmonks.org/?node_id=966076

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-08-29 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls