fix: ignore build()/initialize() return value in constructor#35
Draft
Koan-Bot wants to merge 1 commit into
Draft
fix: ignore build()/initialize() return value in constructor#35Koan-Bot wants to merge 1 commit into
Koan-Bot wants to merge 1 commit into
Conversation
build() ending with a falsy expression (e.g. $self->count(0)) silently aborted construction — new() returned undef. This contradicts Perl OO convention: Moose and Moo both ignore BUILD's return value. To abort construction, users should throw an exception instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Constructor no longer aborts when
build()orinitialize()returns a falsy value.Why
build()commonly ends with a setter call like$self->count(0). The setter returns the stored value (0), which is falsy. The old code hadreturn unless $self->$init(%opts), causingnew()to silently returnundef. This contradicts Perl OO convention — both Moose and Moo ignoreBUILD's return value. To abort construction, users shoulddie.How
Replaced
return unless $self->$init(%opts)with$self->$init(%opts)— a one-line fix. Exception propagation still works (die in build() still kills construction).Testing
t/18-build-return-value.t(16 tests): covers build/initialize returning 0, empty string, undef; _after_build firing correctly; die still propagating.t/05-coverage.tandt/11-build-precedence.tto match new semantics.🤖 Generated with Claude Code
Quality Report
Changes: 4 files changed, 161 insertions(+), 16 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline