Title: CGI::Application
1CGIApplication
- Raleigh.PM February 21st, 2005
- Jason Purdy
- jason_at_journalistic.com
2WebDev Evolution
- CGI.pm scripts
- Separation of code design
- MVC framework
3CGIApplication
4CGIApp Benefits
- Great framework
- Strong community
- Much much more
5Whats it good for?
6Development Approach
- Mock-up Screens
- Write Instance Script
- Write CGIApp Frame PM
- Code / Test / Debug
- Roll Out
7Typical Scenario 3-Step Application
Show receipt
Enter user data
Enter credit card data
8Mock-up Screens (write Template files)
lthtmlgt First Name ltinput typetext
namefname /gt Last Name ltinput typetext
namelname /gt ltinput typehidden namerm
valuecc_data /gt lt/htmlgt
user_data.TMPL
lthtmlgt CC ltinput typetext namecc_num
/gt Exp. Date (MMYY) ltinput typetext
namecc_exp /gt ltinput typehidden
namefname valuelt!-- TMPL_VAR NAMEfname
ESCAPEHTML --gt /gt ltinput typehidden
namerm valuereceipt /gt lt/htmlgt
cc_data.TMPL
lthtmlgt Thanks for your Order! Ref Num lt!--
TMPL_VAR NAMEref_num --gt lt/htmlgt
receipt.TMPL
9Write Your Instance Script
https//www.example.com/payme.cgi
!/usr/bin/perl wT this is payme.cgi us
e strictuse MyModule my app
MyModule-gtnew() app-gtrun()
10Write cgiapp Frame PM
package MyModule use base CGIApplication sub
setup my ( self ) self
shift self-gtrun_modes( user_data,
red cc_data, yellow receipt
green ) self-gtmode_param( rm
) self-gtstart_mode( user_data
) self-gttmpl_path( /path/to/your/template/file
s ) self-gterror_mode( error )
Commented out, but good practice 1
11Flesh Out Individual Runmodes
package MyModule sub setup .. sub
user_data my ( self, template ) self
shift template self-gtload_tmpl(
user_data.TMPL ) return template-gtoutput()
1
12Flesh Out Individual Runmodes
package MyModule sub setup .. sub
user_data .. sub cc_data my ( self,
query, template ) self shift query
self-gtquery() template self-gtload_tmpl(
cc_data.TMPL, associate gt
query, ) return template-gtoutput() 1
13Flesh Out Individual Runmodes
package MyModule sub setup .. sub
user_data .. sub cc_data .. sub receipt
my ( self, query, ref_num, template
) self shift query self-gtquery()
Imaginary bill_card() method takes the CGI query
object and gets the data out of it and returns
a ref_num ref_num bill_card( query
) template self-gtload_tmpl( receipt.TMPL
) template-gtparam( ref_num gt ref_num
) return template-gtoutput() 1
14Gravy
- Add Plugin Code ValidateRM and Session
- Easy to port to mod_perl
- Anonymous handler in httpd.conf OR handler()
method in your .PM class - Keep in mind
- Code changes will need apache restarts
- Template Caching Directives
15I ? ValidateRM
- Very easy and powerful way to verify user data
input (this may lead to another Raleigh.PM talk)
use CGIApplicationPluginValidateRM sub
user_data my ( self, errs, template
) self shift errs shift
... template-gtparam( errs ) if errs sub
cc_data my ( self ) self shift my (
results, err_page ) self-gtcheck_rm( user_d
ata, _dfv_profile ) return err_page if
err_page 1
16I ? ValidateRM
- Very easy and powerful way to verify user data
input (this may lead to another Raleigh.PM talk)
use CGIApplicationPluginValidateRM sub
user_data .. sub cc_data .. sub
_dfv_profile return required gt qw(
fname lname ) 1
17Reference
- CGIApp Wiki http//cgi-app.org
- Mailing Lists
- CGIApp
- cgiapp-subscribe_at_lists.erlbaum.net?SubjectSubscri
be - HTMLTMPL
- http//lists.sourceforge.net/lists/listinfo/htmltm
pl-support - DFV
- http//lists.sourceforge.net/lists/listinfo/cascad
e-dataform