# dump-memory: Interchange low-level memory dump tool for debugging
# by Jon Jensen <jon@endpointdev.com>
#
# To use:
#
# 1. Put this in interchange.cfg and restart.
#
# 2. Then go to /dump-memory with any of your catalog URLs.
#
# 3. You'll get back a very large text file with a dump of the Global::*
# and %$Vend::Cfg namespaces as they actually exist in memory, which is
# the same in many respects as the interchange.structure and
# $catalog.structure dumps, but differs in some important respects as well.
#
# 4. Do *not* leave this in place on a production server accessible to the
# general public, because you will likely be exposing confidential
# information. Run it preferably only on a development machine, firewalled
# from the outside world, or in the worst case on a production server
# temporarily under a different ActionMap name or with web server access
# control to the URL.

UserTag dump-memory Routine <<EOR
sub {
    my %global;
    @global{keys %Global::} = map { ${$Global::{$_}} } keys %Global::;
    my %structure = (
        global => \%global,
        catalog => $Vend::Cfg,
    );  
    return ::uneval(\%structure);
}
EOR

ActionMap dump-memory <<EOR
sub {
    $Document->header('Content-Type: text/plain');
    $Document->hot(1);
    HTML(
        '# '
        . $Tag->time
        . "\n"
        . $Tag->dump_memory
    );  
    return 0;
}
EOR
