The following examples refer to my wiki-node a quick and dirty Wiki - but the code is quite easy to transfer to all kind of webapps.

If you debug CGIs you've possbily utilized sometimes something like this:

use CGI::Carp qw/fatalsToBrowser/; use Data::Dumper # yada yada yada die Dumper $form; # or some other data-structure

This works fine and I used it quite often. But sometimes it would be cool to have a more vizualized output (even if you just want to impress your coworkers/boss). There is a cool module for this on cpan called GraphViz::Data::Grapher - but how can you use it in your CGI?

# this is part of the actions-dispatch of my wiki-project 'debug' => sub { use MIME::Base64; use GraphViz::Data::Grapher; my $debug_wiki; while (my ($k, $v) = each %$wiki) { $debug_wiki->{$k} = substr($v, 0, 20).' ...'; } my $graph = GraphViz::Data::Grapher->new($debug_wiki); return $q->header(), $q->start_html('DEBUG'), '<IMG SRC="data:image/png;base64,', encode_base64($graph->as_png), '" alt="debug"/>', $q->end_html; },

Alternatively I could have dumped $q->form or something else. The trick is to use base64-encoding as described in this RFC (The "data" URL scheme) http://www.ietf.org/rfc/rfc2397.txt to embed the GraphViz-dump in your html. This doesn't work for IE-users and beside that it isn't a good idea to try to dump bigger amounts of data this way.

Wiki-analyzing

I wanted to know which nodes in my wiki refer to other nodes. GraphViz::Data::Grapher won't do the trick but GraphViz (http://www.research.att.com/sw/tools/graphviz/) and the GraphViz - module are still the right tools for this. If you've read my wiki-node you know that I've put the whole wiki in a simple hash-ref. It's easy to build a graph out of this structure:

# this is part of the actions-dispatch of my wiki-project 'analyze' => sub { use GraphViz; use MIME::Base64; my $g = GraphViz->new(); $g->add_node($_) for keys %$wiki; while (my ($k, $v) = each %$wiki) { $g->add_edge($k => $_) for ($v =~ /$wikiwords/g); } return $q->header(), $q->start_html('ANALYZE'), '<IMG SRC="data:image/png;base64,', encode_base64($g->as_png), '" alt="debug"/>', $q->end_html; }
As you see it's also just a few lines of code but you get a real cool picture of the relations within the wiki.

I hope you like it and maybe you've now some cool ideas of what you want to vizualize in your next webapp.


In reply to Graphical debugging of WebApps (and analyzing Wikis) by neniro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.