Homework 6
This homework will get you accustommed to using Perl to create CGI
applications, using HTML::Template to separate the layout
of the web page from the programming logic.
Description
Write a Perl CGI script to implement a simple expense tracker. Using HTML::Template, you will write two template files. The first will be used to display a running total of your expenses and earnings. This will show each transaction's date, a description ("Birthday present for Joe"), the amount of the transaction, and your new total balance. The listing should be sorted by date.
The second template will be used to create a form which can be used to add a new transaction or edit an existing transaction. The form should have fields for the date, description, and amount. It should have a pair of radio buttons to determine if the transaction is subtracting from your total (ex, a purchase), or adding to it (ex, a paycheck).
Read the documentation for HTML::Template to learn how to include one template in another. When the user first views your program, he should see the listing of transactions, with the form to add a new transaction below it. The listing must have some way of editing an existing transaction (the method by which you choose which transaction to edit is up to you). Once the user has chosen to edit a particular transaction, your script should display just the form template, with the current values of the transaction already displayed. The user can edit any or all of the fields of that transaction, and save changes. At this point, you should return to the main page, displaying all of the transactions, including the newly modified transaction, and the form to add a new transaction.
In addition to being able to edit a transaction, you must provide a method by which to delete a given transaction. Once a transaction is edited or deleted, make sure your "new balance" column acurately reflects the current transaction history.
Notes
- You will obviously need some kind of data file in which to store your transactions. The format of this datafile is entirely up to you, as only your script will be reading, parsing, or writing to it.
- In addition to all of the user-visible data for each transaction, I strongly suggest you store some sort of unique id for each transaction in the data file. This will likely make it much easier to implement the edit and delete functionality.
- You are free to have additional HTML::Template files, if you wish. The two specified above (the form, and the listing) are required. Also required is that the larger listing template uses the HTML::Template method to include the form template - you may not simply duplicate the form in the listing template.
- You are again free to use any CPAN module you can get working on the CS System. (Obviously, HTML::Template is one you're definately going to have to download and use). Please note that when running a CGI script, the $ENV{HOME} parameter is not set, so you will have to hard-code your lib statement as
use lib '/cs/lallip/lib'; - If you wish to include any CSS for styling your HTML pages, please include the CSS inline, not in an external file
- For the Edit and Delete sections, you may find the Perl feature of
"in-place editing" very helpful. Recall the command line option
-i(from the Debugging page), which causes all prints to go to the file currently being read in awhile(<>){...}loop. This feature can be enabled from within a script by setting the global$^Ivariable to the extension you want for the backups (or to the empty string to not save backups), and by setting@ARGVto the list of files you want to process. Make sure youlocally set these variables so as to not affect other portions of your code.
Grading criteria
| Display initial listing and form | 15 |
|---|---|
| Include form template in listing template | 10 |
| Add a new transaction | 15 |
| Display form for editing a transaction | 10 |
| Edit an existing transaction | 20 |
| Delete existing transaction | 10 |
| Compilation | 5 |
| Output Style | 5 |
| Code Style | 5 |
| Error Checking | 5 |
Compilation
Points are deducted for any warning messages your code produces. Note that warnings will be enabled when we run your program, regardless of whether or not you've enabled warnings within the code.
As a reminder, while use strict; is not a requirement
for the homework, it is a very strong suggestion (also keep in mind
that it is required before emailing for help.)
If your code produces compilation errors, you will lose all the points for compilation, and the remainder of your program will be graded subjectively based on the code you've written itself. You should never submit code that does not compile.
Output Style
Output, in this case, refers to the two web pages your CGI script will produce. Nothing overly 'fancy' is required, but it shoudl be formatted in such a way that all data is clearly identifiable. All output on one single line is bad. The raw data, without being labeled, is also bad. If it hurts my (or the TA's) eyes to look at, it's bad.
Code Style
All code that you write should be well styled. Most important are three features: A consistent and helpful indentation scheme; Meaningful variable names; explanatory but not over-abundant comments.
For examples of well-styled code, please see perldoc perlstyle
Submission Instructions
You will submit your homework by running ~lallip/public/hw_submit on solaris.remote.cs.rpi.edu. (This program is not yet written... update will be sent to the list when it is read). Your homework is due on Tuesday, November 29, 2005 at 11:59:59pm. It will be accepted for a deduction of 20 points until Wednesday, November 30 at 3:59:59pm.
