/
Procedure.pm
1225 lines (1004 loc) · 40.3 KB
/
Procedure.pm
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
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###############################################################################
#
# 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 abstracts out all the procedure-related
# operations from the RPC::XML::Server class. It also
# provides the RPC::XML::Method and RPC::XML::Function
# namespaces.
#
# Functions: new
# name \
# code \
# signature \ These are the accessor functions for the
# help / data in the object, though it's visible.
# version /
# hidden /
# clone
# add_signature
# delete_signature
# make_sig_table
# match_signature
# reload
# load_xpl_file
# call
#
# Libraries: XML::Parser (used only on demand in load_xpl_file)
# File::Spec
#
# Global Consts: $VERSION
#
# Environment: None.
#
###############################################################################
# Perl::Critic:
#
# We use explicit @ISA in RPC::XML::Method and RPC::XML::Function because it
# is faster than doing 'use base' when we're already in the same file.
## no critic (ProhibitExplicitISA)
package RPC::XML::Procedure;
use 5.008008;
use strict;
use warnings;
use vars qw($VERSION);
use subs qw(
new name code signature help version hidden add_signature
delete_signature make_sig_table match_signature reload load_xpl_file
);
use File::Spec;
use Scalar::Util 'blessed';
use RPC::XML 'smart_encode';
# This module also provides RPC::XML::Method
## no critic (ProhibitMultiplePackages)
$VERSION = '1.27';
$VERSION = eval $VERSION; ## no critic (ProhibitStringyEval)
###############################################################################
#
# Sub Name: new
#
# Description: Create a new object of this class, storing the info on
# regular keys (no obfuscation used here).
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $class in scalar Class to bless into
# @argz in variable Disposition is variable; see
# below
#
# Returns: Success: object ref
# Failure: error string
#
###############################################################################
sub new
{
my ($class , @argz) = @_;
my $data; # This will be a hashref that eventually gets blessed
if (ref $class)
{
return __PACKAGE__ . '::new: Must be called as a static method';
}
# There are three things that @argz could be:
if (ref $argz[0])
{
# 1. A hashref containing all the relevant keys
$data = {
namespace => q{},
version => 0,
hidden => 0,
help => q{},
signature => [],
};
for (keys %{$argz[0]}) { $data->{$_} = $argz[0]->{$_} }
}
elsif (@argz == 1)
{
# 2. Exactly one non-ref element, a file to load
# Loading code from an XPL file, it can actually be of a type other
# than how this constructor was called. So what we are going to do is
# this: If $class is RPC::XML::Procedure, act like a factory method
# and return whatever the file claims to be. Otherwise, the file has
# to match $class or it's an error.
($data, my $pkg) = load_xpl_file($argz[0]);
if (! ref $data)
{
# load_xpl_path signalled an error
return $data;
}
if ($class ne 'RPC::XML::Procedure' && $pkg ne $class)
{
return "${class}::new: File loaded ($argz[0]) must match " .
'this calling class';
}
$class = $pkg;
}
else
{
# 3. If there is more than one arg, it's a sort-of-hash. That is, the
# key 'signature' is allowed to repeat.
my ($key, $val);
$data = {
namespace => q{},
version => 0,
hidden => 0,
help => q{},
signature => [],
};
while (@argz)
{
($key, $val) = splice @argz, 0, 2;
if ($key eq 'signature')
{
# Since there may be more than one signature, we allow it to
# repeat. Of course, that's also why we can't just take @argz
# directly as a hash. *shrug*
push @{$data->{signature}},
ref $val ? join q{ } => @{$val} : $val;
}
else
{
$data->{$key} = $val;
}
}
}
# A sanity check on the content of the object before we bless it:
if (! ($data->{name} && $data->{code}))
{
return "${class}::new: Missing required data (name or code)";
}
if (($class ne 'RPC::XML::Function') &&
(! ((exists $data->{signature}) &&
(ref($data->{signature}) eq 'ARRAY') &&
scalar(@{$data->{signature}}))))
{
return "${class}::new: Missing required data (signatures)";
}
bless $data, $class;
# This needs to happen post-bless in case of error (for error messages)
return $data->make_sig_table;
}
###############################################################################
#
# Sub Name: make_sig_table
#
# Description: Create a hash table of the signatures that maps to the
# corresponding return type for that particular invocation.
# Makes looking up call patterns much easier.
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $self in ref Object of this class
#
# Returns: Success: $self
# Failure: error message
#
###############################################################################
sub make_sig_table
{
my $self = shift;
my ($return, $rest);
delete $self->{sig_table};
for my $sig (@{$self->{signature}})
{
($return, $rest) = split / /, $sig, 2;
if (! $rest)
{
$rest = q{};
}
# If the key $rest already exists, then this is a collision
if ($self->{sig_table}->{$rest})
{
return
ref($self) . '::make_sig_table: Cannot have two different ' .
"return values for one set of params ($return vs. " .
"$self->{sig_table}->{$rest})";
}
$self->{sig_table}->{$rest} = $return;
}
return $self;
}
# These are basic accessor/setting functions for the various attributes
sub name { return shift->{name}; } # "name" cannot be changed at this level
sub namespace { return shift->{namespace} || q{}; } # Nor can "namespace"
sub help
{
my ($self, $value) = @_;
if ($value)
{
$self->{help} = $value;
}
return $self->{help};
}
sub version
{
my ($self, $value) = @_;
if ($value)
{
$self->{version} = $value;
}
return $self->{version};
}
sub hidden
{
my ($self, $value) = @_;
if ($value)
{
$self->{hidden} = $value;
}
return $self->{hidden};
}
sub code
{
my ($self, $value) = @_;
if ($value and ref $value eq 'CODE')
{
$self->{code} = $value;
}
return $self->{code};
}
sub signature
{
my ($self, $sig) = @_;
if ($sig)
{
if (ref $sig eq 'ARRAY')
{
my $old = $self->{signature};
$self->{signature} = $sig;
my $tmp = $self->make_sig_table;
if (! ref $tmp)
{
# If it failed to re-init the table, restore the old list (and
# old table). We don't have to check this return, since it had
# worked before.
$self->{signature} = $old;
$self->make_sig_table;
# Return an error message, since this failed:
return ref($self) . "::signature: $tmp";
}
}
else
{
# Anything not an array ref isn't useful
return ref($self) . "::signature: Bad value '$sig'";
}
}
# Return a copy of the array, not the original
return [ @{$self->{signature}} ];
}
###############################################################################
#
# Sub Name: clone
#
# Description: Create a near-exact copy of the invoking object, save that
# the listref in the "signature" key is a copy, not a ref
# to the same list.
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $self in ref Object of this class
#
# Returns: Success: $new_self
# Failure: error message
#
###############################################################################
sub clone
{
my $self = shift;
my $new_self = {};
for (keys %{$self})
{
next if $_ eq 'signature';
$new_self->{$_} = $self->{$_};
}
if (! $self->isa('RPC::XML::Function'))
{
$new_self->{signature} = [ @{$self->{signature}} ];
}
return bless $new_self, ref $self;
}
###############################################################################
#
# Sub Name: add_signature
# delete_signature
#
# Description: This pair of functions may be used to add and remove
# signatures from a method-object.
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $self in ref Object of this class
# @args in list One or more signatures
#
# Returns: Success: $self
# Failure: error string
#
###############################################################################
sub add_signature
{
my ($self, @args) = @_;
my (%sigs, $tmp, $old);
# Preserve the original in case adding the new one causes a problem
$old = $self->{signature};
%sigs = map { $_ => 1 } @{$self->{signature}};
for my $one_sig (@args)
{
$tmp = (ref $one_sig) ? join q{ } => @{$one_sig} : $one_sig;
$sigs{$tmp} = 1;
}
$self->{signature} = [ keys %sigs ];
$tmp = $self->make_sig_table;
if (! ref $tmp)
{
# Because this failed, we have to restore the old table and return
# an error
$self->{signature} = $old;
$self->make_sig_table;
return ref($self) . '::add_signature: Error re-hashing table: ' . $tmp;
}
return $self;
}
sub delete_signature
{
my ($self, @args) = @_;
my %sigs;
my $old = $self->{signature};
%sigs = map { $_ => 1 } @{$self->{signature}};
for my $one_sig (@args)
{
my $tmp = (ref $one_sig) ? join q{ } => @{$one_sig} : $one_sig;
delete $sigs{$tmp};
}
$self->{signature} = [ keys %sigs ];
if (@{$self->{signature}} == 0)
{
# Don't have to re-run make_sig_table, because it's still valid for
# this set:
$self->{signature} = $old;
return ref($self) . '::delete_signature: Cannot delete last signature';
}
# This can't fail, because deleting a signature will never cause an
# ambiguity in the table like adding one could.
return $self->make_sig_table;
}
###############################################################################
#
# Sub Name: match_signature
#
# Description: Determine if the passed-in signature string matches any
# of this method's known signatures.
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $self in ref Object of this class
# $sig in scalar Signature to check for
#
# Returns: Success: return type as a string
# Failure: 0
#
###############################################################################
sub match_signature
{
my $self = shift;
my $sig = shift;
if (ref $sig)
{
$sig = join q{ } => @{$sig};
}
return $self->{sig_table}->{$sig} || 0;
}
###############################################################################
#
# Sub Name: reload
#
# Description: Reload the method's code and ancillary data from the file
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $self in ref Object of this class
#
# Returns: Success: $self
# Failure: error message
#
###############################################################################
sub reload
{
my $self = shift;
my $class = ref $self;
my $me = "${class}::reload";
if (! $self->{file})
{
return "$me: No file associated with method $self->{name}";
}
my ($tmp) = load_xpl_file($self->{file});
if (ref $tmp)
{
# Update the information on this actual object
for (keys %{$tmp})
{
$self->{$_} = $tmp->{$_};
}
# Re-calculate the signature table, in case that changed as well
return $self->make_sig_table;
}
else
{
return "$me: Error loading $self->{file}: $tmp";
}
}
###############################################################################
#
# Sub Name: load_xpl_file
#
# Description: Load a XML-encoded method description (generally denoted
# by a *.xpl suffix) and return the relevant information.
#
# Note that this is not a method, it does not take $self as
# an argument.
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $file in scalar File to load
#
# Returns: Success: hashref of values
# Failure: error string
#
###############################################################################
sub load_xpl_file
{
my $file = shift;
require XML::Parser;
my ($me, $data, $signature, $code, $codetext, $accum, $P, $fh, $eval_ret,
$class, %attr);
$me = __PACKAGE__ . '::load_xpl_file';
$data = {};
# So these don't end up undef, since they're optional elements
$data->{hidden} = 0;
$data->{version} = q{};
$data->{help} = q{};
$data->{namespace} = __PACKAGE__;
$P = XML::Parser->new(
ErrorContext => 1,
Handlers => {
Char => sub { $accum .= $_[1] },
Start => sub { %attr = splice @_, 2 },
End => sub {
my $elem = $_[1];
$accum =~ s/^\s+//;
$accum =~ s/\s+$//;
if ($elem eq 'signature')
{
$data->{signature} ||= [];
push @{$data->{signature}}, $accum;
}
elsif ($elem eq 'hidden')
{
$data->{hidden} = 1;
}
elsif ($elem eq 'code')
{
if (! ($attr{language} &&
$attr{language} ne 'perl'))
{
$data->{$elem} = $accum;
}
}
elsif ('def' eq substr $elem, -3)
{
$class = 'RPC::XML::' . ucfirst substr $elem, 0, -3;
}
else
{
$data->{$elem} = $accum;
}
%attr = ();
$accum = q{};
}
}
);
if (! $P)
{
return "$me: Error creating XML::Parser object";
}
open $fh, '<', $file or return "$me: Error opening $file for reading: $!";
# Trap any errors
$eval_ret = eval { $P->parse($fh); 1; };
close $fh or return "$me: Error closing $file: $!";
if (! $eval_ret)
{
return "$me: Error parsing $file: $@";
}
# Try to normalize $codetext before passing it to eval
# Fudge a little and let them use '.' as a synonym for '::' in the
# namespace hierarchy.
$data->{namespace} =~ s/[.]/::/g;
# Next step is to munge away any actual subroutine name so that the eval
# yields an anonymous sub. Also insert the namespace declaration.
($codetext = $data->{code}) =~
s/sub\s+(?:[\w:]+)?\s*[{]/sub \{ package $data->{namespace}; /;
$code = eval $codetext; ## no critic (ProhibitStringyEval)
return "$me: Error creating anonymous sub: $@" if $@;
$data->{code} = $code;
# Add the file's mtime for when we check for stat-based reloading, name
# for reloading, and init the "called" counter to 0.
$data->{mtime} = (stat $file)[9];
$data->{file} = $file;
$data->{called} = 0;
return ($data, $class);
}
###############################################################################
#
# Sub Name: call
#
# Description: Encapsulates the invocation of the code block that the
# object is abstracting. Manages parameters, signature
# checking, etc.
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $self in ref Object of this class
# $srv in ref An object derived from the
# RPC::XML::Server class
# @data in list The params for the call itself
#
# Globals: None.
#
# Environment: None.
#
# Returns: Success: value
# Failure: dies with RPC::XML::Fault object as message
#
###############################################################################
sub call
{
my ($self, $srv, @data) = @_;
my (@paramtypes, @params, $signature, $resptype, $response, $name, $noinc);
$name = $self->name;
# Create the param list.
# The type for the response will be derived from the matching signature
@paramtypes = map { $_->type } @data;
@params = map { $_->value } @data;
$signature = join q{ } => @paramtypes;
$resptype = $self->match_signature($signature);
# Since there must be at least one signature with a return value (even
# if the param list is empty), this tells us if the signature matches:
if (! $resptype)
{
return $srv->server_fault(
badsignature =>
"method $name has no matching signature for the argument list: " .
"[$signature]"
);
}
# Make sure that the response-type is a valid XML-RPC type
if (($resptype ne 'scalar') && (! "RPC::XML::$resptype"->can('new')))
{
return $srv->server_fault(badsignature =>
"Signature [$signature] for method $name has unknown " .
"return-type '$resptype'");
}
# Set these in case the server object is part of the param list
local $srv->{signature} = ## no critic (ProhibitLocalVars)
[ $resptype, @paramtypes ];
local $srv->{method_name} = $name; ## no critic (ProhibitLocalVars)
# If the method being called is "system.status", check to see if we should
# increment the server call-count.
$noinc =
(($name eq 'system.status') &&
@data &&
($paramtypes[0] eq 'boolean') &&
$params[0]) ? 1 : 0;
# For RPC::XML::Method (and derivatives), pass the server object
if ($self->isa('RPC::XML::Method'))
{
unshift @params, $srv;
}
# Now take a deep breath and call the method with the arguments
if (! eval { $response = $self->{code}->(@params); 1; })
{
# On failure, propagate user-generated RPC::XML::fault exceptions, or
# transform Perl-level error/failure into such an object
if ($@)
{
return (blessed $@ and $@->isa('RPC::XML::fault')) ?
$@ : $srv->server_fault(execerror =>
"Method $name returned error: $@");
}
}
if (! $noinc)
{
$self->{called}++;
}
# Create a suitable return value
if (! ref $response)
{
if ($resptype eq 'scalar')
{
# Server code from the RPC::XML::Function class doesn't use
# signatures, so if they didn't encode the returned value
# themselves they're trusting smart_encode() to get it right.
$response = smart_encode($response);
}
else
{
# We checked that this was valid earlier, so no need for further
# tests here.
$response = "RPC::XML::$resptype"->new($response);
}
}
return $response;
}
###############################################################################
#
# Description: This is now an empty sub-class of RPC::XML::Procedure.
# It differs behaviorally from ::Procedure in that the
# RPC::XML::Server object is passed in the arguments list
# when the underlying code is invoked by call().
#
# Functions: None.
#
###############################################################################
package RPC::XML::Method;
use strict;
use warnings;
use vars qw(@ISA);
@ISA = qw(RPC::XML::Procedure);
###############################################################################
#
# Description: This is a type of Procedure that does no signature tests
# at either creation or invocation. Like RPC::XML::Procedure
# it does *not* get the RPC::XML::Server object when the
# underlying code is invoked by call().
#
# Functions: signature
# make_sig_table (called by some superclass methods)
# add_signature
# delete_signature
# match_signature
#
###############################################################################
package RPC::XML::Function;
use strict;
use warnings;
use vars qw(@ISA);
use subs qw(new signature make_sig_table clone match_signature);
@ISA = qw(RPC::XML::Procedure);
# These two are only implemented here at all, because some of the logic in
# other places call them
sub signature { return [ 'scalar' ]; }
sub make_sig_table { return shift; }
sub add_signature { return shift; }
sub delete_signature { return shift; }
###############################################################################
#
# Sub Name: match_signature
#
# Description: Noop. Needed for RPC::XML::Server.
#
# Arguments: NAME IN/OUT TYPE DESCRIPTION
# $self in ref Object of this class
# $sig in scalar Signature to check for
#
# Returns: Success: return type as a string
# Failure: 0
#
###############################################################################
sub match_signature
{
return 'scalar';
}
1;
__END__
=head1 NAME
RPC::XML::Procedure - Object encapsulation of server-side RPC procedures
=head1 SYNOPSIS
require RPC::XML::Procedure;
...
$method_1 = RPC::XML::Procedure->new({ name => 'system.identity',
code => sub { ... },
signature => [ 'string' ] });
$method_2 = RPC::XML::Procedure->new('/path/to/status.xpl');
=head1 IMPORTANT NOTE
This package is comprised of the code that was formerly B<RPC::XML::Method>.
The package was renamed when the decision was made to support procedures and
methods as functionally different entities. It is not necessary to include
both this module and B<RPC::XML::Method> -- this module provides the latter as
an empty subclass. In time, B<RPC::XML::Method> will be removed from the
distribution entirely.
=head1 DESCRIPTION
The B<RPC::XML::Procedure> package is designed primarily for behind-the-scenes
use by the B<RPC::XML::Server> class and any subclasses of it. It is
documented here in case a project chooses to sub-class it for their purposes
(which would require setting the C<method_class> attribute when creating
server objects, see L<RPC::XML::Server|RPC::XML::Server>).
This package grew out of the increasing need to abstract the operations that
related to the methods a given server instance was providing. Previously,
methods were passed around simply as hash references. It was a small step then
to move them into a package and allow for operations directly on the objects
themselves. In the spirit of the original hashes, all the key data is kept in
clear, intuitive hash keys (rather than obfuscated as the other classes
do). Thus it is important to be clear on the interface here before
sub-classing this package.
=head1 SUBROUTINES/METHODS
The following methods are provided by this class:
=over 4
=item new(FILE|HASHREF|LIST)
Creates a new object of the class, and returns a reference to it. The
arguments to the constructor are variable in nature, depending on the type:
=over 8
=item FILE
If there is exactly on argument that is not a reference, it is assumed to be a
filename from which the method is to be loaded. This is presumed to be in the
B<XPL> format descibed below (see L</"XPL File Structure">). If the file
cannot be opened, or if once opened cannot be parsed, an error is raised.
=item HASHREF
If there is exactly one argument that is a reference, it is assumed to be a
hash with the relevant information on the same keys as the object itself
uses. This is primarily to support backwards-compatibility to code written
when methods were implemented simply as hash references.
=item LIST
If there is more than one argument in the list, then the list is assumed to be
a sort of "ersatz" hash construct, in that one of the keys (C<signature>) is
allowed to "stack" if it occur multiple times. Otherwise, any keys that occur
multiple times overwrite the previous value:
=over 12
=item name
The name of the method, as it will be presented to clients
=item code
A reference to a subroutine, or an anonymous subroutine, that will receive
calls for the method
=item signature
Provides one calling-signature for the method, as either a space-separated
string of types or a list-reference
=item help
The help-text for a method, which is generally used as a part of the
introspection interface for a server
=item version
The version number/string for the method
=item hidden
A boolean (true or false) value indicating whether the method should be hidden
from introspection and similar listings
=back
Note that all of these correspond to the values that can be changed via the
accessor methods detailed later.
=back
If any error occurs during object creation, an error message is returned in
lieu of the object reference.
=item clone
Create a copy of the calling object, and return the new reference. All
elements are copied over cleanly, except for the code reference stored on the
C<code> hash key. The clone will point to the same code reference as the
original. Elements such as C<signature> are copied, so that changes to the
clone will not impact the original.
=item name
Returns the name by which the server is advertising the method. Unlike the
next few accessors, this cannot be changed on an object. In order to
streamline the managment of methods within the server classes, this must
persist. However, the other elements may be used in the creation of a new
object, which may then be added to the server, if the name absolutely must
change.
=item namespace
If the procedure object was created from a file, or if the instantiation
included namespace information, this accessor will return the namespace that
the underlying code executes in. Otherwise, it returns an empty string. This
cannot be altered (even if the B<code> method is used to replace the code
routine).
=item code([NEW])
Returns or sets the code-reference that will receive calls as marshalled by
the server. The existing value is lost, so if it must be preserved, then it
should be retrieved prior to the new value being set.
=item signature([NEW])
Return a list reference containing the signatures, or set it. Each element of
the list is a string of space-separated types (the first of which is the
return type the method produces in that calling context). If this is being
used to set the signature, then an array reference must be passed that
contains one or more strings of this nature. Nested list references are not
allowed at this level. If the new signatures would cause a conflict (a case in
which the same set of input types are specified for different output types),
the old set is silently restored.
=item help([NEW])
Returns or sets the help-text for the method. As with B<code>, the previous
value is lost.
=item hidden([NEW])
Returns or sets the hidden status of the method. Setting it loses the previous
value.
=item version([NEW])
Returns or sets the version string for the method (overwriting as with the
other accessors).
=item add_signature(LIST)
Add one or more signatures (which may be a list reference or a string) to the
internal tables for this method. Duplicate signatures are ignored. If the new
signature would cause a conflict (a case in which the same set of input types
are specified for different output types), the old set is restored and an
error message is returned.
=item delete_signature(LIST)
Deletes the signature or signatures (list reference or string) from the
internal tables. Quietly ignores any signature that does not exist. If the new
signature would cause a conflict (a case in which the same set of input types
are specified for different output types), the old set is restored and an
error message is returned.
=item match_signature(SIGNATURE)
Check that the passed-in signature is known to the method, and if so returns
the type that the method should be returning as a result of the call. Returns
a zero (0) otherwise. This differs from other signature operations in that the
passed-in signature (which may be a list-reference or a string) B<I<does not
include the return type>>. This method is provided so that servers may check a
list of arguments against type when marshalling an incoming call. For example,
a signature of C<'int int'> would be tested for by calling
C<$M-E<gt>match_signature('int')> and expecting the return value to be C<int>.
=item call(SERVER, PARAMLIST)
Execute the code that this object encapsulates, using the list of parameters
passed in PARAMLIST. The SERVER argument should be an object derived from the
B<RPC::XML::Server> class. For some types of procedure objects, this becomes
the first argument of the parameter list to simulate a method call as if it
were on the server object itself. The return value should be a data object
(possibly a B<RPC::XML::fault>), but may not always be pre-encoded. Errors
trapped in C<$@> are converted to fault objects. This method is generally used
in the C<dispatch> method of the server class, where the return value is
subsequently wrapped within a B<RPC::XML::response> object.
=item reload
Instruct the object to reload itself from the file it originally was loaded
from, assuming that it was loaded from a file to begin with. Returns an error
if the method was not originally loaded from a file, or if an error occurs
during the reloading operation.
=back
=head2 Additional Hash Data