3 use ExtUtils::Manifest 'maniread';
5 my $outname = shift || '-';
7 my @funcs = make_func_list();
8 my %funcs = map { $_ => 1 } @funcs;
10 # look for files to parse
13 my @files = sort grep /\.(c|im|h)$/, keys %$mani;
15 # scan each file for =item <func>\b
28 for my $file (@files) {
30 or die "Cannot open $file for documentation: $!\n";
32 if (/^=item (\w+)\b/ && $funcs{$1}) {
37 elsif ($func && /^=(cut|head)/) {
38 if ($funcs{$func}) { # only save the API functions
39 $alldocs{$func} = [ @funcdocs ];
40 $from{$func} = "File $file";
42 $funccats{$func} = $category;
43 push @{$cats{$category}}, $func;
46 $funcsyns{$func} = $synopsis;
48 defined $order or $order = 50;
49 $order{$func} = $order;
57 if (/^=category (.*)/) {
60 elsif (/^=synopsis (.*)/) {
61 unless (length $synopsis) {
65 push @funcdocs, " $1\n";
67 elsif (/^=order (.*)$/) {
70 or die "=order must specify a number for $func in $file\n";
78 die "Documentation for $func not followed by =cut or =head in $file\n";
83 open OUT, "> $outname"
84 or die "Cannot open $outname: $!";
86 # I keep this file in git and as part of the dist, make sure newlines
91 Do not edit this file, it is generated automatically by apidocs.perl
92 from Imager's source files.
94 Each function description has a comment listing the source file where
95 you can find the documentation.
99 Imager::APIRef - Imager's C API - reference.
104 color.rgba.r = 255; color.rgba.g = 0; color.rgba.b = 255;
105 double x[] = { ... };
106 double y[] = { ... };
108 poly.count = sizeof(x) / sizeof(*x);
114 for my $cat (sort { lc $a cmp lc $b } keys %cats) {
115 print OUT "\n # $cat\n";
116 my @funcs = @{$cats{$cat}};
118 @orig{@funcs} = 0 .. $#funcs;
119 @funcs = sort { $order{$a} <=> $order{$b} || $orig{$a} <=> $orig{$b} } @funcs;
120 for my $func (grep $funcsyns{$_}, @funcs) {
121 my $syn = $funcsyns{$func};
135 for my $cat (sort { lc $a cmp lc $b } keys %cats) {
136 print OUT "=head2 $cat\n\n=over\n\n";
137 my @ordered_funcs = sort {
138 $order{$a} <=> $order{$b}
141 for my $func (@ordered_funcs) {
142 print OUT @{$alldocs{$func}}, "\n";
143 print OUT "=for comment\nFrom: $from{$func}\n\n";
144 delete $undoc{$func};
146 print OUT "\n=back\n\n";
149 # see if we have an uncategorised section
150 if (grep $alldocs{$_}, keys %undoc) {
151 print OUT "=head2 Uncategorized functions\n\n=over\n\n";
152 #print join(",", grep !exists $order{$_}, @funcs), "\n";
153 for my $func (sort { $order{$a} <=> $order{$b} || $a cmp $b }
154 grep $undoc{$_} && $alldocs{$_}, @funcs) {
155 print OUT @{$alldocs{$func}}, "\n";
156 print OUT "=for comment\nFrom: $from{$func}\n\n";
157 delete $undoc{$func};
159 print OUT "\n\n=back\n\n";
167 The following API functions are undocumented so far, hopefully this
174 print OUT "=item *\n\nB<$_>\n\n" for sort keys %undoc;
176 print OUT "\n\n=back\n\n";
183 Tony Cook <tonyc@cpan.org>
187 Imager, Imager::API, Imager::ExtUtils, Imager::Inline
197 qw(i_img i_color i_fcolor i_fill_t mm_log mm_log i_color_model_t
198 im_context_t i_img_dim i_img_dim_u im_slot_t
199 i_polygon_t i_poly_fill_mode_t i_mutex_t
200 i_img_has_alpha i_DF i_DFc i_DFp i_DFcp i_psamp_bits i_gsamp_bits
202 open FUNCS, "< imexttypes.h"
203 or die "Cannot open imexttypes.h: $!\n";
206 /^typedef struct/ && ++$in_struct;
207 if ($in_struct && !/SKIP/ && /\(\*f_(i[om]?_\w+)/) {
212 if (/^\} im_ext_funcs;$/) {
214 or die "Found end of functions structure but not the start";
221 die "Found start of the functions structure but not the end\n";
224 die "Found neither the start nor end of the functions structure\n";
230 apidocs.perl - parse Imager's source for POD documenting the C API
234 perl apidocs.perl lib/Imager/APIRef.pod
238 Parses Imager's C sources, including .c, .h and .im files searching
239 for function documentation.
241 Besides the normal POD markup, the following can be included:
245 =item =category I<category-name>
247 The category the function should be in.
249 =item =synopsis I<sample-code>
251 Sample code using the function to include in the Imager::APIRef SYNOPSIS
253 =item =order I<integer>
255 Allows a function to be listed out of order. If this isn't specified
256 it defaults to 50, so a value of 10 will cause the function to be
257 listed at the beginning of its category, or 90 to list at the end.
259 Functions with equal order are otherwise ordered by name.
265 Tony Cook <tonyc@cpan.org>