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

Pod html refactoring 2 of 5 #18950

Merged
merged 16 commits into from Jul 6, 2021
Merged

Conversation

jkeenan
Copy link
Contributor

@jkeenan jkeenan commented Jun 29, 2021

This is the second of two five pull requests in support of #18894. These p.r.s are intended to make the internals of Pod-Html less messy. Ultimately Pod::Html will hold a series of methods calls on an object. In this commit we start to gather together most of the loose lexical variables holding state into an object. We also move auxiliary functions into a package of their own.

@jkeenan jkeenan self-assigned this Jun 29, 2021
@jkeenan jkeenan requested a review from rjbs July 2, 2021 13:06
Copy link
Member

@rjbs rjbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a lot of my comments are about style. Because this commit has moved a lot of code (which is good!) a lot of it looks like new code, and I tend to provide "the style is not consistent" to new code. But I know you didn't write all this new code, so ignoring style nits to move the structural improvements forward makes sense.

On the other hand, I did make a few comments that should be addressed, especially about $Podroot and eval.

Mostly: looks great!

MANIFEST Outdated Show resolved Hide resolved
Makefile.SH Show resolved Hide resolved
ext/Pod-Html/lib/Pod/Html.pm Outdated Show resolved Hide resolved
ext/Pod-Html/lib/Pod/Html.pm Outdated Show resolved Hide resolved
ext/Pod-Html/lib/Pod/Html.pm Show resolved Hide resolved
ext/Pod-Html/lib/Pod/Html/Auxiliary.pm Outdated Show resolved Hide resolved
if( $dirs[0] ) {
unshift @dirs, $vol;
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, another style nit: why is this not cuddled, when many/most others are? (I will comment on the style items entirely at the end of my review.)

ext/Pod-Html/lib/Pod/Html/Auxiliary.pm Outdated Show resolved Hide resolved

# Find the line with the least amount of indent, as that's our "base"
my @indent_levels = (sort(map { $_ =~ /^( *)./mg } @$para));
my $indent = $indent_levels[0] || "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this mechanism confusing. I suppose it relies on the fact that two spaces sorts before three spaces, which is not something that I find obvious. (I've never been good with less trivial string sorts, though.) I wonder if this would be clearer with a comment, anyway.

# Extract leading runs of spaces from each line, then sort these runs.
# Shorter strings will sort before longer strings (when they're all one
# character), so we can just take the first one as the shortest indent
# prefix.  If there's none, default to an empty string, just to avoid
# uninitialized warnings.
my ($indent) = sort(map { $_ =~ /^( *)./mg } @$para);
$indent //= "";

die("'run' element takes integer") unless $args->{run} =~ m/^\d+$/;

my @cachelines = ();
open my $IN, '<', $cache or die "Unable to open $cache for reading";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I echo my comments about capitalized variable names here.)

@jkeenan
Copy link
Contributor Author

jkeenan commented Jul 5, 2021 via email

jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 5, 2021
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 5, 2021
Remove superfluous assignment to @isa.

Per rjbs code review in Perl#18950
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 5, 2021
jkeenan added 16 commits July 6, 2021 01:08
A method to assist in debugging cache problems.

Should assist in resolving Perl#12271.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
Group all the "global" variables into a hashref $globals.  This variable
will be the return value of init_globals() within pod2html(), will be
passed through, and augmented by, parse_command_line() and then used
through the balance of pod2html().

In essence, so far this is just a renaming of variables.

Remove declarations of superseded variables.

Pass $globals to get_cache(), cache_key() and load_cache().
This package will hold helper subroutines used within the main package
or in tests.  They can be placed in a separate module and imported into
Pod::Html because they won't depend on having the globals passed as an
argument.  They will also be potentially independently testable.

Start with html_escape().

Move anchorify(), htmlify() to Auxiliary.pm.  Also _unixify -- now as unixify().

Move relativize_url() to Auxiliary.

Move usage() to Auxiliary.

Move trim_leading_whitespace to Auxiliary.

Move parse_command_line() to Auxiliary.

Keep porting tests happy. Increment $VERSION.  Run: ./perl -Ilib
regen/lib_cleanup.pl

anchorify.t, eol.t:  Correct excessive corrections.

Standardize setting of $VERSION.
We now start placing parts of sub pod2html() into separate subs so that
we reduce the length of pod2html(), making it more readable and
(ultimately) preparing for method calls.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
Signed-off-by: James E Keenan <jkeenan@cpan.org>
This clears up a bit of semantic confusion.  We were using one lexically
scoped variable -- my $parser -- to hold two different objects: one for
parsing input, one for writing output.  We can encapsulate the working
of the input parser to make the code more readable.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
Encapsulate! Encapsulate!

Signed-off-by: James E Keenan <jkeenan@cpan.org>
Encapsulate more code within pod2html(). The return value is for
convenience.  It's the setting inside $globals that counts.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
Further encapsulation of code to improve readability.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
Further encapsulation of code internal to pod2html().

At this point we face obstacles:  %Pages; $output.

Signed-off-by: James E Keenan <jkeenan@cpan.org>
Remove superfluous assignment to @isa.

Per rjbs code review in Perl#18950
@jkeenan jkeenan force-pushed the pod-html-refactoring-2-of-5 branch from 9322b29 to ca8c8b6 Compare July 6, 2021 01:08
@jkeenan jkeenan merged commit 6cc408b into Perl:blead Jul 6, 2021
@jkeenan jkeenan added the ext/Pod-Html issues in the blead-upstream Pod-Html distribution label Jul 6, 2021
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 6, 2021
Per rjbs code review in Perl#18950

Signed-off-by: James E Keenan <jkeenan@cpan.org>
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 6, 2021
Remove superfluous assignment to @isa.

Per rjbs code review in Perl#18950

Signed-off-by: James E Keenan <jkeenan@cpan.org>
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 6, 2021
Per rjbs code review in Perl#18950

Signed-off-by: James E Keenan <jkeenan@cpan.org>
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 6, 2021
Per rjbs code review in Perl#18950

Signed-off-by: James E Keenan <jkeenan@cpan.org>
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 6, 2021
Remove superfluous assignment to @isa.

Per rjbs code review in Perl#18950

Signed-off-by: James E Keenan <jkeenan@cpan.org>
jkeenan added a commit to jkeenan/perl5 that referenced this pull request Jul 6, 2021
Per rjbs code review in Perl#18950

Signed-off-by: James E Keenan <jkeenan@cpan.org>
thibaultduponchelle pushed a commit to thibaultduponchelle/perl5 that referenced this pull request Jul 9, 2021
thibaultduponchelle pushed a commit to thibaultduponchelle/perl5 that referenced this pull request Jul 9, 2021
Remove superfluous assignment to @isa.

Per rjbs code review in Perl#18950
thibaultduponchelle pushed a commit to thibaultduponchelle/perl5 that referenced this pull request Jul 9, 2021
@jkeenan jkeenan deleted the pod-html-refactoring-2-of-5 branch August 23, 2021 02:24
nicomen pushed a commit to nicomen/pumpkin-perl that referenced this pull request Oct 11, 2021
nicomen pushed a commit to nicomen/pumpkin-perl that referenced this pull request Oct 11, 2021
Remove superfluous assignment to @isa.

Per rjbs code review in Perl/perl5#18950
nicomen pushed a commit to nicomen/pumpkin-perl that referenced this pull request Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext/Pod-Html issues in the blead-upstream Pod-Html distribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants