Skip to content

Instantly share code, notes, and snippets.

@ywatase
Last active August 29, 2015 14:11
Show Gist options
  • Save ywatase/e510f8c8c725a55c2096 to your computer and use it in GitHub Desktop.
Save ywatase/e510f8c8c725a55c2096 to your computer and use it in GitHub Desktop.
use strict;
use utf8;
use Plack::Request;
use Graph::Easy;
# cpanm Graph::Easy::As_svg;
my $body = <<END;
<!DOCTYPE html>
<html>
<body>
<h1>Graph::Easy sample</h1>
%s
</body>
</html>
END
sub svg {
my $graph = Graph::Easy->new;
$graph->add_edge('A','B');
$graph->add_edge('B','C');
$graph->add_edge('C','D');
$graph->add_edge('B','E');
$graph->add_edge('E','F');
$graph->add_edge('F','G');
$graph->add_edge('D','G');
$graph->as_svg; # Graph::Easy::As_svg
}
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $res = $req->new_response(200);
$res->body(sprintf $body, svg() );
$res->finalize;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment