Graph-Easy-Introspect
view release on metacpan or search on metacpan
script/graph_easy_introspect view on Meta::CPAN
#!/usr/bin/env perl
use strict ;
use warnings ;
use Getopt::Long ;
use JSON::PP ;
use Graph::Easy::Parser::Graphviz ;
use Graph::Easy ;
use Graph::Easy::Introspect ;
my $opt_json = 0 ;
my $opt_dtd = 0 ;
my $opt_grid = 0 ;
my $opt_cell_grid = 0 ;
my $opt_compact = 0 ;
my $opt_help = 0 ;
GetOptions
(
'json' => \$opt_json,
'dtd' => \$opt_dtd,
'grid' => \$opt_grid,
'cell-grid' => \$opt_cell_grid,
'compact' => \$opt_compact,
'help' => \$opt_help,
) or die "Usage: $0 [options] file.dot\n" ;
if ($opt_help)
{
print <<'HELP' ;
Usage: graph_easy_introspect [options] file.dot
Output format:
--json emit the AST as JSON
--dtd emit the AST via Data::TreeDumper
--compact suppress port and path detail; show only edge endpoints
Supplementary data (text mode: printed as sections; json/dtd: included in dump):
--grid include the rendered character grid
--cell-grid include the cell-grid lookup table
--help show this message
HELP
exit ;
}
my $file = shift or die "Usage: $0 [options] file.dot (--help for details)\n" ;
open my $fh, '<', $file or die "Cannot open $file: $!\n" ;
my $dot = do { local $/ ; <$fh> } ;
close $fh ;
my $parser = Graph::Easy::Parser::Graphviz->new ;
my $g = $parser->from_text($dot) ;
my $ast = $g->ast ;
die "Layout error: $ast->{error}\n" if exists $ast->{error} ;
my $grid = $g->ast_grid ;
my $cell_grid = $g->ast_cell_grid ;
if ($opt_dtd)
{
eval { require Data::TreeDumper } ;
die "--dtd requires Data::TreeDumper: $@\n" if $@ ;
my %dump = (%$ast) ;
$dump{grid} = $grid if $opt_grid ;
$dump{cell_grid} = $cell_grid if $opt_cell_grid ;
print Data::TreeDumper::DumpTree(\%dump, 'AST') ;
exit ;
}
if ($opt_json)
{
my %dump = (%$ast) ;
$dump{grid} = $grid if $opt_grid ;
$dump{cell_grid} = $cell_grid if $opt_cell_grid ;
print JSON::PP->new->pretty->canonical->encode(\%dump) ;
exit ;
}
# Graph::Easy default attribute values â suppressed unless overridden
my %GRAPH_DEFAULTS =
(
colorscheme => 'x11',
flow => 'south',
title => 'unnamed',
) ;
print_rendered($grid) if $opt_grid ;
print_graph($ast) ;
print "\n" ;
( run in 0.744 second using v1.01-cache-2.11-cpan-39bf76dae61 )