[Bio] / FigKernelScripts / create-new-page.pl Repository:
ViewVC logotype

View of /FigKernelScripts/create-new-page.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.6 - (download) (as text) (annotate)
Tue Nov 29 21:19:36 2011 UTC (7 years, 11 months ago) by disz
Branch: MAIN
CVS Tags: rast_rel_2014_0912, rast_rel_2014_0729, mgrast_release_3_1_2, mgrast_version_3_2, mgrast_dev_12152011, HEAD
Changes since 1.5: +10 -0 lines
added sopme more use lines

use strict;
use FIG_Config;
use Getopt::Long;

=head1 NAME

create-new-page - create a new seedviewer / cgi page


create-new-page ImplementationMod.pm SeedviewerPageMod.pm cgi_script.cgi


We wish to make it easy to create new SeedViewer pages in a way that
development may be performed in standard CGI pages or in plain perl
scripts (to enable debugging or profiling).

=head2 The Guts of the Application

In order to do this the code that performs the actual web-page
rendering and request processing must be moved to a standalone module
that resides in FigKernelPackages. This module must define a single

  run($fig, $cgi, $sapObject, $user, $my_url, $hidden_form_var,

The invoking code (SeedViewer or standalone CGI script) will pass or
construct the arguments appropriately. They are:

  $fig	      	     A FIG object
  $cgi	      	     A CGI.pm instance initialized with the request parameters
    	      	     for the web request being processed.
  $sapObject  	     A SAPserver object.
  $my_url     	     The URL to use to refer to the this web page.
  $hidden_form_var   If web forms are constructed, the data in this
  		     parameter must be included inside the form.
  $seedviewer_page_object If the page was brought up in the
  			  SeedViewer, the page object will be passed here.

A sample module that performs the simple operation of displaying the
function of a peg may be found in FigKernelPackages/BlankSVP.pm.

=head2 The SeedViewer Page

For the application to appear in the seedviewer, a module must be
placed in the directory SeedViewer/WebPage. This module contains some
standard boilerplate plus the invocation of the module we defined

The URL to this page is constructed using the name of the module in


A sample module for our example may be found in
SeedViewer/WebPage/BlankSVPPage.pm. The corresponding URL in the
pubseed would be


If you are using a sandbox in your home directory, the corresponding
URL would be


=head2 The CGI script

To make the code available via CGI some simple boilerplate must be
placed in the directory FigWebServices. 

A sample CGI for this example may be found in

=head2 Automating everything

In order to make the creation of new pages as simple as possible, we
provide a script that will generate the boilerplate pages as described

To use it, one must specify the names of the three files ("guts"
module, SeedViewer page, cgi script). For example:

  create-new-page MyNewScript.pm MyNewScriptPage.pm my_new_script.cgi


my $overwrite;

my $rc = GetOptions("overwrite" => \$overwrite);

($rc && @ARGV == 3) or die "usage: $0 [--overwrite] ImplementationMod.pm SeedViewerPageMod.pm cgi_script.cgi\n";

my $impl = shift;
my $page = shift;
my $cgi = shift;

$impl .= ".pm" unless $impl =~ /\.pm$/;
$page .= ".pm" unless $page =~ /\.pm$/;
$cgi .= ".cgi" unless $cgi =~ /\.cgi$/;

my $impl_mod = $impl;
my $page_mod = $page;
my $cgi_base = $cgi;
$impl_mod =~ s/\.pm$//;
$page_mod =~ s/\.pm$//;
$cgi_base =~ s/\.cgi$//;

my $base = "$FIG_Config::fig_disk/dist/releases/current";

-d $base or die "Cannot find base directory $base\n";

my $impl_path = "$base/FigKernelPackages/$impl";
my $page_path = "$base/SeedViewer/WebPage/$page";
my $cgi_path = "$base/FigWebServices/$cgi";

if (!$overwrite)
    -f $impl_path and die "$impl_path already exists\n";
    -f $page_path and die "$cgi_path already exists\n";
    -f $cgi_path and die "$cgi_path already exists\n";

my $hdr = <<END;
# This file is part of an application created with create-new-page.
# The implementation module is FigKernelPackages/$impl_mod.pm.
# The SeedViewer page module is SeedViewer/WebPage/$page_mod.pm.
# The CGI script is FigWebServices/$cgi_base.cgi.
# The SeedViewer url is http://yourseed/seedviewer.cgi?page=$page_mod
# The CGI url is http://yourseed/$cgi_base.cgi


print "Created files:\n";
print "   Implementation module $impl_path\n";
print "   Seedviewer module     $page_path\n";
print "   CGI script            $cgi_path\n";
print "\n";
my $sv_url = $FIG_Config::cgi_url . "/seedviewer.cgi?page=$page_mod";
my $cgi_url = $FIG_Config::cgi_url . "/$cgi_base.cgi";

print "Your seedviewer URL is (probably) $sv_url\n";
print "Your CGI url is (probably) $cgi_url\n";

sub create_impl
    open(F, ">", $impl_path) or die "Cannot create $impl_path: $!";

    print F <<EOF;
package $impl_mod;


use strict;
use HTML;
use Data::Dumper;
use Data::Dumper;
use LinksUI;
use RC;
use URI::Escape;

sub run
    my(\$fig, \$cgi, \$sapObject, \$user, \$url, \$hidden_form_var, \$seedviewer_page_obj) = \@_;

    my \@html = ();

    push(\@html, "The creator of the $impl_mod module hasn't put any HTML in place yet");

    my \$title = "default  title";

    my \$html_txt = join("", \@html);
    return(\$html_txt, \$title);


sub create_page
    open(F, ">", $page_path) or die "Cannot create $page_path: $!";

    print F <<EOF;
package SeedViewer::WebPage::$page_mod;


use base qw(SimpleWebPage);

use SAPserver;
use $impl_mod;

use strict;
use FIG_Config;

sub page_title
    return "My title";

sub page_content
    my(\$self, \$fig, \$cgi, \$user_name, \$my_url) = \@_;

    my \$sap = SAPserver->new();

    my(\$html, \$title) = ${impl_mod}::run(\$fig, \$cgi, \$sap, \$user_name, \$my_url,
				      "<input type='hidden' name='page' value='$page_mod'>", \$self);

    return \$html;



sub create_cgi
    open(F, ">", $cgi_path) or die "Cannot create $cgi_path: $!";

    print F <<EOF;
#!/usr/bin/env/perl -w
use SAPserver;
use $impl_mod;


use strict;
use FIG;
use CGI;
use Data::Dumper;
use Carp;
use FIG_Config;

my \$cgi = CGI->new;
my \$fig = FIG->new;
my \$sap = SAPserver->new();

my \$user_name = \$cgi->param("user");

my \$my_url = "$cgi_base.cgi";

my(\$html, \$title) = ${impl_mod}::run(\$fig, \$cgi, \$sap, \$user_name, \$my_url, '', undef);

print \$cgi->header;
print "<title>\$title</title>";
print \$html;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3