开发者

How can I make a rich web application in Perl?

开发者 https://www.devze.com 2022-12-20 10:44 出处:网络
I have a Perl command-line script that I 开发者_如何学Pythonwant to convert to a rich. cross-platform desktop GUI application. What\'s the best methodto do it. I want to the internal and the logic cod

I have a Perl command-line script that I 开发者_如何学Pythonwant to convert to a rich. cross-platform desktop GUI application. What's the best method to do it. I want to the internal and the logic code in Perl but the GUI should be rich web application.


I have been working on the Perl module XUL::Gui on CPAN which uses Firefox as a host platform to render cross platform gui's from Perl. All you need is Firefox installed on the target platforms. It is currently in development, but may be stable enough for your needs. Here is a brief example of how the syntax looks:

use XUL::Gui;

display Window title => 'Foo Processor',
    Hbox(
        (map {
            my $id = $_;
            CheckBox id => $id,
                label   => "use $id",
                option  => sub {shift->checked eq 'true' ? " -$id" : ()}
          } qw/foo bar baz/
        ),
        TextBox( id => 'num', 
             type   => 'number', 
             option => sub {' -num ' . shift->value}
        ),
        Button( label => 'run', oncommand => sub {
            my @opts = map {$ID{$_}->option} qw/foo bar baz num/;
            $ID{txt}->value = `fooproc @opts`;
        }),
    ),
    TextBox( FILL, id => 'txt' );

Since it is under development, if you have any feature requests (or find any bugs) let me know.

Also, since you are inside of Firefox, any web technologies that Firefox supports (canvas, iframes, flash...) are fully usable from Perl. For gui components, you can use any combination of HTML and XUL tags.


Mojolicious is a light but yet powerful Web framework which is particularly useful to wrap scripts into quick and well done Web apps.

We are using it extensively on the local network to let colleagues make use of the scripts we develop on our Unix boxes, whatever their platform. For simple tasks, you can even pack everything (templates and routing) in one file: check Mojolicous::Lite.


Does it need to be a rich, native-OS style GUI? Or just any old user interface? You could get something up and running very quickly with CGI::Application - it's probably the best balance between clean, maintainable code and a short learning curve. For more heavily duty work, Catalyst seems to be the weapon of choice.

If you want to make a full-featured GUI with menus and draggable dialog boxes etc. Perl is probably not the best candidate.


If by

the gui should be web for cross platfrom
you mean it should be written using HTML / CSS /JavaScript, one solution is to use HTTP::Server::Simple::CGI in conjunction with CGI::Application and HTML::Template. Browser::Open completes the required minimal functionality.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号