{
1;
}
- elsif (defined(&overload::StrVal))
- {
- if ($in_recurse ||
- !do {
- local $@;
- local $in_recurse = 1;
- local $SIG{__DIE__} = sub{};
- eval {
- $arg = "$arg";
- 1;
- }
- }) {
- $arg = overload::StrVal($arg);
- }
- }
else
{
- $arg = "$arg";
+ $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg";
}
}
if ( defined($arg) ) {
data types, such as objects and other references, this can simply
display C<'HASH(0x1ab36d8)'>.
-Carp gives three ways to control this.
+Carp gives two ways to control this.
=over 4
This variable is expected to be a code reference, and the current parameter
is passed in. If this function doesn't exist (the variable is undef), or
it recurses into C<Carp>, or it otherwise throws an exception, this is
-skipped, and Carp moves on to the next option, otherwise checking stops
+skipped, and Carp moves on to the next option, otherwise checking stops
and the string returned is used.
-=item 3.
-
-The reference is stringified. If overloading is being used on the object,
-that overloading is called. If that overload recurses into C<Carp>, or it
-otherwise throws an exception, this is skipped, and Carp moves on to the next
-option, otherwise checking stops and the string returned is used.
-
-=item 4.
+=item 3
-To get this far, L<overload> must be loaded because the object failed
-to stringify normally. L<overload>::StrVal is called to stringify the
-object without any overloading to produce a value where all of the above
-has failed.
+Otherwise, if neither C<CARP_TRACE> nor C<$Carp::RefArgFormatter> is
+available, stringify the value ignoring any overloading.
=back
use warnings;
no warnings 'once';
-use Test::More 0.98 tests => 10;
+use Test::More 0.98 tests => 7;
use Carp;
my $o = Stringable->new(key => 'Baz');
my $msg = call(\&with_longmess, $o, {bar => 'buzz'});
-like($msg, qr/'Stringable=Baz'/, "Stringable object stringified");
+like($msg, qr/'Stringable=HASH\(0x[[:xdigit:]]+\)'/,
+ "Stringable object not overload stringified");
like($msg, qr/'HASH\(0x[[:xdigit:]]+\)'/, "HASH *not* stringified");
{
like($msg, qr/'TRACE:CarpTracable=Bax'/, "CARP_TRACE output used") or diag explain $msg;
like($msg, qr/'HASH\(0x[[:xdigit:]]+\)'/, "HASH not stringified again");
-{
- my @warn;
- local $SIG{__WARN__} = sub { push @warn, "@_" };
- $o = CarpBad->new(key => 'Zoo');
- $msg = call(\&with_longmess, $o, {bar => 'kill'});
- like($msg, qr/THIS CAN NOW HAPPEN|Zoo/, "Didn't get the as-string version");
- like($warn[0], qr/this is now allowed/, "check warning produced");
- @warn = ();
-
- $o = CarpBad2->new(key => 'Apple');
- $msg = call(\&with_longmess, $o, {bar => 'kill'});
- like($msg, qr/CarpBad2=HASH/,"Normal non-overload string conversion");
-}
-
sub call
{
my $func = shift;
"TRACE:" . $self; # use string overload
}
-package CarpBad;
-
-use parent -norequire => 'Stringable';
-
-sub as_string
-{
- Carp::cluck("this is now allowed");
- "THIS CAN NOW HAPPEN";
-}
-
-package CarpBad2;
-
-use parent -norequire => 'Stringable';
-
-sub as_string
-{
- confess("this should fallback");
- "THIS SHOULD NEVER HAPPEN";
-}