App-karr
view release on metacpan or search on metacpan
lib/App/karr/Dispatch.pm view on Meta::CPAN
# recorded.
set_original_argv(@ARGV);
# Inside the eval on purpose: the "Usage error:" marker is what
# App::karr::Error::is_usage_error keys on, so the handler below turns this
# into exit 2 through the same path as every other usage error.
my $ran = eval { _refuse_empty_argument(); _normalize_option_argv(); App::karr->new_with_cmd; 1 };
if ( !$ran ) {
my $err = $@;
# An embedding host's exit-signal (see EMBEDDING) is not a command that
# died: hand it back rather than classifying it. Nothing in karr's own
# code answers this, so under bin/karr -- where exit() really exits and
# never reaches this eval -- it never fires.
die $err if blessed($err) && $err->can('__karr_dispatch_exit');
# Exit-code contract (ADR 0002): 0 success / 1 runtime failure / 2 usage
# error. This is the central handler the ADR calls for: it catches every
# uncaught die from a command body and turns it into a deterministic 1
# or 2, replacing the accidental 255 an uncaught die used to leak.
#
lib/App/karr/Dispatch.pm view on Meta::CPAN
dashed-option normalisation), and the central handler that turns an uncaught
C<die> into the exit-code contract (ADR 0002). This module is that code, moved
out whole so the F<karr> executable and the in-process test runner
(F<t/lib/TestKarr.pm>) share B<one> dispatch path rather than two copies that
drift.
L</dispatch> does exactly what F<bin/karr> used to do inline. F<bin/karr> is now
a thin wrapper that calls it (and keeps the END block that flushes
L<App::karr::SyncGuard>, which is a process-lifecycle concern -- see there).
=head1 EMBEDDING
An embedding host may run L</dispatch> many times in one interpreter -- the
in-process test runner does, to skip ~0.3s of Perl startup per C<karr> call.
Such a host installs, in a C<BEGIN> block before L<App::karr> is compiled, an
override of C<CORE::GLOBAL::exit> that raises an exception instead of tearing
the whole interpreter down. karr reaches C<exit> from three places -- this
module's handler, L<App::karr::Role::ExitCodes>, and L<App::karr/_print_help> --
and the override catches all three.
So that L</dispatch>'s own handler does not mistake such an exit-signal for a
lib/App/karr/Dispatch.pm view on Meta::CPAN
=head2 dispatch
dispatch(@ARGV);
Runs one C<karr> invocation: sets up the character/octet boundary, records the
caller's argv, applies the empty-argument (#243) and dashed-option (#256)
rewrites, and calls C<< App::karr->new_with_cmd >> inside the central
exit-code handler (ADR 0002). Operates on a localised C<@ARGV>. Returns nothing
on success; on failure it prints the message to C<STDERR> and C<exit>s C<1> or
C<2> -- which, under an embedding host that overrides C<exit> (see
L</EMBEDDING>), becomes the host's exit-signal instead.
=head1 SEE ALSO
L<karr>, L<App::karr>, L<App::karr::Error>, L<App::karr::Encoding>,
L<App::karr::SyncGuard>
=head1 SUPPORT
=head2 Issues
( run in 0.737 second using v1.01-cache-2.11-cpan-8dfa8b56332 )