Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: overload and the perl debugger (StrVal)

by tye (Sage)
on Aug 27, 2007 at 14:43 UTC ( [id://635309]=note: print w/replies, xml ) Need Help??


in reply to overload and the perl debugger

overload::StrVal($var)

Update: I figured that'd be XS code and so wouldn't trigger DB::sub, but it is actually this rather simple Perl code (from overload.pm):

sub AddrRef { my $package = ref $_[0]; return "$_[0]" unless $package; require Scalar::Util; my $class = Scalar::Util::blessed($_[0]); my $class_prefix = defined($class) ? "$class=" : ""; my $type = Scalar::Util::reftype($_[0]); my $addr = Scalar::Util::refaddr($_[0]); return sprintf("$class_prefix$type(0x%x)", $addr); }

So you can just use that same technique yourself. Yes, reftype() and refaddr() are XS unless Scalar::Util fails to load its XS component, in which case it uses the Perl replacements found in Util.pm, which you could also copy (they rebless to avoid overload magic).

- tye        

Replies are listed 'Best First'.
Re^2: overload and the perl debugger (StrVal)
by diotalevi (Canon) on Aug 27, 2007 at 15:44 UTC

    There's little sense in copying out of overload.pm - that module is core and is always available.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      For one, "core" does not actually mean "always available". For another, copying what boils down to two lines of code isn't something I sweat much about.

      But, perhaps most importantly, if one can't even use "$x" because it calls a subroutine, then I'm not sure one can, um, call a subroutine. I haven't tried to write a debugger but perldebguts says:

      When execution of the program reaches a subroutine call, a call to &DB::sub(args) is made instead, with $DB::sub holding the name of the called subroutine. (This doesn't happen if the subroutine was compiled in the DB package.)

      (emphasis added). So I think you might need to recompile those couple of lines of code into a different package in this case.

      And I wouldn't be surprised if understanding the few key concepts presented in those several lines of code from the 3 subroutines wouldn't lead to a better way to integrate the concepts into the OP's code then would be possible by just calling those routines.

      - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://635309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-03-28 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found