File Coverage

lib/Egg/Release.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Egg::Release;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: Release.pm 342 2008-05-29 16:05:06Z lushe $
6             #
7 2     2   727 use strict;
  2         3  
  2         96  
8 2     2   14 use warnings;
  2         5  
  2         161  
9              
10             our $VERSION = '3.14';
11              
12             our $DISTURL = 'http://egg.bomcity.com/';
13              
14              
15             1;
16              
17             __END__
18              
19             =head1 NAME
20              
21             Egg::Release - Version of Egg WEB Application Framework.
22              
23             =head1 DESCRIPTION
24              
25             Egg is MVC framework that is influenced from L<Catalyst> and developed.
26              
27             I want you to see the document of L<Egg> in detail.
28              
29             =head1 TUTORIAL
30              
31             It introduces the example of making the tinyurl site as a tutorial.
32              
33             Tinyurl registers long URL beforehand, and is the one to call and to redirect
34             URL that corresponds by the thing accessed specifying the registration ID for
35             URL that is.
36              
37             =head2 project
38              
39             First of all, a suitable project is made.
40             It generates it here as 'MyApp'.
41              
42             % egg_helper.pl project MyApp -o/path/to
43              
44             * 'egg_helper.pl' is a helper script generated beforehand.
45             Please look at the document of Egg about the making method.
46              
47             The authority of the directory is set.
48              
49             % cd /path/to/MyApp
50            
51             % chmod 777 cache tmp
52            
53             or
54            
55             % chown webserver cache tmp
56            
57             The access authority from the WEB server is set.
58              
59             =head2 Model
60              
61             L<Egg::Model::DBI> is used for the model. And, SQLite is used for DBD.
62              
63             The data base is '/path/to/MyApp/etc/myapp.db'.
64              
65             The table is prepared as follows.
66              
67             CREATE TABLE tiny_url (
68             id text primary key,
69             url text
70             );
71              
72             Please do not forget to make it read and write by the authority of the WEB server.
73              
74             And, the configuration of the model is done.
75              
76             % vi /path/to/MyApp/lib/MyApp/config.pm
77            
78             MODEL => [
79             [ DBI => { dsn=> 'dbi:SQLite;dbname=<e.dir.etc>/myapp.db' } ]
80             ],
81              
82             It is a description of the replace function of <e.***> Egg because to use it.
83              
84             Please see at the document of L<Egg::Util> in detail.
85              
86             =head2 View
87              
88             L<Egg::View::Mason> is used for the view.
89              
90             Then, the configuration of the view is done.
91              
92             % vi /path/to/MyApp/lib/MyApp/config.pm
93            
94             VIEW => [
95             [ Mason => {
96             comp_root=> [
97             [ main => '<e.dir.template>' ],
98             [ private=> '<e.dir.comp>' ],
99             ],
100             data_dir=> '<e.dir.tmp>',
101             } ],
102             ],
103              
104             =head2 Controller
105              
106             The following plugins are used.
107              
108             Egg::Plugin::ConfigLoader
109             Egg::Plugin::Tools
110             Egg::Plugin::Filter
111             Egg::Plugin::FillInForm
112             Egg::Plugin::EasyDBI
113             Egg::Plugin::Mason
114              
115             Then, the controller is changed to the following feeling.
116              
117             % vi /path/to/MyApp/lib/MyApp.pm
118            
119             use Egg qw/ -Debug
120             ConfigLoader
121             Tools
122             Filter
123             FillInForm
124             EasyDBI
125             Mason
126             /;
127              
128             'Egg::Plugin' part of the module name is omitted and described like this.
129              
130             For instance, when an original plugin such as 'MyApp::Plugin::Hoge' is loaded,
131             the full name is specified putting '+' on the head.
132              
133             use Egg qw/ -Debug
134             .....
135             +MyApp::Plugin::Hoge
136             /;
137              
138             =head2 Dispatch
139              
140             As for dispatch, MyApp::Dispatch is usually used.
141             To change this, the module name is set to environment variable 'MYAPP_DISPATCH_CLASS'.
142              
143             Then, dispatch is changed to the following feeling.
144              
145             % vi /path/to/MyApp/lib/MyApp/Dispatch.pm
146            
147             MyApp->dispatch_map(
148            
149             _default => sub {},
150            
151             r => sub {
152             my($e)= @_;
153             my $id= $e->snip->[1] || return $e->finished('403 Forbidden');
154             my $url= $e->db->tiny_url->scalar('url', 'id = ?', $id)
155             || return $e->finished('404 Not Found');
156             $e->response->redirect($url);
157             },
158            
159             );
160              
161             '_default' specified '/index.tt' when writing so.
162              
163             In the code when you want to specify a suitable template
164              
165             _default => sub {
166             my($e)= @_;
167             $e->template('/top-page.tt');
168             },
169              
170             It specifies it by feeling.
171              
172             The registration of URL is accepted in this 'index.tt'.
173              
174             And, 'r' is a place accessed by registration ID.
175              
176             http://ho.com/r/abc12
177              
178             It is a setting that assumes URL.
179              
180             If it is usual dispatch.
181              
182             r=> {
183             abc12 => sub {},
184             },
185              
186             Then, because the part of abc12 cannot be specified in the specification of this
187             tutorial, the template cannot be prepared beforehand though r/abc12.tt is
188             recognized as a template.
189              
190             Therefore, 'r' makes for the code reference, and acquires registration ID in that.
191              
192             Besides, it is sure to go as follows well.
193              
194             r=> {
195             _default=> sub { $_[0]->finished('403 Forbidden') },
196             qr{^([a-f0-9]{5})$}=> sub {
197             my($e, $d, $s)= @_;
198             my $url= $e->db->tiny_url->scalar('url', 'id = ?', $s->[0])
199             || return $e->finished('404 Not Found');
200             $e->response->redirect($url);
201             },
202             },
203              
204             This is an example of acquiring the match character string by using the regular
205             expression for dispatch.
206             In this case, I think that the processing when the request is put right under 'r'
207             is also necessary.
208             When this is omitted, top '_default' obtains it.
209             It only has to use both favors.
210              
211             The following contexts are passed for the code reference of dispatch as an
212             argument.
213              
214             1. Object of project.
215             2. Object of dispatch handler.
216             3. When the regular expression is used, the matched character string is listed.
217              
218             There is data to divide request URI by '/' in $e->snip. The element of 0 of this
219             data is 'r', and the element of one is sure to have registration ID.
220             If ID cannot be acquired, all Forbidden is returned and processing is ended.
221              
222             my $url= $e->db->tiny_url->scalar('url', 'id = ?', $id)
223             || return $e->finished('404 Not Found');
224             $e->response->redirect($url);
225              
226             It looks for corresponding URL from the data base by this code, and it redirects
227             it to acquired URL.
228              
229             =head2 Template
230              
231             'index.tt' that exists in '/path/to/MyApp/root' is edited as follows.
232              
233             % vi /path/to/MyApp/root/index.tt
234            
235             <%init>
236             my $ms= $e->mason->prepare(
237             page_title=> 'TineURL',
238             );
239             my $req= $e->request;
240             $ms->code_action(sub {
241             $e->referer_check(1) || return 0;
242             my $mode= $req->param('mode') || return 0;
243             return 0 unless $mode eq 'regist';
244             $e->filter( url => [qw/ hold hold_html uri /] );
245             my $url= $req->param('url') || return $e->error('URL is enmpty.');
246             $url=~m{^https?\://.+} || return $e->error('Format error of URL.');
247             my $turl= $e->db->tiny_url;
248             $turl->scalar('id', 'url = ?', $url)
249             and return $e->error('It has registered.');
250             $turl->find_insert( id=> $e->create_id(5), url=> $url )
251             || return $ms->error_complete('SYSTEM-ERROR', 'Failure of registration.');
252             $ms->complete('Complete', <<END_INFO);
253             <a href="/">Please click.</a>
254             END_INFO
255             });
256             $ms->code_entry(sub {
257             $req->param( mode=> 'regist' );
258             $e->fillin_ok(1);
259             });
260             $ms->exec;
261             </%init>
262             %
263             <& /html-header.tt &>
264             <& /body-header.tt &>
265             <div id="content">
266             %
267             % if ($ms->is_complete) {
268             %
269             <h2><% $ms->complete_topic %></h2>
270             <p><% $ms->complete_info %></p>
271             %
272             % } else {
273             %
274             % if (my $error= $e->errstr) {
275             <div id="warning"><% $error %></div>
276             % } # $e->errstr end.
277             <form method="POST" action="<% $req->path %>">
278             <input type="hidden" name="mode" id="mode" />
279             URL : <input type="text" name="url" id="url" maxlength="300" size="50" />
280             <input type="submit" value="REGIST" />
281             </form>
282             %
283             % } # $s->{complete} end.
284             %
285             </div><!-- content end. -->
286             <& /body-side.tt &>
287             <& /body-footer.tt &>
288             <& /html-footer.tt &>
289              
290             Please look at http://www.masonhq.com/about the grammar of L<HTML::Mason>.
291              
292             $e-E<gt>mason is a method that L<Egg::Plugin::Mason> makes available.
293             This object is acquired from the prepare method of $e-E<gt>mason.
294              
295             # Bad code.
296             my $m= $e->mason->prepare(
297             .....
298              
299             I think that this moves actually well like this though it is time when it uses '$m'.
300             However, the object of L<HTML::Mason> is not set in '$m' as a global value and
301             do not use '$m' so as not to cause confusion, please.
302              
303             The code registers the following two kinds.
304              
305             1. code_action ..... Action when registration button is pushed.
306             2. code_entry ..... Code for access usually.
307              
308             'code_action' decides whether to check first of all and to process 'HTTP_REFERER'
309             and 'REQUEST_METHOD'. And, it registers in the data base through the input check etc.
310              
311             'code_entry' doesn't have the so much work. Processing is only added deflecting
312             because the value of mode is checked with 'code_action'. If mode is not checked,
313             'code_entry' becomes there is no necessity.
314              
315             And, a series of processing is done with $ms-E<gt>exec.
316              
317             The part of the HTML source especially omits explaining.
318              
319             =head2 Confirm
320              
321             It confirms the operation when the above-mentioned work is finished.
322              
323             First of all, 'bin/trigger.cgi' is stricken from the console.
324              
325             % cd /path/to/MyApp/bin
326             % perl trigger.cgi
327              
328             It deals at the right time if the error occurs by this.
329              
330             The work file of L<HTML::Mason> is temporarily deleted if normally displayed.
331              
332             % rm -rf /path/to/MyApp/tmp/*
333            
334             # It is also good to change the owner.
335             % chown -R webserver /path/to/MyApp/tmp
336              
337             Because this tutorial explains the method of constructing the application, the
338             method of setting these is omitted only though it is made to set 'mod_perl' and
339             'FastCGI' and to display by a browser now. Please see at the document of L<Egg>
340             in detail.
341              
342             Perhaps, if 'trigger.cgi' normally returns contents when the error is returned
343             by displaying a browser, the problem concerns the setting and the authority, etc.
344             Please adjust and try these.
345              
346             =head2 End
347              
348             If the application is added to the project further, it is a translation that
349             adds the plugin to the controller, registers the code in dispatch, and makes the
350             template.
351              
352             Egg - The project production that uses the MVC framework is advanced based on the
353             above-mentioned work.
354              
355             =head1 SEE ALSO
356              
357             L<Egg>,
358              
359             =head1 AUTHOR
360              
361             Masatoshi Mizuno, E<lt>lusheE<64>cpan.orgE<gt>
362              
363             =head1 COPYRIGHT AND LICENSE
364              
365             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
366              
367             This library is free software; you can redistribute it and/or modify
368             it under the same terms as Perl itself, either Perl version 5.8.6 or,
369             at your option, any later version of Perl 5 you may have available.
370              
371             =cut
372