Skip to content

Conversation

@NetcraftPm
Copy link

Previously, we were not able to match use base ("Package1", "Package2");.
This style is used extensively by OpenAPI Generator
(https://openapi-generator.tech).

As a result, all Perl code generated by this tool fails to install the correct
dependencies when using perl-generators in the specfile.

With this change, we check for a single- or double-quoted array (as opposed
to the current lexing of qw arrays) following a use X statement, and parse
this into the $list scalar, stripping out quotes, splitting on quotes and
joining on commas, to keep the same format that $list currently uses.

Tested locally (albeit with some hackery to make packages load correctly in the tests):

[penn@penn template (penn/use-base-unquoted-array)]$ prove -I lib -r t
t/01_basic.t ................ ok
t/02_list.t ................. ok
t/03_anymoose.t ............. ok
t/04_provides.t ............. ok
t/05_whitespace.t ........... ok
t/06_variables.t ............ ok
t/07_multiline.t ............ ok
t/08_heredoc.t .............. ok
t/09_perl_versions.t ........ ok
t/10_filename_with_space.t .. ok
t/test.t .................... ok
All tests successful.
Files=11, Tests=23,  1 wallclock secs ( 0.06 usr  0.02 sys +  0.94 cusr  0.29 csys =  1.31 CPU)
Result: PASS

Previously, we were not able to match `use base ("Package1", "Package2");`.
This style is used extensively by OpenAPI Generator
(https://openapi-generator.tech).

As a result, all Perl code generated by this tool fails to install the correct
dependencies when using perl-generators in the specfile.

With this change, we check for a single- or double-quoted array (as opposed
to the current lexing of qw arrays) following a `use X` statement, and parse
this into the $list scalar, stripping out quotes, splitting on quotes and
joining on commas, to keep the same format that $list currently uses.
@jplesnik
Copy link
Owner

Thanks for the PR. I tried to apply the patch and rebuild all packages which use base. I found some problems.

The package perl-SVK contains following code in file SVK-v2.2.3/lib/SVK/Inspector/Root.pm

use base qw {
        SVK::Inspector
};

which ends with this change found by rpmdiff

### perl-SVK-2.2.3-44
removed     REQUIRES perl(SVK::Inspector)
added       REQUIRES SVK::Inspector)
added       REQUIRES perl(

perl-Prima
code in Prima-1.76/Prima/InputLine.pm

use base qw(
        Prima::Widget
        Prima::Widget::Fader
        Prima::Widget::BidiInput
        Prima::Widget::MouseScroller
        Prima::Widget::UndoActions
);

code in Prima-1.76/Prima/Edit.pm

use base qw(
        Prima::Widget Prima::Widget::MouseScroller Prima::Widget::GroupScroller
        Prima::Widget::UndoActions Prima::Widget::BidiInput
);

code in Prima-1.76/Prima/Sliders.pm

use base qw(
        Prima::AbstractSlider
        Prima::Widget::Fader
);

changes

removed     REQUIRES perl(Prima::Widget::BidiInput)
removed     REQUIRES perl(Prima::Widget::ListBoxUtils)
removed     REQUIRES perl(Prima::Widget::UndoActions)
added       REQUIRES Prima::AbstractSlider)
added       REQUIRES Prima::Widget)
added       REQUIRES Prima::Widget::BidiInput)
added       REQUIRES Prima::Widget::Fader)
added       REQUIRES Prima::Widget::GroupScroller)
added       REQUIRES Prima::Widget::ListBoxUtils)
added       REQUIRES Prima::Widget::MouseScroller)
added       REQUIRES Prima::Widget::UndoActions)
added       REQUIRES Prima::Widget::UndoActionsPrima::Widget::BidiInput)
added       REQUIRES Prima::WidgetPrima::Widget::MouseScrollerPrima::Widget::GroupScroller)
added       REQUIRES perl(

Could you please check it?

@NetcraftPm
Copy link
Author

NetcraftPm commented Jun 18, 2025

Thanks for spotting this case!

It appears that this behaviour stems from the presence of tab characters in the source files, as I was able to reproduce a minimal example using Requires: perl( a).

The existing code for handling qw{ blocks uses chomp which doesn't strip leading whitespace either, so I didn't add a case to handle this. However, when switching to using an array to store the import list, my changes are incorrectly only matching on spaces (and the regex also seems to be missing a ^, which is unrelated). Previously we were splitting with split(' ', $list) which hit a special case that I didn't notice:

As another special case, split emulates the default behavior of the command line tool awk when the PATTERN is either omitted or a string composed of a single space character (such as ' ' or "\x20", but not e.g. / /). In this case, any leading whitespace in EXPR is removed before splitting occurs, and the PATTERN is instead treated as if it were /\s+/; in particular, this means that any contiguous whitespace (not just a single space character) is used as a separator.

Therefore the solution is to strip all leading and trailing whitespace from each element of @list. I'll validate these changes and push a fix shortly.

The existing code stores the arguments of various statements into $list as
a space-separated scalar. It's much cleaner to store this as an array, so we now do that instead.
Handling tabs and spaces is tricky, especially around in the complex
logic that surrounds use base qw{ stuff };
@NetcraftPm NetcraftPm force-pushed the penn/use-base-unquoted-array branch from d031391 to 36c9c00 Compare June 18, 2025 13:07
@NetcraftPm
Copy link
Author

Hi @jplesnik, I think I've fixed the issues you identified as well as a few things we found internally. Please do let me know if there's anything else needed to get this merged 😄

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.

2 participants