Skip to content

Commit 32bc99e

Browse files
committed
ParseXS: refactor: OUTPUT_handler(): mv to Node.pm
This is #3 of a small series of commits to refactor the OUTPUT_handler() method and turn it into a Node subclass method. This commit moves the ExtUtils::ParseXS methods OUTPUT_handler() OUTPUT_handler_line() from ParseXS.pm into ParseXS/Node.pm. For now they temporarily remain as ExtUtils::ParseXS methods; this is just a straight cut and paste, except for fully-qualifying the $BLOCK_regexp package variable name and adding a couple of temporary 'package ExtUtils::ParseXS' declarations.
1 parent 58ffdb2 commit 32bc99e

File tree

2 files changed

+83
-75
lines changed

2 files changed

+83
-75
lines changed

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

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,81 +1743,6 @@ sub ST {
17431743
}
17441744

17451745

1746-
# Process the lines following the OUTPUT: keyword.
1747-
1748-
sub OUTPUT_handler {
1749-
my ExtUtils::ParseXS $self = shift;
1750-
1751-
my $line = shift;
1752-
1753-
# In this loop: process each line until the next keyword or end of
1754-
# paragraph
1755-
1756-
for (; $line !~ /^$BLOCK_regexp/o; $line = shift(@{ $self->{line} })) {
1757-
$self->OUTPUT_handler_line($line);
1758-
} # foreach line in OUTPUT block
1759-
1760-
$_ = $line;
1761-
}
1762-
1763-
1764-
# process a single line from an OUTPUT section
1765-
1766-
sub OUTPUT_handler_line {
1767-
my ExtUtils::ParseXS $self = shift;
1768-
my $line = shift;
1769-
1770-
return unless $line =~ /\S/; # skip blank lines
1771-
1772-
if ($line =~ /^\s*SETMAGIC\s*:\s*(ENABLE|DISABLE)\s*/) {
1773-
$self->{xsub_SETMAGIC_state} = ($1 eq "ENABLE" ? 1 : 0);
1774-
return;
1775-
}
1776-
1777-
# Expect lines of the two forms
1778-
# SomeVar
1779-
# SomeVar sv_setsv(....);
1780-
#
1781-
my ($outarg, $outcode) = $line =~ /^\s*(\S+)\s*(.*?)\s*$/s;
1782-
1783-
my ExtUtils::ParseXS::Node::Param $param =
1784-
$self->{xsub_sig}{names}{$outarg};
1785-
1786-
if ($param && $param->{in_output}) {
1787-
$self->blurt("Error: duplicate OUTPUT parameter '$outarg' ignored");
1788-
return;
1789-
}
1790-
1791-
if ($outarg eq "RETVAL" and $self->{xsub_seen_NO_OUTPUT}) {
1792-
$self->blurt("Error: can't use RETVAL in OUTPUT when NO_OUTPUT declared");
1793-
return;
1794-
}
1795-
1796-
if ( !$param # no such param or, for RETVAL, RETVAL was void
1797-
# not bound to an arg which can be updated
1798-
or $outarg ne "RETVAL" && !$param->{arg_num})
1799-
{
1800-
$self->blurt("Error: OUTPUT $outarg not a parameter");
1801-
return;
1802-
}
1803-
1804-
1805-
$param->{in_output} = 1;
1806-
$param->{do_setmagic} = $outarg eq 'RETVAL'
1807-
? 0 # RETVAL never needs magic setting
1808-
: $self->{xsub_SETMAGIC_state};
1809-
$param->{output_code} = $outcode if length $outcode;
1810-
1811-
if ($outarg eq 'RETVAL') {
1812-
# Postpone processing the RETVAL line to last (it's left to the
1813-
# caller to finish).
1814-
return;
1815-
}
1816-
1817-
$param->as_output_code($self);
1818-
}
1819-
1820-
18211746
sub FALLBACK_handler {
18221747
my ExtUtils::ParseXS $self = shift;
18231748
my ($setting) = @_;

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,89 @@ sub as_code {
30343034
}
30353035

30363036

3037+
# ======================================================================
3038+
3039+
package ExtUtils::ParseXS; # XXX tmp
3040+
3041+
# Process the lines following the OUTPUT: keyword.
3042+
3043+
sub OUTPUT_handler {
3044+
my ExtUtils::ParseXS $self = shift;
3045+
3046+
my $line = shift;
3047+
3048+
# In this loop: process each line until the next keyword or end of
3049+
# paragraph
3050+
3051+
for (; $line !~ /^$ExtUtils::ParseXS::BLOCK_regexp/o; $line = shift(@{ $self->{line} })) {
3052+
$self->OUTPUT_handler_line($line);
3053+
} # foreach line in OUTPUT block
3054+
3055+
$_ = $line;
3056+
}
3057+
3058+
3059+
# ======================================================================
3060+
3061+
package ExtUtils::ParseXS; # XXX tmp
3062+
3063+
# process a single line from an OUTPUT section
3064+
3065+
sub OUTPUT_handler_line {
3066+
my ExtUtils::ParseXS $self = shift;
3067+
my $line = shift;
3068+
3069+
return unless $line =~ /\S/; # skip blank lines
3070+
3071+
if ($line =~ /^\s*SETMAGIC\s*:\s*(ENABLE|DISABLE)\s*/) {
3072+
$self->{xsub_SETMAGIC_state} = ($1 eq "ENABLE" ? 1 : 0);
3073+
return;
3074+
}
3075+
3076+
# Expect lines of the two forms
3077+
# SomeVar
3078+
# SomeVar sv_setsv(....);
3079+
#
3080+
my ($outarg, $outcode) = $line =~ /^\s*(\S+)\s*(.*?)\s*$/s;
3081+
3082+
my ExtUtils::ParseXS::Node::Param $param =
3083+
$self->{xsub_sig}{names}{$outarg};
3084+
3085+
if ($param && $param->{in_output}) {
3086+
$self->blurt("Error: duplicate OUTPUT parameter '$outarg' ignored");
3087+
return;
3088+
}
3089+
3090+
if ($outarg eq "RETVAL" and $self->{xsub_seen_NO_OUTPUT}) {
3091+
$self->blurt("Error: can't use RETVAL in OUTPUT when NO_OUTPUT declared");
3092+
return;
3093+
}
3094+
3095+
if ( !$param # no such param or, for RETVAL, RETVAL was void
3096+
# not bound to an arg which can be updated
3097+
or $outarg ne "RETVAL" && !$param->{arg_num})
3098+
{
3099+
$self->blurt("Error: OUTPUT $outarg not a parameter");
3100+
return;
3101+
}
3102+
3103+
3104+
$param->{in_output} = 1;
3105+
$param->{do_setmagic} = $outarg eq 'RETVAL'
3106+
? 0 # RETVAL never needs magic setting
3107+
: $self->{xsub_SETMAGIC_state};
3108+
$param->{output_code} = $outcode if length $outcode;
3109+
3110+
if ($outarg eq 'RETVAL') {
3111+
# Postpone processing the RETVAL line to last (it's left to the
3112+
# caller to finish).
3113+
return;
3114+
}
3115+
3116+
$param->as_output_code($self);
3117+
}
3118+
3119+
30373120
# ======================================================================
30383121

30393122

0 commit comments

Comments
 (0)