The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Finance::Shares::CGI - support for Finance::Shares cgi interface scripts

SYNOPSIS

The perl module

    use Finance::Shares::CGI;

    my $cgi = new Finance::Shares::CGI;
    my $db  = $cgi->get_records();

    $cgi->print_header($title, $text, $script, $style);
    $cgi->print_form_start($url, $code, $centered);
    $cgi->print_form_end();
    $cgi->print_footer($text);

    $cgi->show_params();
    $cgi->show_hash($hashref);
    $cgi->show_records();

Administration scripts

    init.pl
    fetch.pl
    list.pl
    drop.pl

Main processing scripts

    chart.pl
    interface.pl
    menu.pl
    shares.pl
    prefs.pl
    run.pl

Support scripts

    make_index

DESCRIPTION

The Finance::Shares::CGI module supports a number of cgi scripts which provide a web interface to the Finance::Shares toolkit. It requires a mysql database. See Finance::Shares::Overview or Finance::Shares::MySQL for details on setting this up.

The scripts must be manually copied to your CGI directory. See the README file for installation details. This documents how the scripts work together.

Constructor

There are no parameters. However, there are seven lines that probably need editing before use. See the README file for INSTALLATION details. Use as:

    my $cgi = new Finance::Shares::CGI;

Methods

login()

Connects to the database. Used by get_records.

get_records()

This requires the CGI parameter 'u' to be set to a user name. It will automatically register any name it does not recognize. The user settings are fetched and available for use. Use as:

    use Finance::Shares::CGI;
    use CGI ':standard';

    my $cgi = new Finance::Shares::CGI;
    param('u', 'myname');
    $cgi->get_records();
    

change_user()

Call this to store any changes to the user data.

Issue the CGI text needed to set up a standardized page. The title becomes a heading as well as the HTML page title. If text is present it is output and subsequent text will be part of a table. script and style would typically be javascript code and the name of a CSS stylesheet. The default is no script and styles.css. Use as:

    $cgi->print_header('My Title', $html);

Declare the start of a form after print_header. url is the form action, code is 'onsubmit' code and centered is a layout flag. Use as:

    $cgi->print_form_start();

Mark the end of a form declared with print_form_start.

Mark the end of the page begun with print_header.

show_error( message )

Output an error page and exit. Use as:

    $cgi->show_error( 'No user' );

Support methods

show_hash( hashref )

Return a string comprising key=value pairs for the top level entries only. Use as:

    print $cgi->show_hash( $h );

show_records( [table] )

Print out the objects key/value pairs within table html if table is true.

head2 Administration scripts

Choose 'Admin' from the 'User levels' Preference menu. An additional menu then gives access to these scripts.

init.pl

Builds the mysql database and maintains the user interface support tables. Mysql must have a user, password and database to match those set in Finance::Shares::CGI.pm. Documentation is available using

    $ perldoc init.pl

Note that tables or users options destroy user data.

This script may be invoked directly from a browser, provided that '?initialize=1' is appended. It will then initialize the database ready for the other CGI scripts.

fetch.pl

Fetches stock quotes into the mysql database. Quotes are fetched when a chart or model is run, anyway. Remember the command line scripts fs_fetch and fs_fetch_csv can be found in the Finance::Shares package.

list.pl

Lists the mysql table names against the DBIx::Namespace user names. Remember fs_list_tables in Finance::Shares.

drop.pl

Small changes to the tables can be made from the mysql prompt. DON'T just delete tables, though, as this destroys the index integrity. It only deletes one user-name at a time. Use list.pl to identify them. This does the same job as fs_drop_table from the Finance::Shares package.

Main processing scripts

These are the scripts which serve the site's main purpose, to make the hundreds of options more manageable.

shares.pl

Top of site, this generates the frameset holding menu and content frames.

Generates the menu according to session browser settings

interface.pl

The main script, driven by params 't' (table name), 'a' (arguments) and 'name' (of user settings) which determine the layout described in the init.pl tables.

prefs.pl

Help and option levels for user. There are three user levels, mostly done, but the three help levels are all the same at present.

chart.pl

Generates PostScript chart from 'Draw chart' settings.

run.pl

Runs a model and returns a chart with the results.

Support scripts

make_index

Constructs the file index.html using the same settings as all the cgi scripts.