Skip to content

perl doc: a correctly-closed POD block counts twice (=pod + =cut) — the #2658 delimiter shape #2670

Closed

Description

@squid-protocol

Found while fixing the keyword-rosetta corpus's perl shell (gitgalaxy#2669 A.3).

The rule

"doc": re.compile(r"^=(?:pod|head[1-6]|item|over|back|cut|begin|end|encoding|for)\b", re.M)

=cut is in the same alternation as the openers, and nothing pairs them. A correctly written
POD block therefore always counts at least 2 doc hits:

=pod
some documentation
=cut          # <- counted as a second, independent doc hit

This is exactly the shape #2658 fixed for python (""" opener and closer counted separately with
no pairing) — resolved there by matching the full delimited span as one bounded hit.

Differential (real scan, full_precision, engine main @ 3ac9182)

keyword-rosetta data/perl/main.pl, one line added and nothing else changed:

main.pl doc
=pod … (unterminated) 1
=pod … =cut 2

Every other recorded signal is identical across the two scans.

Why it is not just a counting nit

The corpus's perl shell had been left with an unterminated =pod — the only way to get
doc = 1 — and that turned out to be masking a much larger effect, because
detector.py (~L3042, the #2239 POD strip) blanks from a POD opener to the next =cut, or to
end of file when there is none:

m_end = pod_end.search(safe_code, m_start.start())
end_idx = m_end.end() if m_end else len(safe_code)

So the whole of main.pl was blanked for structural scanning. Closing the block restores it:

main.pl before (=pod unterminated) after (=pod … =cut)
avg_func_loc 0.0 6.75
avg_func_complexity 0.0 0.75
func_internal_density 0.0 0.111
structural_mass 104.52 11.9 (siblings: 8.3 / 11.44 / 9.36)

Corpus-wide that was functions_found 9 vs a 13 median for perl, and it is the direct cause of
perl's depressed avg_func_loc (-27%), avg_func_complexity (-38%), max_func_complexity
(-50%), func_complexity_gini (-53%), func_internal_density (-49%) and control_flow_ratio
(-40%) cells, plus structural_mass +212%.

The corpus side is fixed (the POD block is now closed). What is left here is the doc double-count.

Suggested fix

Same shape as #2658: pair the opener with its =cut and count the span once. Note the
end-of-file fallback above is a second, related question — a file with an unterminated POD
opener silently loses all structure after it, with no warning; worth deciding whether that
should stay silent.

Cross-repo

Activity

  1. added
    bug
    metrics
    core-engine
    on Sep 2, 2026
  2. squid-protocol commented on Sep 2, 2026

    @squid-protocol
    OwnerAuthor

    Member of the doc-delimiter family filed as #2672 (Batch B.1 of #2669) — the perl POD case is =pod/=cut in the same shape as java/groovy/kotlin/php/scala /**+@param and solidity ///+@param. Fix shape and prototype evidence live there; #2672 should close this one with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginemetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions