| 1 | package Apache2::Controller::Dispatch::RenderTemplate; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Apache2::Controller::Dispatch::RenderTemplate - | ||
| 6 | dispatch to controllers mapped by files in primary A2C_Render_Template_Path. | ||
| 7 | |||
| 8 | =head1 VERSION | ||
| 9 | |||
| 10 | Version 1.001.001 | ||
| 11 | |||
| 12 | =cut | ||
| 13 | |||
| 14 | 2 | ▶ | use version; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | our $VERSION = version->new('1.001.001'); | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | UNIMPLMENTED - AN AMBITIOUS AND INTERESTING SPEC | ||
| 20 | |||
| 21 | I am going on to write OpenID auth first but this is an idea for | ||
| 22 | an automatic dispatcher based on the template directory tree structure. | ||
| 23 | |||
| 24 | You do not need to subclass this A2C dispatch class. It assumes | ||
| 25 | controller library structure from the structure of html template files | ||
| 26 | and renders them with L<Apache2::Controller::Render::Template>. | ||
| 27 | |||
| 28 | # virtualhost.conf: | ||
| 29 | PerlSwitches -I/myapp/lib | ||
| 30 | |||
| 31 | <Location '/'> | ||
| 32 | |||
| 33 | # primary path looks like a web site; secondary 'cmp' = component templates: | ||
| 34 | A2C_Render_Template_Path /myapp/html /myapp/cmp | ||
| 35 | |||
| 36 | # what lib name do we prefix to the ucfirst()ed primary html files? | ||
| 37 | A2CControllerLibs MyApp::C | ||
| 38 | |||
| 39 | # set and go: | ||
| 40 | SetHandler modperl | ||
| 41 | PerlInitHandler Apache2::Controller::Dispatch::RenderTemplate | ||
| 42 | |||
| 43 | </Location> | ||
| 44 | # EOF | ||
| 45 | |||
| 46 | shell% find /myapp -type f | ||
| 47 | /myapp/cmp/loginbox.html | ||
| 48 | /myapp/cmp/newsticker.html | ||
| 49 | /myapp/cmp/quickmenu.html | ||
| 50 | /myapp/html/index.html | ||
| 51 | /myapp/html/foo.html | ||
| 52 | /myapp/html/foo/biz.html | ||
| 53 | /myapp/html/foo/baz.html | ||
| 54 | /myapp/lib/MyApp/C/Foo.pm | ||
| 55 | /myapp/lib/MyApp/C/Noz.pm | ||
| 56 | |||
| 57 | Except, you do not type the '.html' in the URL. They are named | ||
| 58 | so that you can easily look at the raw files with a local browser. | ||
| 59 | |||
| 60 | A URL with a corresponding file in /myapp/html will always render, | ||
| 61 | whether a specific controller is found or not. | ||
| 62 | |||
| 63 | Foo allowed_methods() is qw( default bar biz ) | ||
| 64 | Noz allowed_methods() is qw( default ) | ||
| 65 | |||
| 66 | / => index.html, no controller | ||
| 67 | ( would be MyApp::C::Default->default() ) | ||
| 68 | |||
| 69 | /yip => index.html, no controller | ||
| 70 | ( would be MyApp::C::Default->yip() or default() ) | ||
| 71 | |||
| 72 | /foo => foo.html, MyApp::C::Foo->default() | ||
| 73 | |||
| 74 | /foo/bar => foo.html, MyApp::C::Foo->bar() | ||
| 75 | /foo/bar/a/b/c => foo.html, MyApp::C::Foo->bar(qw( a b c )) | ||
| 76 | |||
| 77 | /foo/biz/a/b/c => foo/biz.html, MyApp::C::Foo->biz(qw( a b c )) | ||
| 78 | |||
| 79 | # cuts 'baz' from args because baz.html gets used: | ||
| 80 | /foo/baz/a/b/c => foo/baz.html, MyApp::C::Foo->default(qw( a b c )) | ||
| 81 | |||
| 82 | /noz/a/b/c => index.html, MyApp::C::Noz->default(qw( a b c )) | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 87 | 2 | ▶ | use warnings FATAL => 'all'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 88 | 2 | ▶ | use English '-no_match_vars'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 89 | |||
| 90 | 0 | ▶ | use Apache2::Const -compile => qw( HTTP_NOT_IMPLEMENTED ); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 91 | |||
| 92 | use Log::Log4perl qw(:easy); | ||
| 93 | use YAML::Syck; | ||
| 94 | use Carp qw( cluck ); | ||
| 95 | |||
| 96 | =head1 METHODS | ||
| 97 | |||
| 98 | =head2 handler | ||
| 99 | |||
| 100 | THIS MODULE IS UNIMPLEMENTED. | ||
| 101 | |||
| 102 | =cut | ||
| 103 | |||
| 104 | sub handler : method { | ||
| 105 | cluck __PACKAGE__." UNIMPLMENTED - AN AMBITIOUS AND INTERESTING SPEC"; | ||
| 106 | return Apache2::Const::HTTP_NOT_IMPLEMENTED; | ||
| 107 | } | ||
| 108 | |||
| 109 | 1; | ||
| 110 | |||
| 111 | |||
| 112 | =head1 SEE ALSO | ||
| 113 | |||
| 114 | L<Apache2::Controller::Dispatch> | ||
| 115 | |||
| 116 | L<Apache2::Controller> | ||
| 117 | |||
| 118 | =head1 AUTHOR | ||
| 119 | |||
| 120 | Mark Hedges, C<hedges +(a t)- formdata.biz> | ||
| 121 | |||
| 122 | =head1 COPYRIGHT AND LICENSE | ||
| 123 | |||
| 124 | Copyright 2008-2010 Mark Hedges. CPAN: markle | ||
| 125 | |||
| 126 | This library is free software; you can redistribute it and/or modify | ||
| 127 | it under the same terms as Perl itself. | ||
| 128 | |||
| 129 | This software is provided as-is, with no warranty | ||
| 130 | and no guarantee of fitness | ||
| 131 | for any particular purpose. | ||
| 132 | |||
| 133 | =cut | ||