Very Brief Intro to Catalyst
Click here to load reader
-
Upload
zachary-d-blair -
Category
Technology
-
view
1.032 -
download
5
Transcript of Very Brief Intro to Catalyst
![Page 2: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/2.jpg)
What's a Web Framework?
a software framework for developming dynamic websites
E.g. Ruby on Rails (Ruby) Django (Python)
Catalyst (Perl)
![Page 3: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/3.jpg)
How Does It Fit?
Perl application using Catalyst
Databasee.g. MySql
Web Browser
Select * FROM.. HTTP Requests
![Page 4: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/4.jpg)
What Is Its Structure?
Each app has a directory structure that separates model, view, and controller modules.
/lib/AppName/Model/
/lib/AppName/View/
/lib/AppName/Controller/Root.pm
/root/static/
/script/hello_server.pl
Makefile.PL
![Page 5: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/5.jpg)
Model-View-Controller
Model: Stores and retrieves data (e.g. in a database).
Controller Receives/processes HTTP requests,
reading/manipulating data from the Model and forwarding it to the View for presentation to the user.
View Formats data for presentation to the user (usually
by generating HTML, but could also generate PDF, PNG, etc).
![Page 6: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/6.jpg)
●Install Catalyst (Ubuntu)
sudo aptitude install libcatalystperl libcatalystmodulesperl libconfiggeneralperl
![Page 7: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/7.jpg)
Create an Application
The ”catalyst.pl” script is used to create the initial application structure:
$ catalyst.pl Hello
$ cd Hello
![Page 8: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/8.jpg)
Start the Application
$ script/hello_server.pl
![Page 9: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/9.jpg)
View the Application
Navigate to:
http://localhost:3000
![Page 10: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/10.jpg)
How it Works
When you access http://localhost:3000/, Catalyst calls index() in /lib/Hello/Controller/Root.pm:
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
# Hello World
$c>response>body( $c>welcome_message );
}
![Page 11: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/11.jpg)
Extending the App
Add http://localhost:3000/hello Just add a new subroutine called ”hello” to
Root.pm:
sub hello :Local {
my ( $self, $c ) = @_;
$c>response>body( ”Hello!!!!” );
}
![Page 12: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/12.jpg)
What We've Got
If in a web browser, you query http://localhost:3000/foo,
in lib/Hello/Controller/Root.pm, a subroutine called ”foo()” is executed, and
foo() generates HTML that is sent back to the web browser.
![Page 13: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/13.jpg)
What Else Can Catalyst Do?
Access a database (e.g. MySql) Object-Relation Mapping
Retrieve user-entered data from HTML forms Generate nice HTML using templates
E.g. Using Template::Toolkit
Integrate with the Apache web server FastCGI protocol
![Page 15: Very Brief Intro to Catalyst](https://reader038.fdocuments.in/reader038/viewer/2022100602/55842558d8b42ac0658b4798/html5/thumbnails/15.jpg)
Thank You!
Zachary D. Blair
http://www.sfu.ca/~zblair