Aha, I missed the few key words in your node about calling a module, my apologies. As far as "a lot of extra work", it may be a simple application now, but damned if those things don't grow at the worst possible times. ;-)

As far as X/CLI, the most reasonable algorithm is:

my $have_X = (!$opt_forceCLI and $ENV{DISPLAY} and try_Xconnection($ENV{DISPLAY}) or $opt_forceX; exec ($have_X && !$opt_useconsole) ? "$app.gui" : "$app.X";

In other words, check the DISPLAY and try to connect to the X server; if that fails, use the CLI. (Also makes certain to handle the command line options to force X or CLI). Yes, this isn't 100%. Yes, there are more complex ways to do it.

In reality, since you are allowing the user to force one or the other via a command-line, you needn't even try to connect to X. With unusual configurations where DISPLAY is set without X running (or vice-versa), the user simply needs to specify a force option on the command line.

Anima Legato
.oO all things connect through the motion of the mind


In reply to Re^3: How to detect X? by legato
in thread How to detect X? by blazar

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.