XML-RPC

 view release on metacpan or  search on metacpan

lib/XML/RPC.pm  view on Meta::CPAN

Returns the last XML that went in the client.

=head2 $xmlrpc->xml_out();

Returns the last XML that went out the client.

=head2 $xmlrpc->indent(indentsize);

Sets the xmlout indentation

=head1 CUSTOM TYPES

=head2 $xmlrpc->call( 'method_name', { data => sub { { 'base64' => encode_base64($data) } } } );

When passing a CODEREF to a value XML::RPC will simply use the returned hashref as a type => value pair.

=head1 TYPECASTING

Sometimes a value type might not be clear from the value alone, typecasting provides a way to "force" a value to a certain type

=head2 as_string

Forces a value to be cast as string.

    $xmlrpc->call( 'gimmeallyourmoney', { cardnumber => as_string( 12345 ) } );

=head2 as_int

Forces a value to be cast as int

=head2 as_i4

Forces a value to be cast as i4

=head2 as_double

Forces a value to be cast as double

=head2 as_boolean

Forces a value to be cast as boolean

=head2 as_base64

Forces a value to be cast as base64

=head2 as_dateTime_iso8601

Forces a value to be cast as ISO8601 Datetime


=head1 ERROR HANDLING

To provide an error response you can simply die() in the \&handler
function. Also you can set the $XML::RPC::faultCode variable to a (int) value
just before dieing.

=head1 PROXY SUPPORT

Default XML::RPC will try to use LWP::Useragent for requests,
you can set the environment variable: CGI_HTTP_PROXY to
set a proxy.

=head1 LIMITATIONS

XML::RPC will not create "bool", "dateTime.iso8601" or "base64" types
automatically. They will be parsed as "int" or "string". You can use the 
CODE ref to create these types.

=head1 AUTHOR

Original author: Niek Albers, http://www.daansystems.com/
Current author: Rene Schickbauer, https://cavac.at

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2007-2008 Niek Albers.  All rights reserved.  This program

Copyright (c) 2012-2022 Rene Schickbauer

This program is free software; you can redistribute it and/or modify it under the same
terms as Perl itself.
=cut

package XML::RPC;

use strict;
use XML::TreePP;
use MIME::Base64;
use Time::Local;
use vars qw($VERSION $faultCode);
no strict 'refs';

$VERSION   = 2.1;
$faultCode = 0;

sub new {
    my $package = shift;
    my $self    = {};
    bless $self, $package;
    $self->{url} = shift;
    $self->{tpp} = XML::TreePP->new(@_);
    $self->{laststatus} = '200';
    return $self;
}

sub indent {
  my $self = shift || return;
  $self->{tpp}->set( indent => shift );
}

sub credentials {
    my ($self, $username, $password) = @_;

    my $authtoken = 'Basic ' . encode_base64($username . ':' . $password, '');

    $self->{authtoken} = $authtoken;

    return;
}



( run in 0.512 second using v1.01-cache-2.11-cpan-71847e10f99 )