Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert many subroutines to use signatures #708

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

convert many subroutines to use signatures #708

wants to merge 4 commits into from

Conversation

rjbs
Copy link
Owner

@rjbs rjbs commented May 28, 2022

No description provided.

rjbs added 4 commits May 28, 2022 12:36
First, I used a small program (included below) to automatically convert
existing subroutines, which use @_, to use signatures.  This will not
have been comprehensive.  Some use "shift" to get signatures.  Also, the
program will not upgrade anonymous subroutines.  And there are probably
other shortfalls.

Then, I ran the tests repeatedly and corrected errors that were exposed,
most of which were related to arguments that were optional but had been
(of course) converted to mandatory arguments.

This may well affect some plugins downstream, so we'll want to do a
bunch of testing before deciding this is a good idea!

    #!/bin/env perl
    use v5.36.0;

    my $fn = $ARGV[0];
    my @output;

    {
      open my $fh, '<', $fn;

      my @input = <$fh>;

      LINE: while (my $line = shift @input) {
        if ($line =~ /^sub (\S+) \{$/) {
          my $sub = $1;
          my $next = shift @input;

          if ($next && $next =~ /^\s*my (\([^)]+\)) = \@_;$/) {
            my $sig = $1;
            my $new_line = "sub $sub $sig {\n";

            warn $new_line;
            push @output, $new_line;

            while (@input && $input[0] !~ /\S/) {
              shift @input;
            }

            next LINE;
          }

          unshift @input, $next;
        }

        push @output, $line;
      }
    }

    open my $fh, '>', $fn;
    print {$fh} @output;
    close $fh;
        - use subroutine signatures throughout
@rjbs rjbs force-pushed the main branch 10 times, most recently from 9361f28 to f825e3b Compare June 3, 2024 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant