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