Note: If you're unfamiliar with state machines, this article should give you the necessary background. Also, a variant of this question was cross-posted to the module authors list.

I've been doing a lot of work with FSA::Rules for my job. I've added GraphViz support to generate state machine graphs on the fly.

To do this, here's how a state is defined (see the module for a full explanation):

installed => { do => sub { shift->result($self->_is_installed) }, rules => [ fail => { "Postgres not\ninstalled" => sub {! shift->result } + }, version => { "Postgres\ninstalled" => sub { shift->result } }, ], },

Each rule now takes an optional hash reference. If supplied, the key is the "label" that appears on the line leading from state to state (take a look at the first state on the linked graph and notice the names.)

If you prefer, you can also specify the rules the old way:

rules => [ fail => sub { ! shift->result }, version => sub { shift->result } ],

The only difference is that there is no label if a graph is generated. In other words, for rules you can use a subref or a hashref. Does that sound confusing? I think it is.

Can anyone suggest a cleaner syntax for the rule labels? Having state machine graphs auto-generated is really cool, but I don't know if it's worth the expense of making things too confusing to use. Because we're struggling with the syntax, we have not yet uploaded the version with GraphViz support.

As a side note, if you would prefer a completely different syntax for the module, we're open to anything that will make it easier to use, even though it's already pretty easy.

Cheers,
Ovid

New address of my CGI Course.


In reply to Interface design question: graphing state machines. by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.