Skip to content

fix: add AUTOLOAD DESTROY guard, document digest_file_ctx#26

Draft
toddr-bot wants to merge 2 commits intomainfrom
koan.toddr.bot/modernize-and-fix-autoload
Draft

fix: add AUTOLOAD DESTROY guard, document digest_file_ctx#26
toddr-bot wants to merge 2 commits intomainfrom
koan.toddr.bot/modernize-and-fix-autoload

Conversation

@toddr-bot
Copy link
Copy Markdown

What

Add a DESTROY guard to prevent AUTOLOAD from catching implicit garbage collection calls, modernize Digest::file's Exporter usage, and document the exported-but-undocumented digest_file_ctx() function.

Why

  • AUTOLOAD DESTROY guard: Without an explicit sub DESTROY {}, Perl's garbage collection triggers AUTOLOAD, which attempts Digest->new("DESTROY") — a silent failure that can produce confusing error messages in edge cases. This is a well-known Perl best practice for any AUTOLOAD implementation.
  • digest_file_ctx undocumented: The function is exported via @EXPORT_OK but has no POD documentation, making it invisible to users reading the docs. The POD also incorrectly states "3 convenience functions" when there are 4.
  • Digest::file @isa modernization: Replace manual use Exporter (); @ISA = ... with use base 'Exporter' for clarity. Uses base (not parent) to preserve Perl 5.006 compatibility.

How

  • Added empty sub DESTROY {} in Digest.pm after AUTOLOAD
  • Replaced @ISA assignment with use base 'Exporter' in Digest::file
  • Added =item digest_file_ctx(...) to the POD with full documentation
  • Fixed function count in POD ("3" → "4")

Testing

  • Added test in t/digest.t: verifies Digest has explicit DESTROY method
  • Added tests in t/file.t: digest_file_ctx() returns correct class, feeds file content, croaks on missing file
  • All existing tests continue to pass

Also exists as gisle#13 (upstream).

🤖 Generated with Claude Code

toddr-bot and others added 2 commits April 15, 2026 08:52
Add empty DESTROY to Digest.pm to prevent AUTOLOAD from catching
implicit DESTROY calls during garbage collection.

Replace @isa with use parent in Digest::file — the last module still
using the legacy pattern.

Document digest_file_ctx() in POD — it was exported but undocumented.
Add tests for both changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
parent.pm was added in 5.10.1 but MIN_PERL_VERSION is 5.006.
base.pm is available since 5.004005 and consistent with
Digest::base's own POD example.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant