OpenPlugin

 view release on metacpan or  search on metacpan

OpenPlugin/Application.pm  view on Meta::CPAN

# $Id: Application.pm,v 1.30 2003/05/11 01:54:03 andreychek Exp $

package OpenPlugin::Application;

use strict;

$OpenPlugin::Application::VERSION = sprintf("%d.%02d", q$Revision: 1.30 $ =~ /(\d+)\.(\d+)/);

use OpenPlugin();
use CGI::Application 2.6 qw();
use base qw( CGI::Application );

# This sub overrides one provided with CGI::Application.  It's job is to return
# a query object.  The one provided with CGI::App returns a CGI.pm object --
# but we want to return an OpenPlugin object.
sub cgiapp_get_query {
    my $self = shift;

    my @keys = $self->param;
    my %params;

    # Gather the parameters sent to us in the new() constructor
    foreach my $key ( @keys ) {
        $params{$key} = $self->param( $key );
    }

    return OpenPlugin::Wrapper->new( %params );
}

# This is meant to be an alias for CGI::App's query() method
sub OP {
    my $self = shift;

    $self->SUPER::query( @_ );

}

package OpenPlugin::Wrapper;

@OpenPlugin::Wrapper::ISA = qw( OpenPlugin );

# This is a wrapper module to make OpenPlugin behave like CGI.pm.  This is
# soley to get CGI::Application to work properly, as it assumes you are using
# CGI.pm.  If anyone has thoughts on a better way to do this, I would certainly
# be glad to hear them :-)

# When called from CGI::Application, this method act's like the param() in
# CGI.pm.  Otherwise, it just passes the request onto OpenPlugin.
sub param {
    my $self   = shift;
    my @params = @_;

    if( (caller)[0] eq "CGI::Application" ) {
        return $self->SUPER::param->get_incoming( @params );
    }
    else {
        return $self->SUPER::param( @params );
    }
}

# When called from CGI::Application, this method act's like the same one from
# CGI.pm.  Otherwise, it just passes the request onto OpenPlugin.
sub header {
    my $self   = shift;
    my @params = @_;

    if( (caller)[0] eq "CGI::Application" ) {
        return $self->SUPER::httpheader->send_outgoing( @params );
    }
    else {
        return $self->SUPER::httpheader( @params );
    }
}

1;

__END__

=pod

=head1 NAME

OpenPlugin::Application - A subclass of CGI::Application, meant to help you
create reusable web applications.

=head1 SYNOPSIS

 # Example from OpenThought's Demo.pm

 package Demo;
 use base "OpenPlugin::Application";
 sub setup {
     my $self = shift;
     $self->run_modes(
        'mode1' => 'init_demo',
        'mode2' => 'get_os_list',
        'mode3' => 'get_os_info',
     );
     $self->start_mode( 'mode1' );
     $self->mode_param('run_mode');
 }
 sub init_demo   { ... }
 sub get_os_list { ... }
 sub get_os_info { ... }
 1;

 # Example from OpenThought's demo.pl

 #!/usr/bin/perl -wT
 use strict;
 my $r = shift;
 my $demo = Demo->new( PARAMS => {
                    config  => { src    => "/path/to/OpenPlugin.conf" },
                    request => { apache => $r },
 });

 $demo->run();

=head1 DESCRIPTION

OpenPlugin::Application is built on Jesse Erlbaum's popular L<CGI::Application>
module.  OpenPlugin::Application is simply a subclass of CGI::Application.
Jesse says the following about CGI::Application:

"CGI::Application is intended to make it easier to create sophisticated,
reusable web-based applications. This module implements a methodology which, if
followed, will make your web software easier to design, easier to document,



( run in 0.510 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )