CGI-Panel
view release on metacpan or search on metacpan
---------------
in SimpleApp.pm:
package SimpleApp;
use strict;
use Basket;
use base qw(CGI::Panel);
sub init {
my ($self) = @_;
$self->add_panel('basket', new Basket); # Add a sub-panel
$self->{count} = 1; # Initialise some persistent data
}
sub _event_add { # Respond to the button click event below
my ($self, $event) = @_;
$self->{count}++; # Change the persistent data
}
sub display {
my ($self) = @_;
return
'This is a very simple app.<p>' .
# Display the persistent data...
"My current count is $self->{count}<p>" .
# Display the sub-panel...
$self->panel('basket')->display . '<p>' .
# Display a button that will generate an event...
$self->event_button(label => 'Add 1', name => 'add');
}
1;
---------------
in Basket.pm:
package Basket;
use base qw(CGI::Panel);
sub display {
'I have the potential to be a shopping basket one day'
}
1;
---------------
DESCRIPTION
* Please note that the subclass CGI::Panel::MainPanel has now been
deprecated to make using the module easier. Please change any code which
uses the module so that the main panel sub-classes CGI::Panel just like
the other panels. *
CGI::Panel allows applications to be built out of simple object-based
components. It'll handle the state of your data and objects so you can
write a web application just like a desktop app. You can forget about
the http requests and responses, whether we're getting or posting, and
all that stuff because that is all handled for you leaving to you
interact with a simple API.
An application is constructed from a set of 'panels', each of which can
contain other panels. The panels are managed behind the scenes as
persistent objects. See the sample applications for examples of how
complex object-based applications can be built from simple encapsulated
components. To try the demo app, copy the contents of the 'demo'
directory to a cgi-bin directory.
CGI::Panel allows you to design the logic of your application in an
event-driven manner. That is, you set up your application the way you
want it, with special buttons and links that trigger 'events'. The
application then sits back and when an event is triggered, the code
associated with that event is run. The code that responds to an event
goes in the same class as the code that generates the event button or
link, making the code more readable and maintainable. If the event code
changes the state of any of the panels, the panels will then stay in the
new state, until their state is changed again.
Each panel is encapsulated not only in terms of the code, but in terms
of the form data that is passed through. For example a panel class can
be defined which has a textfield called 'name'. Three instances of this
panel can then exist simultaneously and each will get the correct value
of the 'name' parameter when they read their parameters (see the
'local_params' method).
Until the software reaches version 1.00 it will be considered beta
software. You should be able to use it in production code, however I
strongly recommend that you 'stabilise' your version of the module if
you release any code that uses it. By this I mean that, once you've
tested your app thoroughly, you rename CGI::Panel as, for example
App::CGIPanel and inherit from this, then include this with your other
panels. This will protect you from any changes in the interface. I'm not
planning to make many changes, however one thing I'm considering is
making the events objects instead of hashes.
Please let me know by email if you're using the module. I'll then inform
you when there's an update.
USAGE
See 'SYNOPSIS'
BUGS
SUPPORT
AUTHOR
Robert J. Symes
CPAN ID: RSYMES
rob@robsymes.com
COPYRIGHT
Copyright (c) 2002 Robert J. Symes. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same
terms as Perl itself.
The full text of the license can be found in the LICENSE file included
with this module.
SEE ALSO
( run in 1.878 second using v1.01-cache-2.11-cpan-5837b0d9d2c )