]> git.vpit.fr Git - perl/modules/with.git/blob - samples/funcs.pl
Importing with-0.01
[perl/modules/with.git] / samples / funcs.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 my $pod = $ARGV[0] || './perlfunc.pod';
7 open my $p, '<', $pod or die "open($pod): $!";
8 my $d = do { local $/; <$p> };
9 my ($f) = $d =~ /=over[^\n]*\n(.*?)=back/s;
10 die "no functions" unless $f;
11 my @f = $f =~ /C<([^<>]+)>/g;
12 my %dup;
13 @f = sort
14       grep { eval { () = prototype "CORE::$_" }; !$@ }
15        grep !$dup{$_}++, @f;
16 my $c = 10;
17 my $base = "my \@core = qw/";
18 my $out = $base;
19 my $l = length $base;
20 my $first = 1;
21 for (@f) {
22  if ($l + (1 - $first) + length() <= 78) {
23   if ($first) {
24    $first = 0;
25   } else {
26    $l++;
27    $out .= ' ';
28   }
29   $l += length;
30   $out .= $_;
31  } else {
32   $l = length($base) - 1;
33   $out .= "\n" . (' ' x $l);
34  }
35 }
36 $out .= "/;\n";
37 print $out;