Skip to content

fix: ignore build()/initialize() return value in constructor#35

Draft
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/fix-build-return-value
Draft

fix: ignore build()/initialize() return value in constructor#35
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/fix-build-return-value

Conversation

@Koan-Bot

@Koan-Bot Koan-Bot commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

What

Constructor no longer aborts when build() or initialize() 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 had return unless $self->$init(%opts), causing new() to silently return undef. This contradicts Perl OO convention — both Moose and Moo ignore BUILD's return value. To abort construction, users should die.

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

  • New t/18-build-return-value.t (16 tests): covers build/initialize returning 0, empty string, undef; _after_build firing correctly; die still propagating.
  • Updated t/05-coverage.t and t/11-build-precedence.t to match new semantics.
  • All 403 tests pass.

🤖 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

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>
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