Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transforming hashref into SOAP::lite

Status
Not open for further replies.

Andyfives

Programmer
Feb 22, 2002
46
DK
Hi there,

I have very little perl experience and would really like some help!

Some background to my little problem first... We use perl template toolkit for our website and this consists of many preference files origanised into hash tables. We want to reference these hash tables and make changes to them probably using .net.

Quick question:- Is there an easy way of passing a perl hash and converting it to SOAP?

Thanks people
 
As you are already using TT2, you might find the easiest way is to use another template to produce the XML you need for SOAP.

In order to use TT2, you need to read all your configuration files into a big data structure, which I guess your code already does before invoking TT2. Then when you change the data, you will need to write it back to the appropriate config files - using another template perhaps?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Hi guys, thanks for your feeback.

brigmar:- I was introduced to the Serializer without any luck. :-(

Steve:- Yes, thats basically the idea. I can use plugins so can run through raw perl code if required.

My first assignment is to output the hash as soap xml in a simlilar way to how I am working with JSON. For JSON using the querystring I can pass the required hash reference..

USER.PREFS.CITY_DATA for example and it outputs:-


{"WEB_SERVER_ZULU_NORMAL":1,"COUNTRY_DATA":{"COUNTRIES":{"TT":{"code":"","AVS_type":"","name":"Trinidad & ....

Exactly what I needed for JSON.

Code:
package plugin::SterlingJSON;

use base qw( Template::Plugin );
use Template::Plugin;
use JSON; 
use lib::SkyObject;

use vars qw( @ISA );
@ISA		= qw( Template::Plugin lib::SkyObject );

sub getHash {

	# STILL TO DO need to pull in the XML from the template
	my $self			= shift;
	
	
	my %params			= (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
	
	my $myhash = $params{SkyHash};
	
	my $js = objToJson($myhash);
	
	return $js;


};

So yes obviously I can retreive the hash structure easy enough in the TT2 code and I am passing the hash into my plugin as a parameter.

What I am having trouble with is converting this hash in a similar way into SOAP using SOAP:Lite. I thought this would be just as easy as JSON, but reading through the documentation in perldoc/CPAN there just seems to be way too much!

Do you have any ideas on what I can and should use?
 
I am looking at building the SOAP body using either XML::simple or XML:Dumper...

I am getting results that are workable at least.

If anyone has a means of doing the same in SOAP:Lite please let me know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top