Skip to content

Commit 952ae95

Browse files
committed
ParseXS: refactor: INPUT_handler() use $line vs $_
This is #1 of a small series of commits to refactor the INPUT_handler() method and turn it into a Node subclass method. This commit changes the main loop from using $_ to hold the current line, to using the variable $line instead.
1 parent 23f7ae5 commit 952ae95

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,30 +1961,30 @@ sub ST {
19611961

19621962
sub INPUT_handler {
19631963
my ExtUtils::ParseXS $self = shift;
1964-
$_ = shift;
1964+
my $line = shift;
19651965

19661966
# In this loop: process each line until the next keyword or end of
19671967
# paragraph.
19681968

1969-
for (; !/^$BLOCK_regexp/o; $_ = shift(@{ $self->{line} })) {
1969+
for (; $line !~ /^$BLOCK_regexp/o; $line = shift(@{ $self->{line} })) {
19701970
# treat NOT_IMPLEMENTED_YET as another block separator, in addition to
19711971
# $BLOCK_regexp.
1972-
last if /^\s*NOT_IMPLEMENTED_YET/;
1973-
next unless /\S/; # skip blank lines
1972+
last if $line =~ /^\s*NOT_IMPLEMENTED_YET/;
1973+
next unless $line =~ /\S/; # skip blank lines
19741974

1975-
trim_whitespace($_);
1976-
my $ln = $_; # keep original line for error messages
1975+
trim_whitespace($line);
1976+
my $orig_line = $line; # keep original line for error messages
19771977

19781978
# remove any trailing semicolon, except for initialisations
1979-
s/\s*;$//g unless /[=;+].*\S/;
1979+
$line =~ s/\s*;$//g unless $line =~ /[=;+].*\S/;
19801980

19811981
# Extract optional initialisation code (which overrides the
19821982
# normal typemap), such as 'int foo = ($type)SvIV($arg)'
19831983
my $var_init = '';
19841984
my $init_op;
1985-
($init_op, $var_init) = ($1, $2) if s/\s* ([=;+]) \s* (.*) $//xs;
1985+
($init_op, $var_init) = ($1, $2) if $line =~ s/\s* ([=;+]) \s* (.*) $//xs;
19861986

1987-
s/\s+/ /g;
1987+
$line =~ s/\s+/ /g;
19881988

19891989
# Split 'char * &foo' into ('char *', '&', 'foo')
19901990
# skip to next INPUT line if not valid.
@@ -2004,15 +2004,15 @@ sub INPUT_handler {
20042004
# int a XYZ;
20052005

20062006
my ($var_type, $var_addr, $var_name) =
2007-
/^
2007+
$line =~ /^
20082008
( .*? [^&\s] ) # type
20092009
\s*
20102010
(\&?) # addr
20112011
\s* \b
20122012
(\w+ | length\(\w+\)) # name or length(name)
20132013
$
20142014
/xs
2015-
or $self->blurt("Error: invalid parameter declaration '$ln'"), next;
2015+
or $self->blurt("Error: invalid parameter declaration '$orig_line'"), next;
20162016

20172017
# length(s) is only allowed in the XSUB's signature.
20182018
if ($var_name =~ /^length\((\w+)\)$/) {
@@ -2143,6 +2143,8 @@ sub INPUT_handler {
21432143
$param->as_code($self);
21442144

21452145
} # foreach line in INPUT block
2146+
2147+
$_ = $line;
21462148
}
21472149

21482150

0 commit comments

Comments
 (0)