File: as_graphviz

package info (click to toggle)
libgraph-easy-as-svg-perl 0.28-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 304 kB
  • sloc: perl: 1,924; makefile: 7
file content (30 lines) | stat: -rwxr-xr-x 733 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env perl

# Convert an input file containing a Graph::Easy description to
# graphviz output that can be feed to dot etc.

# Example usage:
#  examples/as_graphviz t/in/2nodes.txt | dot -Tpng >test.png
#  echo "[ A ] -> [ B ]" | examples/as_graphviz | dot -Tpng >test.png

BEGIN { $|++; }

use strict;
use lib 'lib';
use Graph::Easy::Parser;

my $file = shift;

my $parser = Graph::Easy::Parser->new( debug => 0 );

if (!defined $file)
  {
  $file = \*STDIN;
  binmode STDIN, ':utf8' or die ("binmode STDIN, ':utf8' failed: $!");
  }
my $graph = $parser->from_file( $file );

die ($parser->error()) unless defined $graph;
binmode STDOUT, ':utf8' or die ("binmode STDOUT, ':utf8' failed: $!");
print $graph->as_graphviz();