How to create a simple Web application with Web::App Template::Toolkit and Class::DBI Leonard Miller June 17, 2008.

Slides:



Advertisements
Similar presentations
(c) Creative Commons Attribution-ShareAlike License- Jason Purdy CGI::Application Raleigh.PM :: February 21 st, 2005 Jason Purdy
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Programming MySQL, Perl COEN 351. Reading List Paul DuBois: MySQL and Perl for the Web, New Riders, 2002 Jacqueline D. Hamilton: CGI Programming 101,
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG.
Implementing Session Support COEN 351. State Maintenance Client Side Mechanisms  Cookies Client needs to allow cookies Cookie handling done by browser.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
Databases and Perl Using Perl to talk to databases.
Python Web Applications A KISS Introduction. Web Applications with Python Fetching, parsing, text processing Database client – mySQL, etc., for building.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class One Instructor:
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
The GUS 3.0 Perl Object Layer CBIL Jonathan Schug June
Introduction to Perl Part III By: Cedric Notredame Adapted from (BT McInnes)
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
Set 5: Perl and Database Connections
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
INTERNET APPLICATION DEVELOPMENT For More visit:
Csc122 - Term Project Presentation, Fall 2005 Advanced Personal Organizer 1 Web Database Systems Term Project Presentation Advanced Personal Organizer.
Survey of Advanced Perl Topics Database access "OpSys"-like functions Signal Handling Inside-Out Objects.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
DBI tutorial February 5 th, What is DBI DBI is short for Database Interface, which is a Perl module DBI is short for Database Interface, which is.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
The MySQL General Purpose Routine library Giuseppe Maxia.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSC 2720 Building Web Applications Database and SQL.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
Templates, Databases and Frameworks. Databases: DBI Common database interface for perl Provides a functional,
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Databases On The Web with perl Archie Warnock
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
How to create a simple Web application with CGI::Application Template::Toolkit and DBIx::Class Leonard Miller February 7, 2009.
JDeveloper 10g and Oracle ADF Business Components Getting the Most Out of Your Data Avrom Roy-Faderman Senior Programmer November, 2005.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
Web Programming Language Week 7 Dr. Ken Cosh PHP and storage.
Google App Engine Data Store ae-10-datastore
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Java, JDBC, Perl, CGI Embedded SQL November 3 rd, 2000.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Four Instructor:
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
NMED 3850 A Advanced Online Design January 14, 2010 V. Mahadevan.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 1 Intermediate Perl Programming Class Two Instructor:
CHAPTER 10 PHP MySQL Database
Final Project Creating an interfaces to manipulate tables Professor. Jon Degallier Professor. Jon Degallier Student Name: Mahfuz Talukder Ohlone College.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
COMP234 - perl Perl DBI Topics Database vs access methods DBMS and DBMS API's Relational database SEQUEL Perl DBI SQL.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
The Web Wizard’s Guide to PHP by David Lash
Databases.
Perl Database – Just Enough
Advanced Topics Web Programming.
PHP and MySQL.
Data Management Innovations 2017 High level overview of DB
SQL NOT NULL Constraint
SQL AUTO INCREMENT Field
Presentation transcript:

How to create a simple Web application with Web::App Template::Toolkit and Class::DBI Leonard Miller June 17, 2008

Who is this talk for?

Need to write web applications

Who is this talk for? Need to write web applications Don’t want/cannot have a heavy framework

Who is this talk for? Need to write web applications Don’t want/cannot have a heavy framework Experienced Programmers.

Who is this talk for? Need to write web applications Don’t want/cannot have a heavy framework Experienced Programmers. Know about CPAN, how to learn from CPAN’s documentation.

Who is this talk for? Need to write web applications Don’t want/cannot have a heavy framework Experienced Programmers. Know about CPAN, how to learn from CPAN’s documentation. Newer programmers that could use a new/better way to organize their code.

Why these three Modules? Separate out the code to MVC Pieces Each can be used/tested alone The modules themselves are easy to use and understand

Why not Catalyst? mod_perl/fastcgi: You don’t always have the access on the machine to get Catalyst to work. CGI::Application is a ‘lite’ framework, and as such is much smaller. Not as big and scary. Trivial to install in a local ~/lib dir

What is MVC MVC stands for Model-View-Controller

What is MVC MVC breaks the work into three parts

What is MVC MVC breaks the work into three parts 1.Model - Short for database model. Class::DBI does all the database work: inserts/queries.

What is MVC MVC breaks the work into three parts 1.Model - Short for database model. Class::DBI does all the database work: inserts/queries. 2.View - Template::Toolkit does all the view/html work.

What is MVC MVC breaks the work into three parts 1.Model - Short for database model. Class::DBI does all the database work: inserts/queries. 2.View - Template::Toolkit does all the view/html work. 3.Controller - CGI::Application holds all the logic to glue the Model and the View together.

What is MVC Who has seen code like this: use DBI; my $sql = "select * from users"; my $dbh = DBI->connect( $ds, $un, $pw ); my $sth = $dbh->prepare($sql); $sth->execute(); print "Content-type: text/html\r\n\r\n"; while (my $h = $sth->fetchrow_hashref()) { print ”Name is:".$h->{'first_name'}." \n"; }

What is MVC Who has seen code like this: my $q = new CGI; if ($q-> param('first_name' eq ''){ print input_form(); } else{ my $sql = "insert into users..."; my $sth = $dbh->prepare($sql); $sth->execute(); print submission_form(); }

What is MVC Any questions regarding what MVC is?

CGI::Application A sample program Helloworld.cgi <- config info HelloWorldCgiApp.pm <- controller Html files: <- View –header.html –body.html –footer.html MyDatabase.pm <- Model

CGI::Application helloworld.cgi: use HelloWorldCgiApp; my $helloworld = HelloWorldCgiApp->new(); $helloworld->run();

CGI::Application helloworld.cgi (with config info): use HelloWorldCgiApp; my $helloworld = HelloWorldCgiApp->new ( PARAMS => { tt_config => { INCLUDE_PATH => ".", PRE_PROCESS => 'header.html', POST_PROCESS => 'footer.html', }, hw_string => "hi there big earth!", }, ); $helloworld->run();

CGI::Application HelloWorldCgiApp (continued): package HelloWorldCgiApp; use base 'CGI::Application'; use Template; sub setup { my $self = shift; $self->run_modes( 'mode1' => 'start’, 'mode2' => 'sec_page' ); $self->start_mode('mode1'); }

CGI::Application HelloWorldCgiApp (continued): package HelloWorldCgiApp; use base 'CGI::Application'; use Template; sub setup { my $self = shift; $self->run_modes( 'mode1' => 'start’, 'mode2' => 'sec_page' ); $self->start_mode('mode1'); } $q -> param (‘rm’);

CGI::Application HelloWorldCgiApp (continued): sub start { my $self = shift; my $tt_config = $self->param(‘tt_config’) my $tt = Template->new( $tt_config ); $tt->process('body.html', { hwstr => 'hi big planet!!!', }, \$html); return $html; }

CGI::Application HelloWorldCgiApp (continued): sub cgiapp_prerun { my ($self, $runmode) my $q = $self->query; }

Class::DBI The mysql table: CREATE TABLE users ( user_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, first_name varchar(75) NOT NULL, last_name varchar(75) NOT NULL, country_code CHAR(2) NULL );

Class::DBI MyDatabase.pm: package MyDatabase; use base 'Class::DBI'; MyDatabase->connection('dbi:mysql:db',‘user’,’pw'); MyDatabase -> table('users'); MyDatabase -> columns( All => qw/user_id first_name last_name country_code / ); MyDatabase -> columns( Primary => user_id );

Class::DBI Using the Class::DBI Module HelloWorldCgiApp.pm: use MyDatabase; = MyDatabase -> retrieve_all; $tt->process('body.html', { users => ], }, \$html);

Class::DBI Using the Module use MyDatabase; = MyDatabase -> retrieve_all; my $user = MyDatabase -> retrieve( 1 ); $tt->process('body.html', { users => ], user => $user, }, \$html);

Class::DBI Using the Module – inserts: use MyDatabase; my $user = MyDatabase -> insert( { first_name => ‘Randall’, last_name => ‘Schwartz’, country_code => ‘US’, } );

Template::Toolkit Why use Template::Toolkit? –Common ‘look and feel’ templates. Easy to change for those people who are better at design than we are. –What type of data is It good for? arrays hashes scalars

Template::Toolkit Any html file is a TT file! Simplest usage for a scalar: [% var_name %]

Template::Toolkit Usage for an Array where users is an array: [% FOREACH item IN users %] [% item %] [% END %]

Template::Toolkit Usage for an Array where users is a hash: [%item.user_id%] [%item.first_name%] [%item.last_name%] [%item.country_code%]

Template::Toolkit Usage for an Array where users is an array of hashes (like an array of rows from a database): [% FOREACH item IN users %] [%item.user_id%] [%item.first_name%] [%item.last_name%] [%item.country_code%] [% END %]

Template::Toolkit Usage for an Array where users is an array of hashes (like an array of rows from a database): <input type=“hidden” name=“rm” value=“page_2” [% FOREACH item IN users %]... [% END %]

Questions?

Thank you Leonard Miller June 17, 2008