When testing a large Web application written in Perl, you should probably not have instances of Foo::Bar=HASH(0x8100664) in the Web source. If those are not visible (e.g., in hidden form elements or in option values), they can be tough bugs to track down. The following snippet will warn if they are detected. You may need to strengthen the regular expression, depending on your needs.

package WWW::Mechanize::NoRefs; use base 'WWW::Mechanize'; use Carp; sub content { my $self = shift; my $content = $self->SUPER::content; if ($content =~ /([\w=:]+\(0x[a-fA-F0-9]+\))/) { carp "Possible stringified reference ($1) found in content"; } return $content; } 1;

Replies are listed 'Best First'.
Re: Detecting stringified references with WWW::Mechanize
by liz (Monsignor) on Jan 08, 2004 at 22:33 UTC
    I like the idea.

    I wonder whether a similar function could be written as a mod_perl 2 filter, logging pertinent information at a specific place for easy perusal by developers.

    The disadvantage of the approach with WWW::Mechanize is that you have to guess the "real live" settings, whereas a filter approach would be run automaticaly for as long as you enable the filter.

    Liz

      I use a similar thing for my pages that served with Apache::PageKit there is a easy content filter for every page. I feed it to tidy and get more output as I want. ;-)
Re: Detecting stringified references with WWW::Mechanize
by Aristotle (Chancellor) on Jan 10, 2004 at 21:10 UTC
    Very nice. As always, it should be noted that relying on the stringification of references may lead to surprises if overloading has been brought into play. Also, with a more specific pattern:
    package WWW::Mechanize::NoRefs; use base 'WWW::Mechanize'; my $rx = qr/( (?: [A-Za-z]\w* (?: :: [A-Za-z]\w* )* = )? (?: SCALAR | ARRAY | HASH | CODE | REF | GLOB | LVALUE ) \( 0x [a-fA-F0-9]+ \) )/x; sub content { my $self = shift; my $content = $self->SUPER::content; if ($content =~ $rx) { require Carp; Carp::carp("Possible stringified reference ($1) found in conte +nt"); } return $content; } 1;

    Makeshifts last the longest.