CGI-Panel

 view release on metacpan or  search on metacpan

lib/CGI/Panel.pm  view on Meta::CPAN

    	# 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;

This example is included with the module.  It's in the 'demo'
directory and can be seen in action at
http://www.cyberdesignfactory.com/public-cgi-bin/simpleapp.cgi

=head1 DESCRIPTION

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).

Please let me know by email if you're using the module and would
like to be informed when there's an update.

=head1 USAGE

See 'SYNOPSIS'

=head1 BUGS

=head1 SUPPORT

=head1 AUTHOR

	Robert J. Symes
	CPAN ID: RSYMES
	rob@robsymes.com

=head1 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.

=head1 SEE ALSO

perl(1).

=head1 PUBLIC METHODS



( run in 2.211 seconds using v1.01-cache-2.11-cpan-ecdf5575e8d )