The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Hessian::Tiny::Client - Hessian Client implementation in pure Perl

VERSION

Version 1.00

SYNOPSIS

use Hessian::Tiny::Client;

my $foo = Hessian::Tiny::Client->new(
    url => 'http://hessian.service.com/serviceName',
    version => 2, # hessian protocol version
);
my($stat,$res) = $foo->call('add',2,4);
if($stat == 0){ # success
    print "2 + 4 = $res";
}else{
    print "error: $Hessian::Tiny::Client::ErrStr";
}
...

SUBROUTINES/METHODS

new

my $foo = Hessian::Tiny::Client->new(
    url => 'http://hessian.service.com/serviceName', # mandatory
    version => 2, # default is 1
    debug => 1,   # add some debugging output (to STDERR)
    auth => [$http_user,$http_pass], # http basic auth, if needed
    hessian_flag => 1, # if you need strong typing in return value
);

argument 'url' need to be a valid url, otherwise the constructor will return undef.

call

# for convinience, simple types can be passed directly
($stat,$res) = $foo->call('addInt',1,2);

# or use Hessian::Type::* for precise typing
($stat,$res) = $foo->call('method1',
    Hessian::Type::Date( Math::BigInt->new( $milli_sec ) ),
    Hessian::Type::Double( 3.14 ),
    Hessian::Type::List( length=>2,
                         data=>[
                                Hessian::Type::String->new('unicode_stream'),
                                Hessian::Type::Binary->new('bytes')
                         ] );
    Hessian::Type::Map( type=>'Car',
                        data=>{
                               'Make' => 'Toto',
                               'Modle' => 'XYZ'
                        } );
                                            
); # end call

if($stat == 0){
    # success

}elsif($stat == 1){
    # Hessian Fault
    print "Exception: $res->{code}, $res->{message}";
}else{
    # communication failure
    print "error: $res";
}

return value, $stat: 0 for success, 1 for Fault, 2 for communication errors;
$res will hold error (Hessian::Fault or string) in case of unsuccessful call;
$res will hold return value in case of successful call; normally Hessian types
are converted to perl data directly, if you want strong typing in return value,
you can set (hessian_flag => 1) in the constructor call new().

HESSIAN TYPE MAPPING

Null

$foo->call('argNull', Hessian::Type::Null->new() );
As return value, by default, you will get undef;
when 'hessian_flag' is set, you will get Hessian::Type::Null as return.

True

$foo->call('argTrue', Hessian::Type::True->new() );
As return value, by default, you will get 1;
when 'hessian_flag' is set, you will get Hessian::Type::True as return.

False

$foo->call('argFalse', Hessian::Type::False->new() );
As return value, by default, you will get undef;
when 'hessian_flag' is set, you will get Hessian::Type::False as return.

Integer

$foo->call('argInt', 250 );

No extra typing for Integer type.
Note, if the number passed in falls outside the range of signed 32-bit integer,
it will be passed as a Long type instead.

Long

$foo->call('argLong', Math::BigInt->new(100000) ); # normally you have this module already
$foo->call('argLong', Hessian::Type::Long->new('100000') ); # same as above

As return value, by default, you will get string representation of the number;
when 'hessian_flag' is set, you will get Math::BigInt as return.

Double

$foo->call('argDouble', 2.50 ); # pass directly, if looks like floating point number
$foo->call('argDouble', Hessian::Type::Double(2.50) ); # equivalent

As return value, by default, you will get the number directly;
when 'hessian_flag' is set, you will get Hessian::Type::Double as return.

Date

$foo->call('argDate', Hessian::Type::Date->new($milli_sec) );
$foo->call('argDate', DateTime->now() ); # if you have this module installed

As return value, by default, you will get epoch seconds;
when 'hessian_flag' is set, you will get Hessian::Type::Date as return.

Binary/String

$foo->call('argBinary', Hessian::Type::Binary->new("hello world\n") );
$foo->call('argString', Hessian::Type::String->new("hello world\n") );
$foo->call('argString', Unicode::String->new("hello world\n") );

As return value, by default, you will get the perl string;
when 'hessian_flag' is set, you will get Hessian::Type::Binary or
Hessian::Type::String object as return.

XML

$foo->call('argXML', Hessian::Type::XML->new( $xml_string ) );

As return value, by default, you will get xml string;
when 'hessian_flag' is set, you will get Hessian::Type::XML as return.
Note, XML type is removed from Hessian 2.0

List

$foo->call('argList', [1,2,3] ); # untyped fixed length list
$foo->call('argList', Hessian::Type::List->new([1,2,3]); # same as above
$foo->call('argList', Hessian::Type::List->new(length=>3,data=>[1,2,3],type=>'Triplet');

As return value, by default, you will get array_ref;
when 'hessian_flag' is set, you will get Hessian::Type::List as return.

Map

$foo->call('argMap', {a=>1,b=>2,c=>3} ); # untyped map
$foo->call('argMap', Hessian::Type::Map->new({a=>1,b=>2,c=>3} ); # same as above
$foo->call('argMap', Hessian::Type::Map->new(type=>'HashTable',data=>{a=>1,b=>2,c=>3} ); # typed

As return value, by default, you will get hash_ref;
when 'hessian_flag' is set, you will get Hessian::Type::Map as return.

Object

my $x = Hessian::Type::Object->new(
            type => 'my.package.LinkedList',
            data => {_value => 1, _rest => undef}
        );
my $y = Hessian::Type::Object->new(
            type => 'my.package.LinkedList',
            data => {_value => 2, _rest => $x}
        );
$foo->call('argObject',$y);

As return value, by default, you will get hash_ref;
when 'hessian_flag' is set, you will get Hessian::Type::Object as return.
Note, Object is essentially a typed Map.

AUTHOR

Ling Du, <ling.du at gmail.com>

BUGS

Please report any bugs or feature requests to bug-hessian-tiny-client at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hessian-Tiny-Client. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Hessian::Tiny::Client

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2010 Ling Du.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.