adding filtering and sorting to the introspection stubber
[OpenSRF.git] / doc / dokuwiki-doc-stubber.pl
1 #!/usr/bin/perl -w
2 use OpenSRF::System qw(/pines/conf/bootstrap.conf);
3 use Getopt::Long
4
5 $| = 1;
6
7 my $cvs_base = 'http://open-ils.org/cgi-bin/viewcvs.cgi/ILS/Open-ILS/src/perlmods/';
8 my $nest = 0;
9 my $service;
10 my $filter;
11 my $sort_ignore;
12
13 GetOptions(     'cvs_base=s'    => \$cvs_base,
14                 'nest'          => \$nest,
15                 'service=s'     => \$service,
16                 'ignore=s'      => \$sort_ignore,
17                 'filter=s'      => \$filter,
18 );
19
20 unless( $service ) {
21         print "usage: $0 -s <service name> [-c <cvs repo base URL> -n]\n";
22         exit;
23 }
24
25 OpenSRF::System->bootstrap_client();
26 my $session = OpenSRF::AppSession->create( $service );
27
28 my $req; 
29 if ($filter) {
30         $req = $session->request('opensrf.system.method', $filter);
31 } else {
32         $req = $session->request('opensrf.system.method.all');
33 }
34
35 my $count = 1;
36 my %m;
37 while( my $meth = $req->recv(60) ) {
38         $meth = $meth->content;
39
40         $api_name = $meth->{api_name};
41
42         $m{$api_name}{api_name} = $meth->{api_name};
43
44         $m{$api_name}{package} = $meth->{package};
45         $m{$api_name}{method} = $meth->{method};
46
47         $m{$api_name}{api_level} = int $meth->{api_level};
48         $m{$api_name}{server_class} = $meth->{server_class} || '**ALL**';
49         $m{$api_name}{stream} = int($meth->{stream} || 0);
50         $m{$api_name}{cachable} = int($meth->{cachable} || 0);
51
52         $m{$api_name}{note} = $meth->{note} || 'what I do';
53         ($m{$api_name}{cvs} = $m{$api_name}{package}) =~ s/::/\//go;
54
55         $m{$api_name}{stream} = $m{$api_name}{stream}?'Yes':'No';
56         $m{$api_name}{cachable} = $m{$api_name}{cachable}?'Yes':'No';
57
58         print STDERR "." unless ($count % 10);
59
60         $count++;
61 }
62
63 warn "\nThere are ".scalar(keys %m)." methods published by $service\n";
64
65 my @m_list;
66 if (!$sort_ignore) {
67         @m_list = sort keys %m;
68 } else {
69         @m_list =
70                 map { ($$_[0]) }
71                 sort {
72                         $$a[1] cmp $$b[1]
73                                 ||
74                         length($$b[0]) <=> length($$a[0])
75                 } map {
76                         [$_ =>
77                         do {
78                                 (my $x = $_) =~ s/^$sort_ignore//go;
79                                 $x;
80                         } ]
81                 } keys %m;
82 }
83
84 for my $meth ( @m_list ) {
85
86         my $pad = 0;
87         my $header = '=====';
88         if ($nest) {
89                 no warnings;
90                 (my $x = $meth) =~ s/\./$pad++;$1/eg;
91         }
92         $pad = ' 'x$pad;
93
94         print <<"       METHOD";
95 $pad$header $meth $header
96
97 $m{$meth}{note}
98
99   * [[osrf-devel:terms#opensrf_api-level|API Level]]: $m{$meth}{api_level}
100   * [[osrf-devel:terms#opensrf_server_class|Server Class]]: $m{$meth}{server_class}
101   * Implementation Method: [[$cvs_base/$m{$meth}{cvs}.pm|$m{$meth}{package}\::$m{$meth}{method}]]
102   * Streaming [[osrf-devel:terms#opensrf_method|Method]]: $m{$meth}{stream}
103   * Cachable [[osrf-devel:terms#opensrf_method|Method]]: $m{$meth}{cachable}
104
105   * **Parameters:**
106     * //param1//\\\\ what it is...
107   * **Returns:**
108     * //Success//\\\\ successful format
109     * //Failure//\\\\ failure format (exception, etc)
110
111
112         METHOD
113 }
114