Skip to content

convert many subroutines to use signatures - #708

Draft
rjbs wants to merge 4 commits into
mainfrom
signatures
Draft

convert many subroutines to use signatures#708
rjbs wants to merge 4 commits into
mainfrom
signatures

Conversation

@rjbs

@rjbs rjbs commented May 28, 2022

Copy link
Copy Markdown
Owner

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
@rjbs
rjbs force-pushed the main branch 2 times, most recently from 40e530a to 370397c Compare November 7, 2025 14:08
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