Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found