473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

From variable to function?

Hello,

I am writing a small Perl program to atest the availbility of a webservice.

So the idea is to call a known method of a known webservice and check the result.

To make the program flexible and to allow me to test several webservices I pass te following params from the command line

SOAP-ping.pl [ -u url ] [ -p proxy ] [ -m method ]

eg: perl SOAP-Ping.pl -u http://www.soaplite.com/Demo -p http://services.soaplite.com/hibye.cgi -m hi()

I pick up the params using the use Getopt::Std;

and pass them to the SOAP::Lite object.

Passing the URL & proxy is not an issue but the method is causing me a headegde.

As I get the method as a variable (string) I can not pass it to SOAP::Lite as this requires it in a different form.
Expand|Select|Wrap|Line Numbers
  1. my $soap = SOAP::Lite
  2.            -> uri($url)                     
  3.            -> proxy($proxy);
  4.  
  5. # this ain't working           
  6. my $result = $soap->$method;
  7.  
  8. #The code that works is
  9. my $result = $soap->hi();
  10.  
How can I make this last line variable so I can pass the method via the command line instead of 'hard coded' in de code?

Here is the full version of my test program
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. http://guide.soaplite.com/#writing%20a%20client
  3. http://www.robertprice.co.uk/robblog...ith_Perl.shtml
  4. #  Usage: SOAP-ping.pl [ -u url ] [ -p proxy ] [ -m method ]
  5.  
  6. ####################################
  7. # Modules                          #
  8. ####################################
  9. use Getopt::Std;
  10. use Time::HiRes qw (time);
  11.  
  12. use SOAP::Lite;
  13.  
  14. ####################################
  15. # Globals                          #
  16. ####################################
  17.  
  18. ####################################
  19. # Get the parameters from the user #
  20. ####################################
  21. %options=();
  22. getopts("u:p:m:",\%options);
  23.  
  24. my $url    = defined($options{u}) ? $options{u} : "http://localhost/";
  25. my $proxy  = defined($options{p}) ? $options{p} : "http://localhost/";
  26. my $method = defined($options{m}) ? $options{m} : "";
  27.  
  28. ####################################
  29. # Test Connection                  #
  30. ####################################
  31.  
  32. printf("Url: %s\nProxy %s\nMethod: %s\n",$url, $proxy, $method);
  33.  
  34. # Calculate the time it takes
  35. my $start = time();
  36.  
  37. my $soap = SOAP::Lite
  38.            -> uri($url)                     
  39.            -> proxy($proxy);
  40.  
  41. my $result = $soap->hi();
  42.  
  43. unless ($result->fault)
  44. {
  45.     print $result->result(),"\n";
  46. }
  47. else
  48. {
  49.     print join ', ', 
  50.       $result->faultcode, 
  51.       $result->faultstring;
  52. }
  53.  
  54. my $soaptime = time() - $start;
  55.  
  56. printf("%d\n%d\n",$soaptime * 1000, $soaptime * 1000);
  57.  
To test it:

perl SOAP-Ping.pl -u http://www.soaplite.com/Demo -p http://services.soaplite.com/hibye.cgi -m hi()

Thx in advance for anyone helping me out here

Regards

Marc
Jan 23 '08 #1
2 1355
KevinADC
4,059 Expert 2GB
If will probably need to use a hash table that defines which method the variable passed in the command line should call:

Expand|Select|Wrap|Line Numbers
  1. my %coms = {
  2.     hi => \&hi;
  3.     foo => \&foo,
  4. }
  5.  
  6. my $result = $soap->$coms{$method}->();
so there is still some hard coding but you can pass in method names and the script will call the corresponding method. Or maybe someone knows of a different way to go about it.
Jan 23 '08 #2
KevinADC
4,059 Expert 2GB
Read the SOAP::Lite documentation, there might be an option in the new method that allows you to call method: call() I have never used SOAP::Lite so I have no experience with it's methods. My above suggextion should still wok if you wanted to go that route.
Jan 23 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
4
by: Ole | last post by:
hello, Little problem: struct operatable { char * operatable_id; int ( * delegate ) ( ... ); somedatatype data; };
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
15
by: tshad | last post by:
I was looking for a way to handle refreshes (user pressed refresh button) and found a piece of code to check if a Web page was refreshed but I can't get it to work. The code is:...
0
by: Holly | last post by:
I copied this code that works to connect into Unix. I am looking for a way to get it to work with a secure Unix box. Anyone have any insights on how to do this? I am trying to build an sftp...
3
by: User1013 | last post by:
I have the Javascript definitive guide book but I'm hoping someone can tell me what "language concepts" are being employed by the following code, so that I can look up the right parts in the book:...
116
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however,...
204
by: Masood | last post by:
I know that this topic may inflame the "C language Taleban", but is there any prospect of some of the neat features of C++ getting incorporated in C? No I am not talking out the OO stuff. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.