[system] / trunk / xmlrpc / RPC / RPC-XML-0.25 / methods / introspection.code Repository:
ViewVC logotype

View of /trunk/xmlrpc/RPC/RPC-XML-0.25/methods/introspection.code

Parent Directory Parent Directory | Revision Log Revision Log


Revision 279 - (download) (annotate)
Fri May 17 21:44:04 2002 UTC (17 years, 6 months ago) by gage
File size: 2092 byte(s)
Experimental xmlrpc WeBWorK webservices

    1 ###############################################################################
    2 #
    3 #   Sub Name:       introspection
    4 #
    5 #   Description:    Collates the data from listMethods, methodHelp and
    6 #                   methodSignature into a single array
    7 #
    8 #   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
    9 #                   $srv      in      ref       Server object instance
   10 #                   $list     in      listref   If passed, limit methods listed
   11 #                                     or scalar   to these.
   12 #
   13 #   Globals:        None.
   14 #
   15 #   Environment:    None.
   16 #
   17 #   Returns:        Success:    string or listref
   18 #                   Failure:    fault object
   19 #
   20 ###############################################################################
   21 sub introspection
   22 {
   23     use strict;
   24 
   25     my $srv = shift;
   26     my $list = shift;
   27 
   28     my (@methods, @all_methods, %all_methods, @bad, @results, $scalar);
   29 
   30     my $name = $srv->{method_name};
   31     $scalar = ($list and (! ref($list))) ? 1 : 0;
   32     @all_methods = sort keys %{$srv->{__method_table}};
   33 
   34     if ($list)
   35     {
   36         # This is an expensive-enough operation that I don't want to do it
   37         # if I don't have to
   38         @methods = ($scalar) ? ($list) : @$list;
   39         @all_methods{@all_methods} = (1) x scalar(@all_methods);
   40         if (@bad = grep(! $all_methods{$_}, @methods))
   41         {
   42             local $" = ', ';
   43             return RPC::XML::fault->new(302, "$name: Method(s) @bad unknown");
   44         }
   45     }
   46     else
   47     {
   48         @methods = @all_methods;
   49     }
   50 
   51     # Now exclude any that are hidden from introspection APIs
   52     @methods = grep(! $srv->{__method_table}->{$_}->{hidden}, @methods);
   53 
   54     for (@methods)
   55     {
   56         push(@results, { name => $_,
   57                          help => $srv->{__method_table}->{$_}->{help},
   58                          signature => $srv->{__method_table}->{$_}->{signature},
   59                          version =>
   60                          RPC::XML::string
   61                          ->new($srv->{__method_table}->{$_}->{version}) });
   62     }
   63 
   64     return $scalar ? $results[0] : \@results;
   65 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9