This file is indexed.

/usr/share/perl5/RPC/XML/Client.pm is in librpc-xml-perl 0.77-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
###############################################################################
#
# This file copyright (c) 2001-2011 Randy J. Ray, all rights reserved
#
# Copying and distribution are permitted under the terms of the Artistic
# License 2.0 (http://www.opensource.org/licenses/artistic-license-2.0.php) or
# the GNU LGPL (http://www.opensource.org/licenses/lgpl-2.1.php).
#
###############################################################################
#
#   Description:    This class implements an RPC::XML client, using LWP to
#                   manage the underlying communication protocols. It relies
#                   on the RPC::XML transaction core for data management.
#
#   Functions:      new
#                   send_request
#                   simple_request
#                   uri
#                   useragent
#                   request
#
#   Libraries:      LWP::UserAgent
#                   HTTP::Request
#                   URI
#                   RPC::XML
#
#   Global Consts:  $VERSION
#
###############################################################################

package RPC::XML::Client;

use 5.008008;
use strict;
use warnings;
use vars qw($VERSION $COMPRESSION_AVAILABLE);
use subs qw(new simple_request send_request uri useragent request
            fault_handler error_handler combined_handler timeout);

use LWP::UserAgent;
use HTTP::Request;
use URI;
use Scalar::Util 'blessed';
use File::Temp;
use IO::Handle;

use RPC::XML;
require RPC::XML::ParserFactory;

BEGIN
{
    # Check for compression support
    if (eval { require Compress::Zlib; 1; })
    {
        $COMPRESSION_AVAILABLE = ($@) ? q{} : 'deflate';
    }
    else
    {
        $COMPRESSION_AVAILABLE = q{};
    }
}

$VERSION = '1.40';
$VERSION = eval $VERSION; ## no critic (ProhibitStringyEval)

###############################################################################
#
#   Sub Name:       new
#
#   Description:    Create a LWP::UA instance and add some extra material
#                   specific to our purposes.
#
#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
#                   $class    in      scalar    Class to bless into
#                   $location in      scalar    URI path for requests to go to
#                   %attrs    in      hash      Extra info
#
#   Globals:        $VERSION
#
#   Returns:        Success:    object reference
#                   Failure:    error string
#
###############################################################################
sub new
{
    my ($class, $location, %attrs) = @_;

    $class = ref($class) || $class;
    if (! $location)
    {
        return "${class}::new: Missing location argument";
    }

    my ($self, $UA, $REQ);

    # Start by getting the LWP::UA object
    $UA = LWP::UserAgent->new(
        (exists $attrs{useragent}) ? @{$attrs{useragent}} : ()
    );
    $UA->agent(sprintf '%s/%s %s', $class, $VERSION, $UA->agent);
    $self->{__useragent} = $UA;
    delete $attrs{useragent};

    # Next get the request object for later use
    $REQ = HTTP::Request->new(POST => $location);
    $self->{__request} = $REQ;
    $REQ->header(Content_Type => 'text/xml');
    $REQ->protocol('HTTP/1.0');

    # Note compression support
    $self->{__compress} = $COMPRESSION_AVAILABLE;
    # It looks wasteful to keep using the hash key, but it makes it easier
    # to change the string in just one place (BEGIN block, above) if I have to.
    # Also (for now) I prefer to manipulate the private keys directly, before
    # blessing $self, rather than using accessors. This is just for performance
    # and I might change my mind later.
    if ($self->{__compress})
    {
        $REQ->header(Accept_Encoding => $self->{__compress});
    }
    $self->{__compress_thresh} = $attrs{compress_thresh} || 4096;
    $self->{__compress_re} = qr/$self->{__compress}/;
    # They can change this value with a method
    $self->{__compress_requests} = 0;
    delete $attrs{compress_thresh};

    # Parameters to control the point at which messages are shunted to temp
    # files due to size, and where to home the temp files. Start with a size
    # threshhold of 1Meg and no specific dir (which will fall-through to the
    # tmpdir() method of File::Spec).
    $self->{__message_file_thresh} = $attrs{message_file_thresh} || 1_048_576;
    $self->{__message_temp_dir}    = $attrs{message_temp_dir}    || q{};
    delete @attrs{qw(message_file_thresh message_temp_dir)};

    # Note and preserve any error or fault handlers. Check the combo-handler
    # first, as it is superceded by anything more specific.
    if (ref $attrs{combined_handler})
    {
        $self->{__error_cb} = $attrs{combined_handler};
        $self->{__fault_cb} = $attrs{combined_handler};
        delete $attrs{combined_handler};
    }
    if (ref $attrs{fault_handler})
    {
        $self->{__fault_cb} = $attrs{fault_handler};
        delete $attrs{fault_handler};
    }
    if (ref $attrs{error_handler})
    {
        $self->{__error_cb} = $attrs{error_handler};
        delete $attrs{error_handler};
    }

    # Get the RPC::XML::Parser instance from the ParserFactory
    $self->{__parser} =
        RPC::XML::ParserFactory->new($attrs{parser} ? @{$attrs{parser}} : ())
              or return "${class}::new: Unable to get RPC::XML::Parser object";
    delete $attrs{parser};

    # Now preserve any remaining attributes passed in
    for (keys %attrs)
    {
        $self->{$_} = $attrs{$_};
    }

    return bless $self, $class;
}

###############################################################################
#
#   Sub Name:       simple_request
#
#   Description:    Simplify the request process by both allowing for direct
#                   data on the incoming side, and for returning a native
#                   value rather than an object reference.
#
#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
#                   $self     in      ref       Class instance
#                   @args     in      list      Various args -- see comments
#
#   Globals:        $RPC::XML::ERROR
#
#   Returns:        Success:    value
#                   Failure:    undef, error in $RPC::XML::ERROR
#
###############################################################################
sub simple_request
{
    my ($self, @args) = @_;

    my $return;

    $RPC::XML::ERROR = q{};

    $return = $self->send_request(@args);
    if (! ref $return)
    {
        $RPC::XML::ERROR = ref($self) . "::simple_request: $return";
        return;
    }

    return $return->value;
}

###############################################################################
#
#   Sub Name:       send_request
#
#   Description:    Take a RPC::XML::request object, dispatch a request, and
#                   parse the response. The return value should be a
#                   RPC::XML::response object, or an error string.
#
#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
#                   $self     in      ref       Class instance
#                   $req      in      ref       RPC::XML::request object or
#                                                 remote method name
#                   @args     in      list      If $req is a method name, these
#                                                 are potential arguments for
#                                                 the remote call
#
#   Returns:        Success:    RPC::XML::response object instance
#                   Failure:    error string
#
###############################################################################
sub send_request ## no critic (ProhibitExcessComplexity)
{
    my ($self, $req, @args) = @_;

    my ($me, $message, $response, $reqclone, $content, $can_compress, $value,
        $do_compress, $req_fh, $tmpdir, $com_engine);

    $me = ref($self) . '::send_request';

    if (! $req)
    {
        return "$me: No request object or remote method name given";
    }
    elsif (! (blessed $req and $req->isa('RPC::XML::request')))
    {
        # Assume that $req is the name of the routine to be called
        if (! ($req = RPC::XML::request->new($req, @args)))
        {
            return "$me: Error creating RPC::XML::request object: " .
                $RPC::XML::ERROR;
        }
    }

    # Start by setting up the request-clone for using in this instance
    $reqclone = $self->request->clone;
    if (! $reqclone->header('Host')) {
        $reqclone->header(Host => URI->new($reqclone->uri)->host_port);
    }
    $can_compress = $self->compress; # Avoid making 4+ calls to the method
    if ($self->compress_requests and $can_compress and
        $req->length >= $self->compress_thresh)
    {
        # If this is a candidate for compression, set a flag and note it
        # in the Content-encoding header.
        $do_compress = 1;
        $reqclone->content_encoding($can_compress);
    }

    # Next step, determine our content's disposition. If it is above the
    # threshhold for a requested file cut-off, send it to a temp file and use
    # a closure on the request object to manage content.
    if ($self->message_file_thresh and
        $self->message_file_thresh <= $req->length)
    {
        require File::Spec;
        # Start by creating a temp-file
        $tmpdir = $self->message_temp_dir || File::Spec->tmpdir;
        # File::Temp->new() croaks on error, rather than just returning undef
        $req_fh = eval { File::Temp->new(UNLINK => 1, DIR => $tmpdir) };
        if (! $req_fh)
        {
            return "$me: Error opening tmpfile: $@";
        }
        binmode $req_fh;
        # Make it auto-flush
        $req_fh->autoflush();

        # Now that we have it, spool the request to it. This is a little
        # hairy, since we still have to allow for compression. And though the
        # request could theoretically be HUGE, in order to compress we have to
        # write it to a second temp-file first, so that we can compress it
        # into the primary handle.
        if ($do_compress && ($req->length >= $self->compress_thresh))
        {
            my $fh_compress = eval {
                File::Temp->new(UNLINK => 1, DIR => $tmpdir);
            };
            if (! $fh_compress)
            {
                return "$me: Error opening compression tmpfile: $@";
            }
            # Make it auto-flush
            $fh_compress->autoflush();

            # Write the request to the second FH
            $req->serialize($fh_compress);
            seek $fh_compress, 0, 0;

            # Spin up the compression engine
            $com_engine = Compress::Zlib::deflateInit();
            if (! $com_engine)
            {
                return "$me: Unable to initialize the Compress::Zlib engine";
            }

            # Spool from the second FH through the compression engine, into
            # the intended FH.
            my $buf = q{};
            my $out;
            while (read $fh_compress, $buf, 4096)
            {
                $out = $com_engine->deflate(\$buf);
                if (! defined $out)
                {
                    return "$me: Compression failure in deflate()";
                }
                print {$req_fh} $out;
            }
            # Make sure we have all that's left
            $out = $com_engine->flush;
            if (! defined $out)
            {
                return "$me: Compression flush failure in deflate()";
            }
            print {$req_fh} $out;

            # Close the secondary FH. Rewinding the primary is done later.
            if (! close $fh_compress)
            {
                return "$me: Error closing spool-file: $!";
            }
        }
        else
        {
            $req->serialize($req_fh);
        }
        seek $req_fh, 0, 0;

        $reqclone->content_length(-s $req_fh);
        $reqclone->content(sub {
                               my $b = q{};
                               if (! defined read $req_fh, $b, 4096)
                               {
                                   return;
                               }

                               return $b;
                           });
    }
    else
    {
        # Treat the content strictly in-memory
        utf8::downgrade($content = $req->as_string);
        if ($do_compress)
        {
            $content = Compress::Zlib::compress($content);
        }
        $reqclone->content($content);
        # Because $content has been force-downgraded, length() should work
        $reqclone->content_length(length $content);
    }

    # Content used to be handled as an in-memory string. Now, to avoid eating
    # up huge chunks due to potentially-massive messages (thanks Tellme), we
    # parse incrementally with the XML::Parser::ExpatNB class. What's more,
    # to use the callback-form of request(), we can't get just the headers
    # first. We have to check things like compression and such on the fly.
    my $compression;
    my $parser = $self->parser->parse(); # Gets the ExpatNB object
    my $cb = sub {
        my ($data_in, $resp) = @_;

        if (! defined $compression)
        {
            $compression =
                (($resp->content_encoding || q{}) =~
                 $self->compress_re) ? 1 : 0;
            if ($compression and (! $can_compress))
            {
                die "$me: Compressed content encoding not supported\n";
            }
            if ($compression)
            {
                if (! ($com_engine = Compress::Zlib::inflateInit()))
                {
                    die "$me: Unable to initialize de-compression engine\n";
                }
            }
        }

        if ($compression)
        {
            my $error;
            if (! (($data_in, $error) = $com_engine->inflate($data_in)))
            {
                die "$me: Error in inflate() expanding data: $error\n";
            }
        }

        $parser->parse_more($data_in);
        1;
    };

    $response = $self->useragent->request($reqclone, $cb);
    if ($message = $response->headers->header('X-Died'))
    {
        # One of the die's was triggered
        return ('CODE' eq ref $self->error_handler) ?
            $self->error_handler->($message) : $message;
    }
    if (! $response->is_success)
    {
        $message =  "$me: HTTP server error: " . $response->message;
        return ('CODE' eq ref $self->error_handler) ?
            $self->error_handler->($message) : $message;
    }

    # Whee. No errors from the callback or the server. Finalize the parsing
    # process.
    if (! eval { $value = $parser->parse_done(); 1; })
    {
        if ($@)
        {
            # One of the die's was triggered
            return ('CODE' eq ref $self->error_handler) ?
                $self->error_handler->($@) : $@;
        }
    }

    # Check if there is a callback to be invoked in the case of
    # errors or faults
    if (! ref $value)
    {
        $message =  "$me: parse-level error: $value";
        return ('CODE' eq ref $self->error_handler) ?
            $self->error_handler->($message) : $message;
    }
    elsif ($value->is_fault)
    {
        return ('CODE' eq ref $self->fault_handler) ?
            $self->fault_handler->($value->value) : $value->value;
    }

    return $value->value;
}

###############################################################################
#
#   Sub Name:       timeout
#
#   Description:    Get or set the timeout() setting on the underlying
#                   LWP::UserAgent object.
#
#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
#                   $self     in      ref       Object of this class
#                   $time     in      scalar    New timeout value, if passed
#
#   Returns:        Return value from LWP::UserAgent->timeout()
#
###############################################################################
sub timeout ## no critic (RequireArgUnpacking)
{
    my $self = shift;

    return $self->useragent->timeout(@_);
}

###############################################################################
#
#   Sub Name:       uri
#
#   Description:    Get or set the URI portion of the request
#
#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
#                   $self     in      ref       Object of this class
#                   $uri      in      scalar    New URI, if passed
#
#   Returns:        Current URI, undef if trying to set an invalid URI
#
###############################################################################
sub uri ## no critic (RequireArgUnpacking)
{
    my $self = shift;

    return $self->request->uri(@_);
}

###############################################################################
#
#   Sub Name:       credentials
#
#   Description:    Set basic-auth credentials on the underlying user-agent
#                   object
#
#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
#                   $self     in      ref       Object of this class
#                   $realm    in      scalar    Realm to authenticate for
#                   $user     in      scalar    User name to authenticate
#                   $pass     in      scalar    Password for $user
#
#   Returns:        $self
#
###############################################################################
sub credentials
{
    my ($self, $realm, $user, $pass) = @_;

    my $uri = URI->new($self->uri);
    $self->useragent->credentials($uri->host_port, $realm, $user, $pass);

    return $self;
}

# Immutable accessor methods
BEGIN
{
    no strict 'refs'; ## no critic (ProhibitNoStrict)

    for my $method (qw(useragent request compress_re compress parser))
    {
        *{$method} = sub { shift->{"__$method"} }
    }
}

# Fetch/set the compression threshhold
sub compress_thresh
{
    my $self = shift;
    my $value = shift || 0;

    my $old = $self->{__compress_thresh};
    if ($value)
    {
        $self->{__compress_thresh} = $value;
    }

    return $old;
}

# This doesn't actually *get* the original value, it only sets the value
sub compress_requests
{
    my ($self, $value) = @_;

    if (! $value)
    {
        return $self->{__compress_requests};
    }

    return $self->{__compress_requests} = $value ? 1 : 0;
}

# These are get/set accessors for the fault-handler, error-handler and the
# combined fault/error handler.
sub fault_handler
{
    my ($self, $newval) = @_;

    my $val = $self->{__fault_cb};
    if ($newval and ref $newval)
    {
        $self->{__fault_cb} = $newval;
    }
    # Special: an explicit undef is used to clear the callback
    if (@_ == 2 and (! defined $newval))
    {
        $self->{__fault_cb} = undef;
    }

    return $val;
}

sub error_handler
{
    my ($self, $newval) = @_;

    my $val = $self->{__error_cb};
    if ($newval and ref $newval)
    {
        $self->{__error_cb} = $newval;
    }
    # Special: an explicit undef is used to clear the callback
    if (@_ == 2 and (! defined $newval))
    {
        $self->{__error_cb} = undef;
    }

    return $val;
}

sub combined_handler
{
    my ($self, $newval) = @_;

    return ($self->fault_handler($newval), $self->error_handler($newval));
}

# Control whether, and at what point, messages are considered too large to
# handle in-memory.
sub message_file_thresh
{
    my ($self, $thresh) = @_;

    if (! $thresh)
    {
        return $self->{__message_file_thresh};
    }

    return $self->{__message_file_thresh} = $thresh;
}

sub message_temp_dir
{
    my ($self, $dir) = @_;

    if (! $dir)
    {
        return $self->{__message_temp_dir};
    }

    return $self->{__message_temp_dir} = $dir;
}

1;

__END__

=pod

=head1 NAME

RPC::XML::Client - An XML-RPC client class

=head1 SYNOPSIS

    require RPC::XML;
    require RPC::XML::Client;

    $cli = RPC::XML::Client->new('http://www.localhost.net/RPCSERV');
    $resp = $cli->send_request('system.listMethods');

    print ref $resp ? join(', ', @{$resp->value}) : "Error: $resp";

=head1 DESCRIPTION

This is an XML-RPC client built upon the B<RPC::XML> data classes, and using
B<LWP::UserAgent> and B<HTTP::Request> for the communication layer. This
client supports the full XML-RPC specification.

=head1 SUBROUTINES/METHODS

The following methods are available:

=over 4

=item new (URI [, ARGS])

Creates a new client object that will route its requests to the URL provided.
The constructor creates a B<HTTP::Request> object and a B<LWP::UserAgent>
object, which are stored on the client object. When requests are made, these
objects are ready to go, with the headers set appropriately. The return value
of this method is a reference to the new object. The C<URI> argument may be a
string or an object from the B<URI> class from CPAN.

Any additional arguments are treated as key-value pairs. Most are attached to
the object itself without change. The following are recognized by C<new> and
treated specially:

=over 4

=item parser

If this parameter is passed, the value following it is expected to be an array
reference. The contents of that array are passed to the B<new> method of the
B<RPC::XML::ParserFactory>-generated object that the client object caches for
its use. See the B<RPC::XML::ParserFactory> manual page for a list of
recognized parameters to the constructor.

=item useragent

This is similar to the C<parser> argument above, and also expects an array
reference to follow it. The contents are passed to the constructor of the
B<LWP::UserAgent> class when creating that component of the client object.
See the manual page for B<LWP::UserAgent> for supported values.

=item error_handler

If passed, the value must be a code reference that will be invoked when a
request results in a transport-level error. The closure will receive a
single argument, the text of the error message from the failed communication
attempt. It is expected to return a single value (assuming it returns at all).

=item fault_handler

If passed, the value must be a code reference. This one is invoked when a
request results in a fault response from the server. The closure will receive
a single argument, a B<RPC::XML::fault> instance that can be used to retrieve
the code and text-string of the fault. It is expected to return a single
value (if it returns at all).

=item combined_handler

If this parameter is specified, it too must have a code reference as a value.
It is installed as the handler for both faults and errors. Should either of
the other parameters be passed in addition to this one, they will take
precedence over this (more-specific wins out over less). As a combined
handler, the closure will get a string (non-reference) in cases of errors, and
an instance of B<RPC::XML::fault> in cases of faults. This allows the
developer to install a simple default handler, while later providing a more
specific one by means of the methods listed below.

=item message_file_thresh

If this key is passed, the value associated with it is assumed to be a
numerical limit to the size of in-memory messages. Any out-bound request that
would be larger than this when stringified is instead written to an anonynous
temporary file, and spooled from there instead. This is useful for cases in
which the request includes B<RPC::XML::base64> objects that are themselves
spooled from file-handles. This test is independent of compression, so even
if compression of a request would drop it below this threshhold, it will be
spooled anyway. The file itself is created via File::Temp with UNLINK=>1,
so once it is freed the disk space is immediately freed.

=item message_temp_dir

If a message is to be spooled to a temporary file, this key can define a
specific directory in which to open those files. If this is not given, then
the C<tmpdir> method from the B<File::Spec> package is used, instead.

=back

See the section on the effects of callbacks on return values, below.

=item uri ([URI])

Returns the B<URI> that the invoking object is set to communicate with for
requests. If a string or C<URI> class object is passed as an argument, then
the URI is set to the new value. In either case, the pre-existing value is
returned.

=item useragent

Returns the B<LWP::UserAgent> object instance stored on the client object.
It is not possible to assign a new such object, though direct access to it
should allow for any header modifications or other needed operations.

=item request

Returns the B<HTTP::Request> object. As with the above, it is not allowed to
assign a new object, but access to this value should allow for any needed
operations.

=item simple_request (ARGS)

This is a somewhat friendlier wrapper around the next routine (C<send_request>)
that returns Perl-level data rather than an object reference. The arguments may
be the same as one would pass to the B<RPC::XML::request> constructor, or there
may be a single request object as an argument. The return value will be a
native Perl value. If the return value is C<undef>, an error has occurred and
C<simple_request> has placed the error message in the global variable
C<B<$RPC::XML::ERROR>>.

=item send_request (ARGS)

Sends a request to the server and attempts to parse the returned data. The
argument may be an object of the B<RPC::XML::request> class, or it may be the
arguments to the constructor for the request class. The return value will be
either an error string or a data-type object. If the error encountered was a
run-time error within the RPC request itself, then the call will return a
C<RPC::XML::fault> value rather than an error string.

If the return value from C<send_request> is not a reference, then it can only
mean an error on the client-side (a local problem with the arguments and/or
syntax, or a transport problem). All data-type classes now support a method
called C<is_fault> that may be easily used to determine if the "successful"
return value is actually a C<RPC::XML::fault> without the need to use
C<UNIVERSAL::ISA>.

=item error_handler ([CODEREF])

=item fault_handler ([CODEREF])

=item combined_handler ([CODEREF])

These accessor methods get (and possibly set, if CODEREF is passed) the
specified callback/handler. The return value is always the current handler,
even when setting a new one (allowing for later restoration, if desired).

=item credentials (REALM, USERNAME, PASSWORD)

This sets the username and password for a given authentication realm at the
location associated with the current request URL. Needed if the RPC location
is protected by Basic Authentication. Note that changing the target URL of the
client object to a different (protected) location would require calling this
with new credentials for the new realm (even if the value of C<$realm> is
identical at both locations).

=item timeout ([INTEGER])

Get or set the current time-out value on the underlying B<LWP::UserAgent>
object that this object uses for sending requests. This is just a proxy
through to the method of the same name in the B<LWP::UserAgent> class. The
return value is the current time-out value (prior to change, if a new value
is given).

=item message_file_thresh

=item message_temp_dir

These methods may be used to retrieve or alter the values of the given keys
as defined earlier for the C<new> method.

=back

=head2 Support for Content Compression

The B<RPC::XML::Server> class supports compression of requests and responses
via the B<Compress::Zlib> module available from CPAN. Accordingly, this class
also supports compression. The methods used for communicating compression
support should be compatible with the server and client classes from the
B<XMLRPC::Lite> class that is a part of the B<SOAP::Lite> package (also
available from CPAN).

Compression support is enabled (or not) behind the scenes; if the Perl
installation has B<Compress::Zlib>, then B<RPC::XML::Client> can deal with
compressed responses. However, since outgoing messages are sent before a
client generally has the chance to see if a server supports compression, these
are not compressed by default.

=over 4

=item compress_requests(BOOL)

If a client is communicating with a server that is known to support compressed
messages, this method can be used to tell the client object to compress any
outgoing messages that are longer than the threshhold setting in bytes.

=item compress_thresh([MIN_LIMIT])

With no arguments, returns the current compression threshhold; messages
smaller than this number of bytes will not be compressed, regardless of the
above method setting. If a number is passed, this is set to the new
lower-limit. The default value is 4096 (4k).

=back

=head2 Callbacks and Return Values

If a callback is installed for errors or faults, it will be called before
either of C<send_request> or C<simple_request> return. If the callback calls
B<die> or otherwise interrupts execution, then there is no need to worry about
the effect on return values. Otherwise, the return value of the callback
becomes the return value of the original method (C<send_request> or
C<simple_request>). Thus, all callbacks are expected, if they return at all,
to return exactly one value. It is recommended that any callback return values
conform to the expected return values. That is, an error callback would
return a string, a fault callback would return the fault object.

=head1 DIAGNOSTICS

All methods return some type of reference on success, or an error string on
failure. Non-reference return values should always be interpreted as errors,
except in the case of C<simple_request>.

=head1 CAVEATS

This began as a reference implementation in which clarity of process and
readability of the code took precedence over general efficiency. It is now
being maintained as production code, but may still have parts that could be
written more efficiently.

=head1 BUGS

Please report any bugs or feature requests to
C<bug-rpc-xml at rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RPC-XML>. I will be
notified, and then you'll automatically be notified of progress on
your bug as I make changes.

=head1 SUPPORT

=over 4

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RPC-XML>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/RPC-XML>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/RPC-XML>

=item * Search CPAN

L<http://search.cpan.org/dist/RPC-XML>

=item * MetaCPAN

L<https://metacpan.org/release/RPC-XML>

=item * Source code on GitHub

L<http://github.com/rjray/rpc-xml>

=back

=head1 LICENSE AND COPYRIGHT

This file and the code within are copyright (c) 2011 by Randy J. Ray.

Copying and distribution are permitted under the terms of the Artistic
License 2.0 (L<http://www.opensource.org/licenses/artistic-license-2.0.php>) or
the GNU LGPL 2.1 (L<http://www.opensource.org/licenses/lgpl-2.1.php>).

=head1 CREDITS

The B<XML-RPC> standard is Copyright (c) 1998-2001, UserLand Software, Inc.
See <http://www.xmlrpc.com> for more information about the B<XML-RPC>
specification.

=head1 SEE ALSO

L<RPC::XML|RPC::XML>, L<RPC::XML::Server|RPC::XML::Server>

=head1 AUTHOR

Randy J. Ray C<< <rjray@blackperl.com> >>

=cut