« blib/script/perl_types_refactor_names_map.pm
↑ Summary
blib/script/refactor_names_map_create_groups.pl »
| 1 | #!/usr/bin/env perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use RPerl; | ||
| 5 | our $VERSION = 0.011_000; | ||
| 6 | |||
| 7 | # wget https://perldoc.perl.org/perlapi.html | ||
| 8 | |||
| 9 | use List::MoreUtils qw(uniq); | ||
| 10 | use English qw(-no_match_vars); | ||
| 11 | use Data::Dumper; | ||
| 12 | $Data::Dumper::Sortkeys = 1; | ||
| 13 | |||
| 14 | ## no critic qw(ProhibitExplicitStdin) # USER DEFAULT 4: allow <STDIN> | ||
| 15 | |||
| 16 | print 'ARE YOU AN RPERL SYSTEM DEVELOPER? '; | ||
| 17 | my $stdin_confirm = <STDIN>; | ||
| 18 | if ( $stdin_confirm =~ /^[Yy]/ ) { | ||
| 19 | print 'Regenerating Perl API Names...' . "\n"; | ||
| 20 | } | ||
| 21 | else { | ||
| 22 | exit; | ||
| 23 | } | ||
| 24 | |||
| 25 | my $perlapinames_filename = 'lib/perlapinames_generated.pm'; | ||
| 26 | |||
| 27 | |||
| 28 | # generate static output | ||
| 29 | |||
| 30 | my $perlapinames_generated = <<'EOF'; | ||
| 31 | # THIS FILE IS AUTOMATICALLY GENERATED BY script/development/perlapinames_regenerate.pl | ||
| 32 | # DO NOT EDIT THIS FILE DIRECTLY!!! please put all changes in perlapinames_regenerate.pl | ||
| 33 | ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names | ||
| 34 | package # hide from PAUSE indexing | ||
| 35 | perlapinames_generated; | ||
| 36 | use strict; | ||
| 37 | use warnings; | ||
| 38 | our $VERSION = 0.001_000; | ||
| 39 | |||
| 40 | ## no critic qw(ProhibitParensWithBuiltins ProhibitNoisyQuotes) # SYSTEM SPECIAL 3: allow auto-generated code | ||
| 41 | |||
| 42 | EOF | ||
| 43 | |||
| 44 | |||
| 45 | # read & parse input file | ||
| 46 | |||
| 47 | my string $input_filename = $ARGV[0]; | ||
| 48 | |||
| 49 | print 'have input $input_filename = ', $input_filename, "\n"; | ||
| 50 | |||
| 51 | my arrayref::string $perl_functions_documented = []; | ||
| 52 | my arrayref::string $perl_functions_undocumented = []; | ||
| 53 | my arrayref::string $perl_variables_documented = []; | ||
| 54 | my arrayref::string $perl_variables_undocumented = []; | ||
| 55 | |||
| 56 | my boolean $documented = 1; | ||
| 57 | |||
| 58 | # read file | ||
| 59 | open my filehandleref $FILE_HANDLE, '<', $input_filename or croak 'ERROR, Cannot open file ' . $input_filename . ' for reading,' . $OS_ERROR . ', croaking'; | ||
| 60 | while ( my $input_line = <$FILE_HANDLE> ) { | ||
| 61 | # print 'have $input_line = ', $input_line, "\n"; | ||
| 62 | |||
| 63 | # HARD-CODED EXAMPLE: | ||
| 64 | #<li><a name="sv_pvn_nomg"></a><b>sv_pvn_nomg | ||
| 65 | |||
| 66 | if ($documented) { | ||
| 67 | if ($input_line eq '<a name="Undocumented-functions"></a><h1>Undocumented functions</h1>' . "\n") { | ||
| 68 | $documented = 0; | ||
| 69 | } | ||
| 70 | if ($input_line =~ m/^<li><a\ name="\w+"><\/a><b>(\w+)$/gxms) { | ||
| 71 | push @{$perl_functions_documented}, $1; | ||
| 72 | if (((substr $1, 0, 4) eq 'get_') or ((substr $1, 0, 4) eq 'set_')) { | ||
| 73 | push @{$perl_variables_documented}, (substr $1, 4); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | } | ||
| 77 | else { | ||
| 78 | if ($input_line =~ m/^<li><a\ name="\w+"><\/a><b>(\w+)$/gxms) { | ||
| 79 | push @{$perl_functions_undocumented}, $1; | ||
| 80 | if (((substr $1, 0, 4) eq 'get_') or ((substr $1, 0, 4) eq 'set_')) { | ||
| 81 | push @{$perl_variables_undocumented}, (substr $1, 4); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | close $FILE_HANDLE or croak 'ERROR, Cannot close file ' . $input_filename . ' after reading,' . $OS_ERROR . ', croaking'; | ||
| 87 | |||
| 88 | |||
| 89 | # generate dynamic output | ||
| 90 | |||
| 91 | $perlapinames_generated .= '$perlapinames_generated::FUNCTIONS_DOCUMENTED = undef;' . "\n"; | ||
| 92 | $perlapinames_generated .= '$perlapinames_generated::FUNCTIONS_DOCUMENTED = {' . "\n"; | ||
| 93 | foreach my string $perl_function_documented (uniq sort @{$perl_functions_documented}) { | ||
| 94 | $perlapinames_generated .= q{ '} . $perl_function_documented . q{' => 1,} . "\n"; | ||
| 95 | } | ||
| 96 | $perlapinames_generated .= '};' . "\n\n"; | ||
| 97 | |||
| 98 | $perlapinames_generated .= '$perlapinames_generated::FUNCTIONS_UNDOCUMENTED = undef;' . "\n"; | ||
| 99 | $perlapinames_generated .= '$perlapinames_generated::FUNCTIONS_UNDOCUMENTED = {' . "\n"; | ||
| 100 | foreach my string $perl_function_undocumented (uniq sort @{$perl_functions_undocumented}) { | ||
| 101 | $perlapinames_generated .= q{ '} . $perl_function_undocumented . q{' => 1,} . "\n"; | ||
| 102 | } | ||
| 103 | $perlapinames_generated .= '};' . "\n\n"; | ||
| 104 | |||
| 105 | $perlapinames_generated .= '$perlapinames_generated::VARIABLES_DOCUMENTED = undef;' . "\n"; | ||
| 106 | $perlapinames_generated .= '$perlapinames_generated::VARIABLES_DOCUMENTED = {' . "\n"; | ||
| 107 | foreach my string $perl_function_documented (uniq sort @{$perl_variables_documented}) { | ||
| 108 | $perlapinames_generated .= q{ '} . $perl_function_documented . q{' => 1,} . "\n"; | ||
| 109 | } | ||
| 110 | $perlapinames_generated .= '};' . "\n\n"; | ||
| 111 | |||
| 112 | $perlapinames_generated .= '$perlapinames_generated::VARIABLES_UNDOCUMENTED = undef;' . "\n"; | ||
| 113 | $perlapinames_generated .= '$perlapinames_generated::VARIABLES_UNDOCUMENTED = {' . "\n"; | ||
| 114 | foreach my string $perl_function_undocumented (uniq sort @{$perl_variables_undocumented}) { | ||
| 115 | $perlapinames_generated .= q{ '} . $perl_function_undocumented . q{' => 1,} . "\n"; | ||
| 116 | } | ||
| 117 | $perlapinames_generated .= '};' . "\n\n"; | ||
| 118 | |||
| 119 | |||
| 120 | # finish static output | ||
| 121 | |||
| 122 | $perlapinames_generated .= '1; # end of package' . "\n"; | ||
| 123 | |||
| 124 | |||
| 125 | # write output file | ||
| 126 | |||
| 127 | my $open_close_retval = open my $PERLAPINAMES_FILEHANDLE_OUT, '>', $perlapinames_filename; | ||
| 128 | if ( not $open_close_retval ) { | ||
| 129 | croak( 'ERROR ERPNS00: Problem opening output file ' . q{'} . $perlapinames_filename . q{': } . $OS_ERROR, 'croaking' ); | ||
| 130 | } | ||
| 131 | |||
| 132 | print {$PERLAPINAMES_FILEHANDLE_OUT} $perlapinames_generated; | ||
| 133 | |||
| 134 | $open_close_retval = close $PERLAPINAMES_FILEHANDLE_OUT; | ||
| 135 | if ( not $open_close_retval ) { | ||
| 136 | croak( 'ERROR ERPNS01: Problem closing output file ' . q{'} . $perlapinames_filename . q{': } . $OS_ERROR, 'croaking' ); | ||
| 137 | } | ||
| 138 | |||
| 139 | system 'perltidy', '-pbp', '--ignore-side-comment-lengths', '--converge', '-b', '-nst', q{-bext='/'}, '-q', $perlapinames_filename; | ||
| 140 | |||
| 141 | print 'Regenerating Perl API Names... DONE!' . "\n"; |