1GraphViz2::Parse::STT(3U)ser Contributed Perl DocumentatiGornaphViz2::Parse::STT(3)
2
3
4
6 GraphViz2::Parse::STT - Visualize a Set::FA::Element state transition
7 table as a graph
8
10 #!/usr/bin/env perl
11
12 use strict;
13 use warnings;
14
15 use File::Spec;
16
17 use GraphViz2;
18 use GraphViz2::Parse::STT;
19
20 use Log::Handler;
21
22 use File::Slurp; # For read_file().
23
24 # ------------------------------------------------
25
26 my($logger) = Log::Handler -> new;
27
28 $logger -> add
29 (
30 screen =>
31 {
32 maxlevel => 'debug',
33 message_layout => '%m',
34 minlevel => 'error',
35 }
36 );
37
38 my($graph) = GraphViz2 -> new
39 (
40 edge => {color => 'grey'},
41 global => {directed => 1},
42 graph => {rankdir => 'TB'},
43 logger => $logger,
44 node => {color => 'green', shape => 'oval'},
45 );
46 my($g) = GraphViz2::Parse::STT -> new(graph => $graph);
47 my $stt = read_file(File::Spec -> catfile('t', 'sample.stt.1.dat') );
48
49 $g -> create(stt => $stt);
50
51 my($format) = shift || 'svg';
52 my($output_file) = shift || File::Spec -> catfile('html', "parse.stt.$format");
53
54 $graph -> run(format => $format, output_file => $output_file);
55
56 See scripts/parse.stt.pl ("Scripts Shipped with this Module" in
57 GraphViz2).
58
59 Note: t/sample.stt.2.dat is output from Graph::Easy::Marpa::DFA V 0.70,
60 and can be used instead of t/sample.stt.1.dat in the above code.
61
63 Takes a Set::FA::Element-style state transition table and converts it
64 into a graph.
65
66 You can write the result in any format supported by Graphviz
67 <http://www.graphviz.org/>.
68
69 Here is the list of output formats
70 <http://www.graphviz.org/content/output-formats>.
71
73 This module is available as a Unix-style distro (*.tgz).
74
75 See <http://savage.net.au/Perl-modules/html/installing-a-module.html>
76 for help on unpacking and installing distros.
77
79 Install GraphViz2 as you would for any "Perl" module:
80
81 Run:
82
83 cpanm GraphViz2
84
85 or run:
86
87 sudo cpan GraphViz2
88
89 or unpack the distro, and then either:
90
91 perl Build.PL
92 ./Build
93 ./Build test
94 sudo ./Build install
95
96 or:
97
98 perl Makefile.PL
99 make (or dmake or nmake)
100 make test
101 make install
102
104 Calling new()
105 "new()" is called as "my($obj) = GraphViz2::Parse::STT -> new(k1 => v1,
106 k2 => v2, ...)".
107
108 It returns a new object of type "GraphViz2::Parse::STT".
109
110 Key-value pairs accepted in the parameter list:
111
112 o graph => $graphviz_object
113 This option specifies the GraphViz2 object to use. This allows you
114 to configure it as desired.
115
116 The default is GraphViz2 -> new. The default attributes are the
117 same as in the synopsis, above, except for the logger of course,
118 which defaults to ''.
119
120 This key is optional.
121
123 create(stt => $state_transition_table)
124 Creates the graph, which is accessible via the graph() method, or via
125 the graph object you passed to new().
126
127 Returns $self for method chaining.
128
129 $state_transition_table is a list of arrayrefs, each with 3 elements.
130
131 That is, it is the contents of the arrayref 'transitions', which is one
132 of the keys in the parameter list to Set::FA::Element's new().
133
134 A quick summary of each element of this list, where each element is an
135 arrayref with 3 elements:
136
137 o [0] A state name
138 o [1] A regexp
139 o [2] Another state name (which may be the same as the first)
140
141 The DFA in Set::FA::Element tests the 'current' state against the state
142 name ([0]), and for each state name which matches, tests the regexp
143 ([1]) against the next character in the input stream. The first regexp
144 to match causes the DFA to transition to the state named in the 3rd
145 element of the arrayref ([2]).
146
147 See t/sample.stt.1.dat for an example.
148
149 graph()
150 Returns the graph object, either the one supplied to new() or the one
151 created during the call to new().
152
154 See "FAQ" in GraphViz2 and "Scripts Shipped with this Module" in
155 GraphViz2.
156
158 Many thanks are due to the people who chose to make Graphviz
159 <http://www.graphviz.org/> Open Source.
160
161 And thanks to Leon Brocard <http://search.cpan.org/~lbrocard/>, who
162 wrote GraphViz, and kindly gave me co-maint of the module.
163
165 Version numbers < 1.00 represent development versions. From 1.00 up,
166 they are production versions.
167
169 The file Changes was converted into Changelog.ini by
170 Module::Metadata::Changes.
171
173 Email the author, or log a bug on RT:
174
175 <https://rt.cpan.org/Public/Dist/Display.html?Name=GraphViz2>.
176
178 GraphViz2 was written by Ron Savage <ron@savage.net.au> in 2011.
179
180 Home page: <http://savage.net.au/index.html>.
181
183 Australian copyright (c) 2011, Ron Savage.
184
185 All Programs of mine are 'OSI Certified Open Source Software';
186 you can redistribute them and/or modify them under the terms of
187 The Perl License, a copy of which is available at:
188 http://dev.perl.org/licenses/
189
190
191
192perl v5.30.1 2020-01-30 GraphViz2::Parse::STT(3)