Debian Codegraph @

examples/as_ascii

raw
1 #!/usr/bin/perl -w
2
3 #############################################################################
4 # This example is a bit outdated, please use the new bin/graph-easy script -
5 # which is after "make install" available on any command line in your system.
6
7 # Convert an input file containing a Graph::Easy description to
8 # ASCII art.
9
10 # Example usage:
11 # examples/as_ascii t/in/2nodes.txt
12 # echo "[ A ] -> [ B ]" | examples/as_ascii
13
14 BEGIN { $|++; }
15
16 use lib 'lib';
17 use Graph::Easy::Parser;
18
19 my $file = shift;
20 my $id = shift || '';
21 my $debug = shift;
22
23 my $parser = Graph::Easy::Parser->new( debug => $debug );
24
25 if (!defined $file)
26 {
27 $file = \*STDIN;
28 binmode STDIN, ':utf8' or die ("binmode STDIN, ':utf8' failed: $!");
29 }
30 binmode STDERR, ':utf8' or die ("binmode STDERR, ':utf8' failed: $!");
31 my $graph = $parser->from_file( $file );
32
33 die ($parser->error()) unless defined $graph;
34
35 $graph->id($id);
36 $graph->timeout(360);
37 $graph->layout();
38
39 warn($graph->error()) if $graph->error();
40
41 binmode STDOUT, ':utf8' or die ("binmode STDOUT, ':utf8' failed: $!");
42 print $graph->as_ascii();
43