PrePAN

Sign in to PrePAN

Lib::GUI Add a graphical user interface to your Perl programs.

Good

Synopsis

# The "Hello, world!" program.

use Atlas; # Temporary name. Will be changed on CPAN.

my $body = '
<div style="display: table; margin: 50px auto auto auto;">
 <fieldset>
  <input id="input" maxlength="20" placeholder="Enter a name here" type="text"
         data-xdh-onevent="Submit" value="World"/>
  <div style="display: flex; justify-content: space-around; margin: 5px auto auto auto;">
   <button data-xdh-onevent="Submit">Submit</button>
   <button data-xdh-onevent="Clear">Clear</button>
  </div>
 </fieldset>
</div>';

sub acConnect {
    my ($hello, $dom) = @_;

    $dom->setLayout("",$body);

    return 1;
}

sub acSubmit {
    my ($hello, $dom) = @_;

    $dom->alert("Hello, " . $dom->getContent("input") . "!");

    return 1;
}

sub acClear {
    my ($hello, $dom) = @_;

    if ( $dom->confirm("Are you sure?") ) {
        $dom->setContent("input", "");
    }

    return 1;
}

my %callbacks = (
    "" => \&acConnect,
    "_PostProcess" => sub {$_[1]->focus("input");},
    "Submit" => \&acSubmit,
    "Clear" => \&acClear,
);

Atlas::launch(\%callbacks);

Description

  • For a live demonstration of above example: http://q37.info/s/zmzcxvm9
  • for other live demonstrations: http://q37.info/s/sssznrb4

The Atlas toolkit (http://atlastk.org/) purpose is to provide a fast and easy way to add a graphical interface to programs. This toolkit is available for Java, Node.js, PHP, Python, Ruby, and, now, also for Perl. It's lightweight, does not need other Perl modules, and requires only basic knowledge of widespread and easy-to-learn web technologies (no JavaScript required).

It can be easily used in programs that were not originally designed to have a GUI, so the user can choose which interface s/he wants to use. The Atlas toolkit also facilitates the development of prototypes, and can also easily be used by beginners.

Comments

anonymouse
Anonymous
Lib::GUI is way too generic a name considering it only works with Atlas and Atlas is not what most people consider a plain GUI. There are many existing GUI alternatives (google "perl gui"), but GUI by itself almost always refers to a native toolkit (like Wx, Tk, Qt, Gtk2, etc). It looks like Atlas is designed for only web GUIs, (i.e. WebApps) so that should be made clear in either the namespace or the description. Atlas, AtlasTk, Atlas::Toolkit, Atlas::WebApp are preferable names.
This is cool. Thanks for doing this.

I agree with Anonymous that Lib::GUI is too generic. Unfortunately, Atlas alone may be confused with the ATLAS linear algebra package. AtlasTk matches the original name, which is useful for domain recognition. There's no clear distinction on CPAN as to how to name interfaces to libraries. Some use Lib::<LibraryName>, others reserve an entire namespace, like Tk,etc.
Thanks for your advice.

Currently, the purpose of the Atlas toolkit is to provide an easy way to add a GUI to programs; that the result is technically a web application is only a side effect.

In the future, with exactly the same API, you will be able to write desktop, mobile and 'real' web applications. With the same source code, you choose the interface by simply importing the right module, maybe something like 'AtlasTK::GUI::Desktop', 'AtlasTK::GUI::Mobile' and 'AtlasTK::GUI::Web' (the native code already exists, but not yet the Perl binding to this native code). So maybe I'll just go with 'AtlasTK::GUI' for this module, as I've read that words like 'Easy(GUI)', 'Simple(GUI)' and similar should be avoided…

Please sign up to post a review.