App-XUL
view release on metacpan or search on metacpan
lib/App/XUL.pm view on Meta::CPAN
}
else {
return '';
}
}
sub _get_file_maxosx_infoplist
{
my ($self) = @_;
return <<EOFSRC
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>start.pl</string>
<key>CFBundleGetInfoString</key>
<string>XULExplorer 1.0a1pre, © 2007-2008 Contributors</string>
<key>CFBundleIconFile</key>
<string>$self->{'name'}</string>
<key>CFBundleIdentifier</key>
<string>org.mozilla.mccoy</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$self->{'name'}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0a1pre</string>
<key>CFBundleSignature</key>
<string>MOZB</string>
<key>CFBundleVersion</key>
<string>1.0a1pre</string>
<key>NSAppleScriptEnabled</key>
<true/>
</dict>
</plist>
EOFSRC
}
1;
__END__
=head1 NAME
App::XUL - Perl extension for creating deployable platform-independent
standalone desktop applications based on XUL and XULRunner.
=for html <span style="color:red">WARNING: PRE-ALPHA - DON'T USE FOR PRODUCTION!</span>
=head1 SYNOPSIS
use App::XUL;
my $app = App::XUL->new(name => 'MyApp');
$app->add(
Window(id => 'main',
Div(id => 'container', 'style' => 'background:black',
Button(label => 'click', oncommand => sub {
ID('container')->style('background:red');
}),
),
),
);
$app->bundle(path => '/path/to/myapp.app', os => 'macosx');
XUL (+ XULRunner) makes it easy to create applications based
on XML, CSS and JavaScript. App::XUL tries to simplify this
even more by exchanging XML and JavaScript with Perl and
providing an easy way to create deployable applications for the
platforms XULRunner exists for.
=head1 WHY XUL/XULRUNNER
XUL provides a set of powerful user widgets that look good
and work as expected. They can be created with minimal effort
and their appearance can be manipulated using CSS.
XUL is based on B<web technologies like XML, CSS and JavaScript>.
So anyone who is able to use these is able to create cool
desktop applications.
Here is the homepage of the L<XUL|https://developer.mozilla.org/En/XUL>
and L<XULRunner|https://developer.mozilla.org/en/xulrunner> projects at Mozilla.
=head1 DESCRIPTION
=head2 new() - Creating an application
The constructor new() is used to create a new application
my $app = App::XUL->new(name => 'MyApp');
=head3 Options
=head4 name => I<string>
The name of the application. Later also used as the application executable's name.
=head2 add() - Add a window to an application
add() adds a window to the XUL application. The XML for the window tag
and its contained tags is created using Perl functions. The names of
the Perl functions used to create the XML tags corresponds to the
tagnames, just the first letter is uppercase:
$app->add(
Window(id => 'main',
Div(id => 'container', 'style' => 'background:black',
Button(label => 'click', oncommand => sub {
ID('container')->style('background:red');
}),
);
)
);
Keep in mind, that add will fail if the added tag is NOT a window tag.
In XUL the root is always a window tag.
The first window beeing added is considered the main window and shown
on startup.
=head2 bundle() - Creating a deployable executable
$app->bundle(path => '/path/to/myapp.app', os => 'macosx');
This will create a complete standalone XUL application containing all XML code.
Some general information about
L<XUL application deployment|https://wiki.mozilla.org/XUL:XUL_Application_Packaging>.
=head3 Options
=head4 path => I<string>
=head4 os => I<string>
The systems currently supported are:
=over 1
=item chrome (native Chrome application)
This creates the usual directory for a XULRunner based application containing
all needed files, except the XULRunner executable itself. A start Perl
script for various operation systems is created as well, e.g. you can start
the application by executing the start_macosx.pl file for Mac OS X.
Note for Linux users: You have to add the directory containing the
xulrunner (or xulrunner-bin) executable to your $PATH variable or
adjust the start_linux.pl script accordingly. This is due to the fact
that XULRunner for Linux us currently in beta phase and can only
be used by unpacking it into a local directory.
=item macosx (Mac OS X)
L<Apple Documentation|http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1>
=item win (Windows)
coming soon
=item deb or rpm (Ubuntu Linux)
tbd. Either a *.deb or *.rpm Paket.
=back
=head4 debug => I<1/0>
If debug is set to 1, a jsconsole is started together with the application
lib/App/XUL.pm view on Meta::CPAN
an interface component. Event handlers can either be written
in Perl or in JavaScript.
Here is an example of a Perl event handler that reacts on
the mouse click of a button:
Button(label => 'click', oncommand => sub {
# access environment and evtl. change it
# ...
});
Here is a similar JavaScript event handler:
Button(id => 'btn', label => 'click', oncommand => <<EOFJS);
// here is some js code
$('btn').update('Alrighty!');
EOFJS
JavaScript event handlers are executed faster than the Perl ones,
due to the architecture (see below).
=head2 Changing the environment from Perl
This refers to all activities within Perl event handlers that
change the DOM of the XUL application. An example is the
addition of another window, the insertion or update of a button
label or the deletion of a style attribute etc.
Some things are important here:
=over 1
=item Changes happen on the server side first and are
transferred to the client side (the XUL application)
when the event handler terminates.
=item To manually transfer the latest changes to the client side
use the PUSH() function.
=back
=head4 Get (XML) element
The first step of changing the DOM is to get an element on which
the changes are applied. The ID() function is used for that:
my $elem = ID('main');
The ID() function only works WHILE the application is running.
Any changes to the object returned by the ID() function are transferred
immedietly (asynchronous) to the XUL application/client.
=head4 Get child (XML) elements
my $child1 = ID('main')->child(0);
my $numchildren = ID('main')->numchildren();
=head4 Create/insert/append (XML) elements
my $e = Div(id => 'container', 'style' => 'background:black',
Button(label => 'click'));
ID('main')->insert($e, 'end'); # end|start|...
=head4 Edit (XML) element
ID('container')->style('background:red')->content(Span('Hello!'));
=head4 Delete/remove (XML) element
my $e = ID('container')->remove();
=head4 Call event handler on (XML) element
ID('container')->click();
=head4 Register event handler on (XML) element
ID('container')->oncommand(sub {
# do stuff here
# ...
});
=head4 Un-register event handler on (XML) element
ID('container')->oncommand(undef);
=head2 EXPORT
None by default.
=head1 INTERNALS
This chapter is meant for informational purposes. Sometimes it is nessessary
to know how things are implemented to decide, for example, if you should
use a Perl or a JavaScript event handler etc.
App::XUL is client-server based. The client is the instance of
XULRunner running and the server is a pure Perl based webserver
that reacts on the events that are triggered by the XUL interface.
=head3 Event handling
Essentially all events are dispatched from XUL as Ajax calls to the
Perl webserver which handles the event, makes changes to the DOM etc.
The changes are then transferred back to the XUL app where they
are applied.
Here is a rough workflow for event handling:
=over 1
=item 1. Client registers an event (e.g. "mouseover", "click", "idle" etc.)
=item 2. Client sends message to server (incl. parameters and environment)
=item 3. Server calls appropriate Perl event handler subroutine
(which may manipulate the environment)
=item 4. Server sends the environment changes to the client as response
=item 5. Client integrates environment changes
=back
=head3 Communication protocol
( run in 1.688 second using v1.01-cache-2.11-cpan-d8267643d1d )