Skip to content

Document that Mojolicious::Lite sets the default Mojo::UserAgent::Server app - #2334

Open
hikmetba-bit wants to merge 1 commit into
mojolicious:mainfrom
hikmetba-bit:docs/2283-lite-sets-ua-server-app
Open

hikmetba-bit wants to merge 1 commit into
mojolicious:mainfrom
hikmetba-bit:docs/2283-lite-sets-ua-server-app

Conversation

@hikmetba-bit

Copy link
Copy Markdown

Summary

Fixes #2283.

Mojolicious::Lite::import() has always contained:

# Make sure there's a default application for testing
Mojo::UserAgent::Server->app($app) unless Mojo::UserAgent::Server->app;

which makes the first Mojolicious::Lite app loaded in a process become the process-wide default for Mojo::UserAgent::Server, so relative URLs passed to Mojo::UserAgent reach it automatically.

As the reporter found, this was previously undocumented in Mojolicious::Lite, Mojo::UserAgent, or Mojo::UserAgent::Server's POD (I confirmed this by grepping all three before writing anything). It's a genuinely useful behavior, but also a real gotcha they pointed out: if a third-party module loads Mojolicious::Lite before your own application does, Mojo::UserAgent::Server->app may already point at that module's app instead of yours, since it's a process-wide, load-order-dependent global.

Change

Added a short note to:

  • Mojolicious::Lite's DESCRIPTION, right after the existing SYNOPSIS/tutorial pointer.
  • Mojo::UserAgent::Server's app method POD, where the reporter specifically looked and found nothing.

Both cross-reference each other.

Verification

Documentation-only change. Verified by reading the exact code path (Mojolicious::Lite::import(), the unless Mojo::UserAgent::Server->app guard) that performs this behavior, and confirming with grep -rn "UserAgent::Server" lib/Mojolicious/Lite.pm lib/Mojolicious.pm lib/Mojo/UserAgent/Server.pm that it was genuinely undocumented before this change. No test suite run needed for a POD-only change (nothing here changes runtime behavior).

🤖 Generated with Claude Code

…ver app

Fixes mojolicious#2283. Mojolicious::Lite::import() has always contained:

  # Make sure there's a default application for testing
  Mojo::UserAgent::Server->app($app) unless Mojo::UserAgent::Server->app;

which makes the first Mojolicious::Lite app loaded in a process become
the process-wide default for Mojo::UserAgent::Server, so relative URLs
passed to Mojo::UserAgent reach it. This was previously undocumented
in Mojolicious::Lite, Mojo::UserAgent or Mojo::UserAgent::Server's POD
(confirmed by grepping all three), which is surprising and, as the
reporter noted, can be a real gotcha: if a third-party module loads
Mojolicious::Lite before your own application does, the global
default may already point at that module's app instead of yours.

Added a note to Mojolicious::Lite's DESCRIPTION and to
Mojo::UserAgent::Server's "app" method POD, cross-referencing each
other.

Verification: documentation-only change, verified by reading the
exact code path (Mojolicious/Lite.pm's import()) that performs this
behavior, and confirming (via grep) it was genuinely undocumented
before this change. No test suite run needed for a POD-only change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kraih

kraih commented Sep 19, 2026

Copy link
Copy Markdown
Member

Afraid we do not accept PRs with a Co-Authored-By an AI agent. You may of course use AI assistants, but a human has to take full responsibility for the patch.

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.

Document somewhere that Mojolicious::Lite initializes Mojo::UserAgent::Server.

2 participants