3

We have some multi level evals, where the passing parameters do not reveal much if it fails, I'm hoping I can get access of the Carp::longmess() parameters passed at higher levels because the dump is really all I have.

[DEBUG:2564] 2013/10/07 12:54:06 /opt/s3/server/S3Comparator.pm:183 - compare() - stacktrace: at (eval 1312) line 2.
S3AIHelper::__ANON__('S3TransISO8583=HASH(0x1696eb10)') called at /opt/s3/server/S3AIHelper.pm line 777
S3AIHelper::match_fields('S3TransISO8583=HASH(0x1696eb10)', 'HASH(0x168dc750)', '') called at /opt/s3/server/S3AIHelper.pm line 177
S3AIHelper::fieldhits('S3TransGroup=HASH(0x16953d10)', 'HASH(0x168dc750)', '') called at (eval 1081) line 90

it looks like this after parsing:

my $value = 'S3TransISO8583=HASH(0x1696eb10)';

How do I get this to become an S3TransISO8583 object with the content fully intact. I will do this in the same running instance, so the memory addresses are valid.

Thanks

MortenB
  • 2,749
  • 1
  • 31
  • 35
  • Related: http://stackoverflow.com/questions/1671281/how-can-i-convert-the-stringified-version-of-array-reference-to-actual-array-ref – RobEarl Oct 07 '13 at 12:04

1 Answers1

5

In Carp, all arguments are forcibly stringified. But this is Perl, and we can work around that – by monkey patching the Carp::format_arg sub.

Basically, this would look like:

BEGIN {
    use Data::Dump 'dump';  # nicer output than Data::Dumper

    my $orig = \&Carp::format_arg;

    *Carp::format_arg = sub {
        my ($arg) = @_
        @_ = (dump $arg);
        goto &$orig;
    };
}

See also this answer of mine which explains a similar hack in more detail.

Community
  • 1
  • 1
amon
  • 57,091
  • 2
  • 89
  • 149
  • Thanks - I get the warning trying to write to a readonly variable for the line '$_[0] = dump $arg;' but I get your stringify example to work – MortenB Oct 07 '13 at 15:00
  • @MortenB Couldn't reproduce your problem, but it should be fixed now. – amon Oct 07 '13 at 16:26