<<

APPENDIX A

Compiling Your Own

Compiling Perl on a Unix-like system is simple. First, obtain the source for Perl from CPAN (dppl6++_l]j*lanh*knc+on_+NA=@IA*dpih). Then input the following sequence of commands:

 p]nvtrblanh)1*4*4*p]n*cv  _`lanh)1*4*4  od?kjbecqna)`ao  i]ga  i]gapaop  oq`ki]gaejop]hh

On most Unix systems, this code will result in your lanh being installed into the +qon+ hk_]h+ directory tree. If you want it installed elsewhere—for example, in the local directory in your home directory—then replace od?kjbecqna)`a with the following:

 od?kjbecqna)`ao)@lnabet9z+hk_]h+ which should enable you to install Perl on your computer without root access. Note that the )`ao flag uses all the default options for compiling Perl. If you know that you want nonstandard configuration, just use the flag )`a instead to be prompted for your requirements. Be aware that the source for Perl 5.10.0 requires a patch to work properly with . This is fixed in subsequent versions of Perl 5.10. If you need to test code guaranteed to run on a wide range of systems, you should con- sider using Perl version 5.8.7. Perl versions greater than 5.8.7 contain features that were not available in earlier versions of Perl, so Perl 5.8.7 is feature complete for all versions of Perl that Catalyst will run on (version 5.8.1 and later). Put another way, versions 5.8.8 and later have new features that you can’t rely on in earlier releases. This should only be important to you if you’re going to be programming libraries for CPAN that will be used very heavily, and you’re having to pay very close attention to Perl’s internals. Further details for installation of Perl are available in the EJOP=HH file in the Perl distribu- tion. If you are on a non-Unix system and you want to compile Perl, you will want to look at EJOP=HH*ukqnlh]pbkni (e.g., EJOP=HH*s/. for Windows) as well. However, for Windows we rec- ommend Strawberry Perl (dppl6++opn]s^annulanh*_ki).

315 316 APPENDIX A N COMPILING YOUR OWN PERL

Once you’ve compiled Perl, you need to sure that your L=PD environment variable is set. Assuming you installed Perl into +hk_]h, you need to put +hk_]h+^ej in your path. The best way of doing this (assuming that your shell is Bash) is to put the following in your *^]odn_:

atlknpL=PD9 DKIA+hk_]h+^ej6 L=PD atlknpI=JL=PD9 DKIA+hk_]h+i]j6 I=JL=PD

Issue the command a_dk ODAHH and ensure that the output is +^ej+^]od or at that it at least ends in +^]od to make sure that you’re using the Bash shell. Once you’ve done this, you need to either log off and then log in again or issue the follow- ing command from the shell:

okqn_a*^]odn_

Patching Perl 5.10.0 to Work (Properly) with Catalyst Details on how to fix this issue are described here: dppl6++sss*jjpl*lanh*knc+cnkql+lanh* lanh1*_d]jcao+.,,4+,.+ioc.--,2*dpih. Condensing the instructions from this bug report, you should download Perl 5.10 (dppl6++ sss*_l]j*knc+on_+lanh)1*-,*,*p]n*cv). Prior to following the instructions in the main part of this appendix, modify the file pkga*_ (pklharah) on line 692 as follows (presented in diff for- mat):

 ahoa l]noan):jatppkga9,7  aj`eb 'l]noan):annkn[_kqjp9kl]noan;kl]noan):annkn[_kqjp6,7 l]noan):_klheja9JKHEJA7 l]noan):hat[op]pa9HAT[JKNI=H7 l]noan):atla_p9TOP=PA7 APPENDIX B

Making Your Own CPAN Mirror with CPAN::Mini or minicpan.sh

Catalyst is very heavy on CPAN dependencies, so it can be useful to have your own CPAN mirror on your local machine or local network. Using CPAN::Mini, especially on a slow net- work, speeds downloading of CPAN modules dramatically and is recommended for anyone doing a lot of Perl development. CPAN::Mini is available by installing it from CPAN. An alternative is ieje_l]j*od, which is available from dppl6++pnkqp*ia*qg+lanh+iennkn*od*ptp. We’ll describe using CPAN::Mini here. The advantage of the ieje_l]j*od script is that you can uncomment a single line and get a full CPAN mirror. ieje_l]j*od is also a good bit faster than CPAN::Mini. First, install CPAN::Mini from the shell:

 _l]j?L=J66Ieje

Next, create a *ieje_l]jn_ file in your home directory with the following content:

hk_]h6+l]pd+pk+ukqn+_l]j+iennkn naikpa6dppl6++ukqn*_hkoaop*_l]j*iennkn at]_p[iennkn6-

Then you can run the ieje_l]j command from your shell:

 ieje_l]j

The first command installs CPAN::Mini, and the second makes a mirror of the fairly com- plete contents of the most relevant parts of the CPAN archive. Once this is done, you can configure CPAN to use your local mirror:

_l]j _l]j:k_kjboapqnhheopbeha6+++dkia+g`+ieje_l]j+ _l]j:k_kjb_kiiep

317 318 APPENDIX B N MAKING YOUR OWN CPAN MIRROR WITH CPAN::MINI OR MINICPAN.SH

Note that you need to use the absolute path to the ieje_l]j directory in your home direc- tory as just shown. You can update your mirror at any time by reissuing the ieje_l]j command. As noted, it’s best to have this as an automated job running daily.

Browsing Your minicpan on the Web You can install the module CPAN::Mini::Webserver from CPAN to provide a web to browse your current ieje_l]j. Once the module is installed, you just run the command ieje_l]j[sa^oanran from the shell, and then point your browser to dppl6++hk_]hdkop6.52/ (although the port is configurable). From here, you can make your ieje_l]j and web server accessible over the local network so that small groups can use the local mirror. Index

Numbers and Symbols ActionClass attribute, 237 502 (bad gateway) response code, 227 creating to serialize the stash to the re- & (ampersand), parameters separated by, 26 sponse body, 240 \ (backslash) character, for breaking long line action classes, as type of Catalyst::Controllers, of shell command, 29 237 + (plus) symbol, in code, 239 ActionClass('REST') attribute, 225 *:Args, using, 106 action for, 171 *:CaptureArgs(0), 98 actions */error_404 action, 99 adding new to application, 238 */name/who/add, calling to update in Reaction UI, 307 of residents, 185 of Interface Model, 306 *:PathPart, 98 add_unique_constraint, adding unique in- $->authenticate call, adding additional argu- dexes to, 143 ment to, 287 all_from directive, in default Makefile.PL file, $c->authenticate() call, altering to reflect new 57 requirements, 205 ALTER TABLE statement, running to update $c->check_any_user_role() method, example table in SQLite database, 146 using, 192 ampersand (&), parameters separated by, 26 $c->check_user_roles() method, example AnnoCPAN, website address, 45 using, 192 Apache $c->detach, demonstrating use of with code, external configuration, 120 178 modules that deal with FastCGI, 119 $c->forward, demonstrating use of with code, static configuration, 119 178 using as a back end to front-end proxy, 125 $c->go, flow control logic for, 180–181 Apache::Registry, 12 $c->logout() method, calling to de-authenti- Apache web server, 115–116 cate a user, 206 load balancing, 115 $c->model('Textile')->textile method, calling website address for obtaining, 115 from controller code, 242 API access, within your application, 285 $c->push stack() helper method, adding to API authorization, persistent login and, application, 182–183 281–285 $c->req->args, overriding values of for a for- App::Ack (CPAN), installing, 128, 129 ward or detach, 179–180 Apple, Perl in OS X 10.3 and later, 22 $c->textile method, adding into MyApp, 242 application $c->user_exists() call, 207 adding authentication for web portion of, $c->user() method, returning current user 74–75 with, 207 adding new features to, 97 $c->visit, flow control logic for, 180–181 as pure UI, 82 $self->next::method(@_) call, 239 extending, 96–102 $userid value, validation, 156 getting started writing, 59–60 normal approach to designing, 82–83 A requiring authentication for, 79 running first code from a test, 83 ab tool, in Apache, 123 running parts of as stand-alone script, ACCEPT_CONTEXT method, 254–255 277–278 access_denied action application example, in Reaction, 308 adding to lib/SneakyCat/Controller/Ideas. apply_label argument, in Reaction Root con- pm, 213 troller, 313 Acme::EyeDrops, output during installation Apress, website address, 195 of, 130 Arguments, in create scripts documentation, Acme::LOLCAT module, required in default 139–140 Makefile.PL file, 58 319 320 NINDEX

attributes base controllers adding more than one new, 240–241 adding multiple, 234 adding to controller actions, 237–241 in Catalyst, 233–234 cleaning up multiple with roles, 241 intelligent use of, 272–274 Auth::Schema argument, in create scripts Bash aliases, to make starting development documentation, 140 server easier, 299–300 Auth::Schema::Result::UserRoles, 144 begin action, uncommenting in each control- Auth::Schema::Result::Users class, adding ler, 174 code to for checking validity of e-mail, BEGIN block, using in controllers, 241 153 begin dispatch type, 171 AuthDB argument, in create scripts documen- belongs_to relationship, arguments to, 144 tation, 139 blib, 132 auth.db database file, 138 blocking server, built-in server as, 111 authdb., updating to add column to users browsers, quickly resolving compatibility is- table, 146 sues, 255–258 authenticated user, working with, 216–218 browsing your Minicpan on the web, 318 authentication BSD, Catalyst needs preinstalled on, 22 adding for web portion of application, bug tracker, open source CPAN RT service, 45 74–75 BUILDARGS subroutine, in , 42 and authorization, 189–218 _build_greeting subroutine, 34 function of authenticate call, 205–206 _build_schema method, 224 requiring for the whole application, 79 BUILD subroutine, in Moose, 42 requiring for web services requests only, _build_translators, refactoring, 90 75–79 built-in server requiring in the application, 75–79 as blocking server, 111 the three parts of, 189–192 deploying with, 110–111 working with after login, 207–208 test for, 110 authentication and authorization, in Catalyst, using, 109–117 7 business logic errors, interlude spotting, 96 authentication configuration byte, 27 adding realms to, 286–287 examining store portion of, 199–200 C authentication keys, 282–285 Cache, deploying public-facing site with, authentication realms, 190–191 289–292 auth key-based authentication, adding new Cache-Control header, two forms of, 289–291 realm for, 283–284 can_whisper role, creating, 212–213 auth_key column, adding to your user table, Cascading Style Sheets (CSS), for styling 282–283 HTML, 201–203 auth key token, 282 Catalyst authkeyusers realm, adding, 283–284 application deployment, 8 authorization authentication check, 190 adding finer-grained access control to authentication realms, 190–191 SneakyCat with, 211–215 automated testing in, 8 authentication and, 189–218 background knowledge, 24–44 authorization with roles, in authentication, base controllers, 233–234 192 basic dispatch process, 169–171 auto action, uncommenting in controller, 175 choosing hardware and software, 19–21 auto dispatch type, 171 connecting to database from, 136–137 autohandler, creating in root/templates direc- dependency installation, 128–132 tory, 265–266 dynamically generating barcodes from, AUTO INCREMENT field, in table, 138 260–261 auto_install directive, in default Makefile.PL extending, 233–245 file, 57 extending with plug-ins, 242–245 automated testing, in Catalyst, 8 flowchart representing request cycle, 167 handling legacy GI scripts in, 270–272 B high-level session management in, 7 barcodes, dynamically generating from Cata- how it prepares before dispatch, 169 lyst, 260–261 installation from CPAN, 24 base action, in Reaction Root controller, 313 installing, 19 BaseController directory, creating in lib/ logging in, 7 MyApp from application root, 233 miscellaneous recipes, 277–292 NINDEX 321

Model/View/Controller (MVC) in, 247–277 catalyst line, in default Makefile.PL file, 57 MVC architectural pattern used by, 2–6 Catalyst mailing list, website address, 45 recipes related to the development process, Catalyst::Model::Adaptor, 87 292–301 usage with model, 221–222 release of 5.7, 2 Catalyst Model, creating, 139–141, 251 template options for, 8 Catalyst::Model::Factory, 254–257 types of actions built into, 170–171 Catalyst::Model::Factory::PerRequest, 254–277 usage and history, 2 Catalyst models, brief introduction to, 65 use of session management plug-ins in, 7 catalyst.pl DispatchTest, 171–177 using web services within, 219–231 catalyst.pl DwarfChains, creating new appli- vs. CGI, 9–11 cation with, 181 vs. CGI::Application framework, 14–16 catalyst.pl script, looking at code generated vs. Jifty, 16 by, 59–60 vs. other frameworks, 13–16 Catalyst::Plugin::Authentication module, Catalyst application installing, 193 adding cache control to, 289–291 Catalyst::Plugin::Authentication namespace, 7 getting started writing, 59–60 Catalyst::Plugin::Authorization::Roles module, process of installing, 127 194 setting up web service in, 220–223 Catalyst::Plugin::Server, 245 Catalyst::Authentication::Credential:: Catalyst::Plugin::Session module, installing, Password module 194 job of, 198–199 Catalyst::Plugin::SmartURI plug-in, 244 Catalyst::Authentication namespace, 7 Catalyst::Plugin::Static::Simple plug-in, Catalyst::Authentication::Store ::DBIx::Class 244–245 module, 199–200 Catalyst.pm methods overridden by, 244 installing, 193 Catalyst::Plugin::, using in Makefile. Catalyst::Controller, creating new Startup, 233 PL file, 58 Catalyst controller action method vs. Catalyst::Test CGI::Application runmode method, advanced usage of, 294–295 15–16 new feature of, 295 Catalyst::Controller::ActionRole, DOES attri- testing against a running server with, 69–71 bute provided by, 241 Catalyst::View::Component::Subinclude, Catalyst::Controller::CGIBin, handling legacy 269–270 GI scripts with, 270–271 Catalyst view, creating, 236 Catalyst controller code, using connection Catalyst::View::Email::Template, 275–277 information in, 252 Catalyst::View::GD Catalyst::Controller::HTML::FormFu, website changing generated index action, 259 address, 150 dynamically generating graphics with, Catalyst::Controller module, implementation 259–260 of built-in subroutine attributes in, installing, 259 170 output from, 260 Catalyst::Controller::reCAPTCHA, integrating Catalyst::View::, installing from CPAN, into your application, 267–268 264 Catalyst::Controller::REST Catalyst-View-SerialiseStashKey directory, 235 creating some tests for, 226–227 CatalystX::REPL installing from CPAN, 225 alternative to perl -, 300–301 Catalyst::Controller::WrapCGI, handling example session from application, 300 legacy CGI scripts with, 271–272 CatalystX::Starter, alternative to Catalyst cookbook, 247–301 Module::Starter, 235 categories of recipes, 247 CGI vs. Catalyst, 9–11 CATALYST_DEBUG variable, suppressing, 150 CGI::Application, early Perl , 2 Catalyst Dispatcher, 167–188 CGI::Application framework, Catalyst vs., Catalyst::Helper, 53 14–16 directories created by, 55 CGI::Application runmode method vs. Cata- Catalyst::Helper::AuthDBIC module, using to lyst controller action method, 15 provide authentication, 74–75 CGI engine, tests for, 109 Catalyst::Helper::DBIC::Schema, creating the CGI.pm, routine for generating HTML, 9 Catalyst Model with, 139–141 CGI.pm module, 1 Catalyst::Helper::Model::DBIC::Schema, mak- CGI script, lolcatalyst_lite_cgi.pl, 55 ing Catalyst model with, 251 Chained('/'), indicating root of chain with, 98 #catalyst IRC channel, 45 Chained actions, 150 322 NINDEX

chained controller, 97–99 CPAN::Mini, installing, 317 Chained dispatch type, 181–187 CPAN::Mini::Webserver module, installing, Chaining, across namespaces, 184–187 318 Changes file, keeping up to date, 54 . command, 130–131 Chart::Clicker, website address, 264 CPAN dependencies, in MojoMojo, 279 Class::MOP, 90 CPAN home page, searching, 46–47 classes, naming, 86 CPAN index, searching, 48 clean command, CPAN, 48 CPAN mirror, making your own, 317–318 cmp_ok method, 35 CPAN module Module::Starter, installing, 29 code error, outputting from die call, 154 CPAN modules code smell, 39 for connecting to database from Catalyst, coercion, in Moose, 44 136 collections testing and test failures, 48–52 displaying in Reaction, 307 CPAN Ratings, website address, 45 of Interface Model objects, 306 CPAN RT service, website address, 45 Collections class, 249 CPAN Testers service, website address, 45 columns method, 151 create script, lolcatalyst_lite_create.pl, 55 comma-separated values (CSV) file, output- create scripts documentation, arguments in, ting from a controller action, 258 139–140 components, 145–147 create=static arguments, in Catalyst::Model:: Comprehensive Perl Archive Network (CPAN). Helper::DBIC::Schema create scripts See also CPAN documentation, 140 website address, 8 create template, 100 configuration credential verifier (Credential), 191 Config::Any for list of supported formats, CRUD, simple, 150–151 55 current_view stash key, setting, 263 overriding public dispatch paths with, custom attributes, adding to controller ac- 187–188 tions, 237–241 connection information, putting into myapp. conf, 251 D constants file, placing configuration in, -D flag, 113 294–295 , dealing with, 149–165 controller actions, database adding user defined attributes to, 237–241 adding new user to, 75 outputting CSV from, 258 choosing and connecting to, 135–137 Controller::Root code, replacing generated, connecting to from Catalyst, 136–137 267–268 connection string, 140 controller methods, for making a request to designing and creating for sample applica- controller, 227 tion, 137–138 Controller/Root.pm, modifying, 100 getting data to our application from, cookie, development of, 24 149–150 C::P::Auth module. See Catalyst::Plugin:: database file, loading into SQLite, 196 Authentication module database models, 135–166 CPAN database systems basic usage of, 47–48 deploying to a different, 147–149 Catalyst::View modules on, 236 popular, 135–136 Catalyst installation from, 24 database tables, creating to store users of ap- Clean command, 48 plication, 138 configuring to use your local mirror, data type, changing for , 228–229 317–318 data_type column_info key, in Users Result home page website address, 46 class, 143 install command, 48 DB2 database system, website address, 135 look command, 48 DBD:SQLite, SQLite embedded in, 136 making the most of, 44–52 DBIC::Schema argument, in create scripts premade Catalyst model modules in, 137 documentation, 139 search strategies for, 45–47 DBIC_TRACE environment variable, running setting up, 23 to see SQL generated by DBIx:Class, upgrade command, 48 150 used by Catalyst, 19 website for module search and documen- tation, 45 NINDEX 323

DBIx::Class dwarfchains.conf, adding configuration to, DBIx::Class store, 199–200 187–188 DBIx::Class::Tree component DwarfChains.pm, changing push stack sub- displaying tree structures in web pages routine in, 186 with, 249 Dwarfs controller, 175–176 output of tree structure from JSON input making separate as part of application, using, 253 173–174 schema, files in lib/ directory, 141 dynamic FastCGI, 118 exploring DBIx::Class::Schema files, 141–147 E importing existing schemas to, 248–249 Edge Side Includes (ESI), 270 including DBIx::Class::Timestamp compo- e-mail address, catching invalid and display- nent, 146 ing error page, 153–154 update method on DBIx::Class::Row, email stash key, changing content of, 277 158–159 Email::Template view, adding and configur- and Ubuntu, Perl included with, 21 ing, 275 debugger breakpoints, adding, 73 email.tt template, adding into application debugging, turning on, 104 root/ directory, 276 default : Path, 172 Email::Valid module, checking validity of an default translation target, storing so $transla- e-mail with, 153 tor->translate can work, 88 emastic, website address, 255 Delete Me button, adding to user's profile Embedding Perl in HTML with Mason, by page, 163 Dave Rolsky and Ken Williams, 267 DELETE request, 228 end action, 172 Deployment, 109–133 called as part of the request cycle, 174 options for Catalyst applications, 8 providing custom error page with, 64,156 Devel::REPL error handling code, changing to output er- alternative to perl -d, 300–301 rors to the log, 104–105 demonstrating usage of, 300 event system, in Reaction API, 305 development process, recipes related to Cata- execute method, 237 lyst, 292–301 exercise development server for adding roles to users, 163 Bash aliases to make starting server easier, for updating users, 159 299–300 external FastCGI, 118 fork option, turning on, 110 verifying that application works manually, F 67–73 -f flag, 113 script, lolcatalyst_lite_server.pl, 55 FastCGI, 8 diag function, using instead of print state- deployment of, 117–123 ment in tests, 31 deployment on shared hosting, 118 die, using for error handling, 156 introduction to, 12 directories, top-level, 54–55 other web servers that support, 123 dispatcher seven dwarfs script rewritten to use, 12 basic process, 169–171 tests for engine, 109 two special types, 171–177 FastCGI script, lolcatalyst_lite_fastcgi.pl, 55 distribution directory, making, 29–31 fat controller, approach to MVC, 4–5 do_apply method, 310 Fedora, installing, 21 Domain Model field_order argument, in Reaction Root con- in Reaction, 303 troller, 313 in Reaction API, 306 filename parameter, 258 driver model, for generic translation, 88–89 files and directories, 54–56 DwarfChains::Controller::Info, adding code to, find method, of DBIx::Class::ResultSet, 186–187 155–156 DwarfChains::Controller::People, creating, focus stack, 307 183–184 FOREIGN KEYs, 138 DwarfChains::Controller::Root, creating new FOREIGN KEY statements, in Auth database, application with, 181–187 143 DwarfChains::People::Info controller form action, in Reaction Root controller, 313 creating, 184 mapping of public URLs to method names, 184–185 324 NINDEX

G Catalyst::Plugin::Authorization::Roles GD (graphics display) module, 194 library for generating graphics, 259–260 Catalyst::Plugin::Session module, 194 website address for Windows installation, CPAN module Module::Starter, 29 259 required modules, 193–194 generic translation, driver model for install script directive, in default Makefile.PL LolCatalyst::Lite, 88–89 file, 57 GET and POST parameters, dealing with INTEGER, for artificial column, 138 separately, 63 Interface Model in Reaction, 303, 305, 306, 311 get ready action, 184 interludes GET request, adding query parameters in, 26 converting snippets to be object based, Git, 20, 126 101–102 graphics, dynamically generating with LolCatalyst::Lite::Model::SnippetStore, Catalyst::View::GD, 259–260 94–96 Graphics::Primitive, producing graphs with, spotting business logic errors, 96 262–264 internal request flow control, 177–181 Graphs, producing with Chart::Clicker and introspection, provided by metaprogram- Catalyst::View::Graphics::Primitive, ming, 304 262–264 in-word scrambler implementing, 91–92 H test for translator, 93 Half Object Plus Protocol pattern, 4 hashref construction, hard-coding, 89 J hash reference, added to matches in catchall JavaScript Object Notation (JSON), used for action, 172 web service view, 58 has_many method, using, 143 Jifty, Catalyst vs., 16 has_role method, implementing in template, jQuery Dynatree extension, website address, 161 252 HEAD request, making rather than a GET jQuery JavaScript framework, website address, request, 26 252 Hello World example, using , jQuery UI enhancements, website address, 252 9–10 JSON request, 72–73 HTML::Mason templating system, 264–267 JSON-RPC, 230 HTML view, setting as default view, 66 JSON view, adding to the application, 66 HTTP::Recorder, to bootstrap behavior tests, 8 HTTP request, anatomy of, 25–28 K HTTP specification information, website ad- -K option (keepalive), 111 dress for, 28 kitty pidgin (LOLspeak), 53 HTTP Wikipedia entry, website address, 28 website address, 54 Hypertext Transfer Protocol (HTTP), basics of, 24–44 L Langworth, Ian, Perl Testing: A Developer's I Notebook by, 299 Ideas controller Layout, in Reaction API, 306 adding a whisper action to, 212 LayoutSet in SneakyCat application, 195 in Reaction, 313 idea sharing page, creating, 207–208 in Reaction UI, 307 IE7 JavaScript library, website address, 256 lazy_build key, 34, 88 index action, 179 libjpeg library, website address, 279 index file, creating in root/templates direc- lib/Catalyst/View/SerialiseStashKey, creating tory, 266 class declaration in, 235 index method, changing in Root controller, lib/ directory, 55 263–264 files of DBIx::Class schema in, 141 index.tt template, 63, 269 lib/DwarfChains.pm file, adding subroutine inheritance, in Moose, 42 to, 182–183 install command, CPAN, 48 lib/LolCatalyst/Lite/Translator.pm file, creat- installing ing, 84–85 Catalyst::Authentication::Store::DBIx::Class lib/MyApp/Action/EnsureEncryption.pm, module, 193 class created in, 238–239 Catalyst::Plugin::Authentication module, lib/MyApp/View/Email/Template.pm, creat- 193 ing and configuring, 275 NINDEX 325 lib//LolCatalyst/Lite/ControllerB/Translate. M pm, writing code to attach /translate/ Mac OS X, making system daemons on, 114 to an action, 98 Mac OS X developer tools (Xcode), included lib/SneakyCat.pm, editing plug-ins and add- on Mac installation media, 22 ing to the use Catalyst section, 197 Mailer::Send Interface Model action, 309–310 lib/SneakyCat/Controller/Ideas.pm file, add- MailerExample::InterfaceModel::Mailer::Send ing can_whisper role to, 212–213 class, types in, 310 libxml library, required by MojoMojo, 279 mailerexample_ui.conf file, editing, 311 (lighty) web server, 112 mailer interface model, in Reaction example compiling from source, 112–114 application, 308 load-balancing features, 114 make catalyst par, bundling application with, obtaining, 112 127–132 web site address for , 112 Makefile.PL file, 54 distributions, Perl included with, 21–22 adding code to in Greeter directory, 32 List::Util module, making use of, 38 adding two genuine dependencies, 89 load balancing, considering for deployment, contents of default, 57 114 fixing up, 89–93 LocalRegex and Regex actions, 175–177 importance of, 57 Logging, in Catalyst, 7 installing dependencies, 58–59 login action modifications to, 58 creating, 204–206 removing bogus requires line for placing in lib/SneakyCat/Controller/ Acme::Bleach, 89 People.pm, 204 make_immutable, calling on the , 85 login page, creating, 203–204 make install, 127–128 logout action, creating, 206 make installdeps tool, installing application LolCatalyst::Lite dependencies with, 131–132 changing to set up the testing environ- make realclean, running to remove generated ment, 77 Makefile.PL, 132 starting, 53 make_schema_at method, debug option set LolCatalyst::Lite::Controller::Root, changing in, 249 index action in, 62 many_to_many relationship bridge method LolCatalyst::Lite::Controller::Root module, 55 arguments to, 145 LolCatalyst::Lite::Controller::Translate:: creation of set_roles method on user ob- Service ject, 163 making backward compatible, 274 Mason, website address, 267 writing new, 272–273 max-age Cache-Control header, 289 writing tests in t/controller_Translate_ Maypole, 2 Service.t, 273–274 Metaprogramming, in Reaction, 304–305 LolCatalyst::Lite::Model::SnippetStore, inter- methods lude, 94–96 adding per translation for extending the LolCatalyst::Lite::Model::Translate, translate() model, 87–96 method provided by, 84 naming, 86 LolCatalyst::Lite module, 55 SQL Server, website address, 136 extending, 81–108 minicpan command, running from the shell, LolCatalyst::Lite::Translator::LOLCAT code 317 moving into its own file, 89 .minicpanrc file, creating in home direc- updating to use Module::Pluggable::Object, tory, 317 90 minicpan.sh, alternative to, 317 lolcatalyst_lite_cgi.pl script, 55 . See roles, in Moose lolcatalyst_lite.conf file, copying to t/lib/ model lolcatalyst_lite_testing.conf, 77 capabilities of new, 82 lolcatalyst_lite_create.pl script, 55 extending, 87–96 lolcatalyst_lite_fastcgi.pl script, 55 model argument, in create scripts documen- lolcatalyst_lite_server.pl script, for develop- tation, 139 ment server, 55 model logic, extracting, 83–87 lolcatalyst_lite_test.pl script, for testing indi- Model/ file, creating for SnippetStore, 100 vidual URLs, 55 Model::Translator class, switching over to use lolcataylst_lite.conf file, 54 the external object, 86 LOLspeak. See kitty pidgin (LOLspeak) Model/View/Controller (MVC), 2–6, 247–277 look command, CPAN, 48 mod_perl, deployment on, 123–125 mod_perl Apache extension, 12–13 326 NINDEX

Module::Install N adding tests_recursive() to, 89 name directive, in default Makefile.PL file, 57 creating directory structure with, 53 named entities, 220 Module::Starter, 30 name/who, calling, 185 as basis for Moose example, 32 namespace::autoclean, 85 for starting new Catalyst::View, 235 namespace::clean, 85 Module::Pluggable::Object object, 90 namespaces, chaining across, 184–187 updating LolCatalyst::Lite::Translator::LOL navigation CAT code to use, 90 adding login and logout processes to, 208 module search and documentation, CPAN modifying for permission check, 214 website for, 45 Net::Calais, modules used by, 220 Modules, installing the required, 193–194 new() method, 85 MojoMojo, 279–280 new() translator, as part of the public inter- initializing the database, 281 face, 103 installing, 279 (engine X) web server IRC channel #mojomojo, using on irc.perl. configuring and compiling from source, org server, 281 116–117 search index, directory path for, 280 installing, 116 starting up, 281 load balancing with, 117 tests, 279 no-cache Cache-Control header, 289 the Catalyst wiki, 278–281 NonEmptySimpleStr type, 310 website address for information, 279 notest install Module::Name command, Moose avoiding running tests in CPAN shell advanced features of, 41–44 with, 24 BUILD and BUILDARGS subroutines, 42 coercion in, 44 O custom type constraints in, 43 housekeeping, 42 Object Interface Model, 306 inheritance in, 42–43 object midchain part, providing simple, 99 object-oriented programming with, 28–44 objects, to render an Interface Model object, roles in, 43–44 307 Moose Cookbook documentation, 32, 42, 44 ok function, syntax for, 31 Moose::Util::TypeConstraints, 43 on_apply_callback, in Reaction Root control- MooseX::Types libraries, importing Str, Non- ler, 313 EmptySimpleStr, and EmailAddress one-to-many relationship, defining, 143 types with, 310 OpenCalais API key, website address, 220 Mouse, Mouse Lite, 29 OpenCalais web service MRO::Compat, 239 Root controller code, 220 multilanguage support, adding to application, setting up in a Catalyst application, 67 220–223 multirealm authentication, 288 OPTIONS request, 28 MVC software design, brief history of, 3–4 Oracle database system, website address, 135 MyApp::Action::SecureSerializeStash, creating new, 240–241 P myapp.bin executable, generating, 132 -p option, 111 MyApp Catalyst application _PACKAGE_, 90 configuration of, 13 .par file, making, 132 startup script for, 11 Password credential, 198–199 myapp.conf, putting connection information password_type configuration option, setting into, 251 to 'crypted', 199 MyApp.pm, helper methods in, 242–244 Path attribute, using for index and default ac- MyCalais::Model::Calais, gluing actual model tions, 170–171 into, 221–222 PATH environment variable, setting, 316 MyCalais::Processor class, writing, 222–223 path_to method, getting access to, 254 My Personal Home Page application, website PAUSE (Perl Authors Upload Server), website address, 297 address, 45 MySQL Perl Template Toolkit, option for Catalyst, 8 for MojoMojo database configuration, 280 People controller website address, 136 adding public parts of URL to configura- tion, 187–188 in SneakyCat application, 195 NINDEX 327

Perl::Critic and Perl::Tidy, enforcing code stan- prepare body method, request body dealt dards with, 292–293 with via, 169 Perl prepare method, in Catalyst.pm, 169 compiling on Unix-like system, 315–316 PRIMARY KEY, 138 CPAN website for obtaining, 315 print statement, using diag function instead installation instructions, 315 of, 31 obtaining and running on various plat- private action, 179 forms/systems, 21–23 in Catalyst, 170 use of underscore convention in, 91 process method, implementing, 235 writing to get a dump of an action, 301 production database, deleting user informa- Perl 5.10.0 tion from, 77 downloading, 316 profile action, creating, 156 note on bug in earliest versions, 20 Pro Git, by Scott Chacon, 20 patch required to work with Catalyst, 315 progressive authentication, 287–288 Perl Authors Upload Server (PAUSE), website Progressive realm, configuring, 287–288 address, 45 prove Perl script, 31 reverse proxy load balancer and web public dispatch paths, overriding with con- server, 117 figuration, 187–188 Perl Best Practices, by , 292 push stack subroutine, changing in Dwarf- Perl CGI script, 9 Chains.pm, 186 Perl::Critic Reaction enforcing code standards with, 292 arsenal, 304–307 website address for useful article about, basic UI components, 306–307 294 component UI framework, 303–314 Perl::Tidy, enforcing code standards with, 292 displaying collections in, 307 perl –d, alternative to, 300–301 Domain Model, 303 Perl debugger, documented in perldoc example application, 308–314 perldebug, 301 infrastructure, 305–306 perldoc Moose::Cookbook::Basics::Recipe1 Interface Model, 303 documentation, 29 metaprogramming in, 304–305 #perl IRC channel, 45 Object Interface Model, 306 PerlMonks, website address, 45 overview of, 303–304 Perl script ViewPorts, layouts, skins, and Widgets, 307 example of JSON, XML, and YAML formats, what it isn't, 304 61 Reaction API, components of, 305–306 for setting up new database with tables, Reaction Catalyst extension, 150 147–148 Reaction example application Perl Testing, by Ian Langworth, 299 Interface Model, 308 perl UnknownError.pm file, creating, 20 mailer interface model, 308 perl -v command, checking version of Perl running, 314 with, 21 send action, 308 persistence, in authentication, 191 setup, 308 persistent login Reaction::InterfaceModel::Object import, in and API authorization, 281–285 Reaction example application, 309 important notes about, 285 Reaction UI, actions, 307 per-user configuration, providing, 128 README file, 54 plug-in loading loop, adding code to, 94 realms plug-ins, extending Catalyst with, 242–245 adding to authentication configuration, plus (+) symbol, in code, 239 286–287 pod documentation, adding to the end of a Catalyst authentication methods, 283 package, 33 reCAPTCHA service. See Catalyst::Controller:: POST and GET parameters, dealing with reCAPTCHA separately, 63 recipes PostgreSQL categories of in Catalyst cookbook, 247 for MojoMojo database configuration, 280 miscellaneous in Catalyst cookbook, website address, 136 277–292 POST requests, 26–27 related to Catalyst development process, getting, 296 292–301 making manually, 26 Red Hat, Scalar::Util problem, 21 Pound reverse proxy server, 117 REFERENCES keyword in SQL, 138 Reflectors, of Interface Model, 306 328 NINDEX

Regex (regular expression) actions, types of, _scramble_block, calling, 92 175 script/lolcatalyst_lite_test.pl script, testing Regex attribute, using, 177 pages from command line with, 68–69 Regex dispatch type, calling the path with, 177 script/dbauthtest_create.pl, for argument relationship bridges, 145 examples in create scripts documen- relationships, between tables, 143–144 tation, 139 render method, implementing, 235 script/ directory, 55–56 Representational State Transfer (REST). See script/make_zotero_schema.pl script, RESTful web services 248–249 Requests, used by web applications, 27–28 self-contained controllers vs. URI routing via REST controller external file, 13–14 implementing, 224–228 sent action, in Reaction Root controller, 313 sketching out dispatch rules for, 224–225 SerialiseStashKey view, simple, 234–236 RESTful web services, 231 Serialization, changing the data type for, REST service 228–229 consuming a simple, 219 Server, getting to from development machine, creating web services with, 224–230 125–128 Result class files, updating and adding a new session management plug-ins, in Catalyst, 7 column to, 146 set_primary_key, 143 Resultsets, understanding to use DBIx::Class, set_roles action, adding to DBICTest:: 149–150 Controller::AuthUsers, 161–163 Results file, 142–143 share action. See also idea sharing page result_source method, 151 editing index action to detach, 208 reverse proxy, web servers for use as, 111–117 shared hosting, FastCGI deployment on, 118 rewrite rule, 118 SimpleDB option, creating a configuration Riedel, Sebastian, Catalyst original author, 2 with, 200 roles SiteLayout, in Reaction UI, 307 adding, 159–160 site_title attribute, in Reaction Root control- adding to users, 160–163 ler, 313 cleaning up multiple attributes with, 241 skin, setting up in Reaction, 311 enforcing the interface using, 93–94 SneakyCat application, 194–218 in Moose, 43–44 adding a relationship to User schema, 196 Roles plug-in, 192 adding finer-grained access control to, Rolsky, Dave, Embedding Perl in HTML with 211–215 Mason by, 267 creating and configuring, 195–200 Root controller creating authentication configuration in, adding auto method to, 284–285 197–198 adding private action to, 276 creating idea sharing page, 207–208 in Reaction, 311–313 defining many-to-many relationship in, making to render templates, 270 197 modifying the index action in, 276 front page for, 209 Root controller code, OpenCalais web service, has_many definition in, 196 220–221 HTML wrapper for, 200–203 root/ directory, for putting templates in, 55 installing required modules for, 193–194 Root end action, 290–291 many-to-many relationship in, 196 root/authusers/profile.tt, adding, 156–156 setting up login, 210 root/authusers/profile.tt template, adding setup, 200–203 roles.tt component to, 163 trying out, 209–210 root/components/roles.tt, adding template using authentication in, 203–206 component in, 160–161 working with authentication after login, root/static/ directory, static files included in, 207–208 55 sneakycat_create.pl, calling, 196 root/templates sneakycat.css file, 201–203 creating autohandler in, 265–266 SneakyCat.sql file, code for database file, 195 creating index file in, 266 snippet object, asking for information, 107 rsync utility, copying files with, 125 snippets converting to be object based, 101–102 S creating method for creation of, 98–99 Scalar::Util problem, checking for in Red Hat, testing storage of and that text is correct, 21 106 Schema file, 141–142 NINDEX 329 snippet store template component, adding in root/compo- adding test ensuring translator object is nents/roles.tt, 160–161 required, 103–104 template file modifying to hold reference to translator, creating, 151–152 103 for editing a user profile, 157–158 SnippetStore, creating a Model/ file for, 100 templates, adding, 100 snippet store object Template Toolkit creating new, 97 preferred over HTML::Mason, 264 viewing, 98 website address, 9 snippet.tt template, making, 269 templating systems Snow White and the 57 dwarfs alternative, 264–267 Moose example, 32–41 on CPAN, 267 example, 10–11 test, running with the prove -1 t/01-Member.t, SOAP, 230 35 source code Test Anything Protocol (TAP), for automated downloading from Apress website, 81 testing in Catalyst, 8 website address for obtaining, 84 test case, writing minimal to troubleshoot, spam, 268 297–299 SQL files, for creating a database, 149 test code SQLite, for MojoMojo database configuration, adding for DELETE request to tB/control- 280 ler_rest.t, 228 SQLite database adding in tB/controller_rest.t, 228 creating a directory for, 137 test harness configuration, placing in a con- setting up new database with tables with, stants file, 294–295 147 Test::Inline CPAN module, for embedding website address, 136 tests in code, 36 SQLite's command-line tool, website for Test::WWW::Mechanize::Catalyst, 296-297 introduction to, 139 Test::WWW::Mechanize::Catalyst Database SQLite SQL syntax, website for, 138 Fixtures, example application with Squid proxy server, 117 commentary, 295 Squirrel module, 29 test-driven debugging, 83 static content, serving with web server, testing Apache, 115 automated, 69–71 stop-start daemons, on Unix, 114 during development cycle, 67–73 stop-start script, for proper server deploy- testing code, ommiting tests with a SKIP ment, 114 block, 78–79 Strawberry Perl test plan, fixing, 71–72 preferred for Windows for Catalyst, 22 tests, in Catalyst-Runtime distribution, website address, 22 109–110 Str type, as Moose core type, 310 test server subinclude method, 252 results of requesting http://localhost:3000, subroutine attributes, 6 270 Subversion results of requesting http://localhost:3000/ tag in, 126 snippet, 270 website address, 20 thin controller, fat model MVC design, 5–6 sudo make install, for installing to system thin controller, smart model, 102–105 perl, 127 top-level directory, files contained in, 54–55 SUSE, installing, 22 traits. See roles, in Moose SVK, website address, 20 /translate/ create functionality, testing to see if it still translates, 101 T translate() method tags, in Subversion, 126 creating role indicating requirement for, tarball 93–94 making for application, 126 provided by LolCatalyst::Lite::Model:: sending to server and deploying, 127 Translate, 84 target_model attribute, 310 translate/$id/to/$type, supporting by chain- Tell page, linking to, 214–215 ing off object, 106 template translate_to controller creating your first in Catalyst, 62–64 adding guard clause to, 107 that displays the tree, 252–253 hooking up to, 107 Template::Declare, use of by Jifty, 16 writing test to verify it is right, 107–108 330 NINDEX

translate_to() method, 89 user table, adding auth_key column to, hooking up, 106 282–283 translator class Using Edge Side Includes with Catalyst, web- directory for tests for, 86 site address, 292 writing rudimentary test for code, 85–86 Using the Varnish cache with Catalyst, website tree class, 249 address, 292 Tree::AdjacencyList component, 250 t/01app.t, modifying to authenticate call to V translate_service action, 77 Varnish, website address for articles about, t/ directory, for scripts for automated testing 117 of applications, 56 version control checkout, 126 t/lib/db directory, making, 76 version control software, used by Catalyst TT (Template Toolkit) view, rendering HTML project, 20 for Catalyst applications with, 58 view action adding tests for new functionality, 105 U writing, 99 UI components, basic in Reaction, 306–307 View base class, in Reaction, 310 underscore (_), prepending to subroutine, 38 ViewPort UNIQUE INDEX, formed in primary key col- in Reaction API, 305 umn or columns, 138 in Reaction UI, 307 Unix systems views needs for compiling Perl on some, 23 adding different, 66 tests for, 110 brief explanation of, 61–62 update method, on DBIx::Class::Row, 158–159 view template, writing, 100 upgrade command call to, 186 W CPAN, 48 web application uri for, 171 adding authentication for web portion of, URI routing via external file vs. self-contained 74–75 controllers, 13–14 adding new features to, 97 URL dispatch action, in Catalyst, 6 building your first in Catalyst, 53–79 URL test script, lolcatalyst_lite_test.pl, 55 getting started writing, 57, 59, 60 use aliased, adding at top of Translator.pm, 94 overview of sample, 53–54 use parent 'Catalyst::Model::Factory', 255 requiring authentication in, 75–79 use parent 'Catalyst; use parent 'Catalyst, web applications, requests used by, 27 ACCEPT_CONTEXT subroutine code Web Client Programming with Perl, website for, 255 address, 28 user_roles argument, 144 web page view, 61 user_roles table, contents of, 138 web server, FastCGI deployment on, 118–123 users web services adding, 157 code for providing, 66 adding roles to, 160–163 flavors of, 231 creating, 150–154 interacting with in application, 219–231 deleting, 163–164 remaining options for, 229–230 displaying, 155–156 Web Services Definition Language (WSDL), exercise for adding roles to, 163 219 exercise for updating, 159 web services requests, requiring authentica- listing all and their roles, 164–165 tion for, 75–79 redirecting browser to view newly created, web service view, 61 154 website addresses removing, 163–164 AnnoCPAN, 45 updating, 157–159 Apple, 22 writing code to create, 152 Apress, 195 Users Result class article on setting up init script for back-end available columns described after the table, server, 114 142 BBC iPlayer, 2 primary key and indexes described in, 143 Catalyst::Controller::HTML::FormFu, 150 start of, 142 #catalyst IRC channel, 45 Users table, making controller for CRUD Catalyst mailing list, 45 operations on, 150 Chart::Clicker, 264 user Store, 191 NINDEX 331

Comprehensive Perl Archive Network Web TT view, creating new, 150 (CPAN), 8 whisper action, 212 CPAN home page, 46 Widget CPAN Ratings, 45 in Reaction API, 306 CPAN RT service, 45 in Reaction, 314 CPAN Testers service, 45 Williams, Ken, Embedding Perl in HTML with DB2 database system, 135 Mason by, 267 emastic, 255 Windows for Catalyst, Strawberry Perl pre- for examples of Chart::Clicker and ferred for, 22 Graphics::Primative, 264 Windows services, utility for making server for HTTP specification information, 28 script into a service, 114 for information about MojoMojo's features, Windows system, tests for, 110 279 World Wide Web, invented by Tim Berners- for introduction to SQLite's command-line Lee, 24 tool, 139 WRAPPER directive, in index.tt file, 63 for Mason details, 267 WRAPPER file, creating, 201 for obtaining Perl, 315 WRAPPER template, 256–258 for Perl 5.10.0 patch to work with Catalyst, wrapper.tt file, reflecting our configuration, 316 269 for SQLite SQL syntax, 138 www.example.com, anatomy of HTTP re- for Windows installation of GD, 259 quest, 25–28 Graphics::Primitive, 262 Half Object Plus Protocol pattern, 4 XYZ HTTP Wikipedia entry, 28 Xcode. See Mac OS X developer tools (Xcode) IE7 JavaScript library, 256 Xerox PARC, website address, 3 jQuery Dynatree extension, 252 XML-based web services, 231 jQuery JavaScript framework, 252 XML::Writer support, in Net::Calais, 220 jQuery UI enhancements, 252 XML-RPC (remote procedure calling using kitty pidgin (LOLspeak), 54 XML), 230 libjpeg library, 279 YAML, 55 libxml library, 279 Zotero, website address, 2, 248 Lingon GUI for making OS X system dae- Zotero::ResultSet::Collections, creating a class mons, 114 in, 250–251 Microsoft SQL Server, 136 Moose Cookbook, 32 My Personal Home Page application, 297 MySQL, 136 OpenCalais API key, 220 Oracle database system, 135 PAUSE (Perl Authors Upload Server), 45 Perl Compatible Regular Expressions (PCRE) library, 112 #perl IRC channel, 45 PerlMonks, 45 PostgreSQL, 136 rsync utility, 125 SneakyCat.sql file, 195 SQLite, 136 Strawberry Perl, 22 Subversion (SVN), 20 SVK, 20 Template Toolkit, 9 Test::WWW::Mechanize::Catalyst Database Fixtures example application, 295 using Edge Side Includes with Catalyst, 292 using the Varnish cache with Catalyst, 292 Vox, 2 Web Client Programming with Perl, 28 Xerox PARC, 3 Zotero, 2, 248