CGI::Panel

Create stateful event-driven web applications from simple panel objects
Download

CGI::Panel Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Rob Symes
  • Publisher web site:
  • http://search.cpan.org/~rsymes/

CGI::Panel Tags


CGI::Panel Description

Create stateful event-driven web applications from simple panel objects CGI::Panel is a Perl module that 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).SYNOPSISA very simple working application consisting of a driver cgi and two panel classes...In simpleapp.cgi: use SimpleApp; my $simple_app = obtain SimpleApp; $simple_app->cycle();In SimpleApp.pm: package SimpleApp; use base qw(CGI::Panel); use Basket; sub init { my ($self) = @_; $self->add_panel('basket1', new Basket); # Add a sub-panel $self->add_panel('basket2', new Basket); # Add a sub-panel $self->add_panel('basket3', 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.' . # Display the persistent data... "My current count is $self->{count}" . # Display the sub-panels... "< table >< tr >" . "< td >" . $self->panel('basket1')->display . "< /td >" . "< td >" . $self->panel('basket2')->display . "< /td >" . "< td >" . $self->panel('basket3')->display . "< /td >" . "< /tr >< /table >" . # 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 init { my ($self) = @_; $self->{contents} = []; } sub _event_add { # Respond to the button event in 'display' my ($self, $event) = @_; # Get panel's localised parameters # (Many instances of this panel each get # their own local parameters) my %local_params = $self->local_params; push @{$self->{contents}}, $local_params{item_name}; } sub display { my ($self) = @_; return '< table bgcolor="#CCCCFF" >' . join('', (map { "< tr >< td >$_< /td >< /tr >" } @{$self->{contents}})) . '< tr >' . # Localised text field '< td >' . $self->local_textfield({name => 'item_name', size => 10}) . '< /td >' . # Button that will generate an event (handled by _event_add above) '< td >' . $self->event_button(label => 'Add', name => 'add') . '< /td >' . '< /tr >' . '< /table >'; }; 1; Requirements: · Perl


CGI::Panel Related Software