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 = 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 (.*)/) {
63 elsif (/^=order (.*)$/) {
66 or die "=order must specify a number for $func in $file\n";
74 die "Documentation for $func not followed by =cut or =head in $file\n";
79 open OUT, "> $outname"
80 or die "Cannot open $outname: $!";
82 # I keep this file in git and as part of the dist, make sure newlines
87 Do not edit this file, it is generated automatically by apidocs.perl
88 from Imager's source files.
90 Each function description has a comment listing the source file where
91 you can find the documentation.
95 Imager::APIRef - Imager's C API - reference.
100 color.rgba.r = 255; color.rgba.g = 0; color.rgba.b = 255;
104 for my $cat (sort { lc $a cmp lc $b } keys %cats) {
105 print OUT "\n # $cat\n";
106 for my $func (grep $funcsyns{$_}, sort { $order{$a} <=> $order{$b} } @{$cats{$cat}}) {
107 my $syn = $funcsyns{$func};
121 for my $cat (sort { lc $a cmp lc $b } keys %cats) {
122 print OUT "=head2 $cat\n\n=over\n\n";
123 my @ordered_funcs = sort {
124 $order{$a} <=> $order{$b}
127 for my $func (@ordered_funcs) {
128 print OUT @{$alldocs{$func}}, "\n";
129 print OUT "=for comment\nFrom: $from{$func}\n\n";
130 delete $undoc{$func};
132 print OUT "\n=back\n\n";
135 # see if we have an uncategorised section
136 if (grep $alldocs{$_}, keys %undoc) {
137 print OUT "=head2 Uncategorized functions\n\n=over\n\n";
138 #print join(",", grep !exists $order{$_}, @funcs), "\n";
139 for my $func (sort { $order{$a} <=> $order{$b} || $a cmp $b }
140 grep $undoc{$_} && $alldocs{$_}, @funcs) {
141 print OUT @{$alldocs{$func}}, "\n";
142 print OUT "=for comment\nFrom: $from{$func}\n\n";
143 delete $undoc{$func};
145 print OUT "\n\n=back\n\n";
153 The following API functions are undocumented so far, hopefully this
160 print OUT "=item *\n\nB<$_>\n\n" for sort keys %undoc;
162 print OUT "\n\n=back\n\n";
169 Tony Cook <tonyc@cpan.org>
173 Imager, Imager::ExtUtils, Imager::Inline
182 my @funcs = qw(i_img i_color i_fcolor i_fill_t mm_log i_img_color_channels i_img_has_alpha i_img_dim);
183 open FUNCS, "< imexttypes.h"
184 or die "Cannot open imexttypes.h: $!\n";
187 /^typedef struct/ && ++$in_struct;
188 if ($in_struct && /\(\*f_(i_\w+)/) {
191 if (/^\} im_ext_funcs;$/) {
193 or die "Found end of functions structure but not the start";
200 die "Found start of the functions structure but not the end\n";
203 die "Found neither the start nor end of the functions structure\n";
209 apidocs.perl - parse Imager's source for POD documenting the C API
213 perl apidocs.perl lib/Imager/APIRef.pod
217 Parses Imager's C sources, including .c, .h and .im files searching
218 for function documentation.
220 Besides the normal POD markup, the following can be included:
224 =item =category I<category-name>
226 The category the function should be in.
228 =item =synopsis I<sample-code>
230 Sample code using the function to include in the Imager::APIRef SYNOPSIS
232 =item =order I<integer>
234 Allows a function to be listed out of order. If this isn't specified
235 it defaults to 50, so a value of 10 will cause the function to be
236 listed at the beginning of its category, or 90 to list at the end.
238 Functions with equal order are otherwise ordered by name.
244 Tony Cook <tonyc@cpan.org>