File Coverage

lib/Egg/Helper/Util/Tester.pm
Criterion Covered Total %
statement 6 43 13.9
branch 0 22 0.0
condition 0 11 0.0
subroutine 2 6 33.3
pod n/a
total 8 82 9.7


line stmt bran cond sub pod time code
1             package Egg::Helper::Util::Tester;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: Tester.pm 337 2008-05-14 12:30:09Z lushe $
6             #
7 1     1   533 use strict;
  1         3  
  1         41  
8 1     1   6 use warnings;
  1         3  
  1         750  
9              
10             our $VERSION= '3.00';
11              
12             sub _start_helper {
13 0     0     my($self)= @_;
14 0   0       my $uri= shift(@ARGV)
15             || return $self->_helper_help('I want request URI.');
16 0           my $o= $self->_helper_get_options;
17 0 0         $o->{help} and return $self->_helper_help;
18 0           my($server, $path);
19 0 0         if ($uri=~m{^https?\://(.+)}) {
20 0           ($server, $path)= $1=~m{^([^/]+)(.+)};
21 0 0         $path || return $self->_helper_help('Bad format of URI.');
22             }
23 0   0       $path ||= $uri;
24 0 0         $path=~m{^/.*} || return $self->_helper_help('Input error of URI.');
25 0           $path=~s{\#.+?$} [];
26 0           $ENV{REQUEST_URI}= $path;
27 0           $ENV{REQUEST_METHOD}= 'GET';
28 0 0         if ($path=~m{(.+?)\?(.+)$}) {
29 0           ($path, $ENV{QUERY_STRING})= ($1, $2);
30             }
31 0           $ENV{PATH_INFO}= $path;
32 0           $ENV{REMOTE_ADDR}= '127.0.0.1';
33 0   0       $server ||= 'localhost';
34 0 0         if ($server=~m{(.+)\:(\d+)$}) {
35 0           $server= $1;
36 0           $ENV{SERVER_PORT}= $2;
37             } else {
38 0           $ENV{SERVER_PORT}= 80;
39             }
40 0   0       $ENV{SERVER_NAME}= $ENV{HTTP_HOST}= $server || 'localhost';
41 0 0         $ENV{HTTPS}= 'on' if $uri=~m{^https\://};
42             my $res= $self->helper_stdout(sub {
43 0     0     my $p= $self->project_name;
44 0 0         $p->require or die $@;
45 0           $p->handler;
46 0           });
47 0 0         if ($res->error) {
    0          
48 0           print STDERR $res->error;
49             } elsif ($o->{all}) {
50 0           print STDERR $res->result;
51             } else {
52 0           print STDERR "\n\nDone...\n";
53             }
54             }
55             sub _helper_get_options {
56 0     0     shift->next::method(' a-all r-response_header ');
57             }
58             sub _helper_help {
59 0     0     my $self= shift;
60 0   0       my $msg = shift || "";
61 0 0         $msg= "ERROR: ${msg}\n\n" if $msg;
62 0           print <<END_HELP;
63             ${msg}% perl myapp_tester.pl [URI] [OPTION]
64              
65             Usage: ./myapp_tester.pl http://mydomain/hoge/boo -ar
66              
67             END_HELP
68             }
69              
70             1;
71              
72             __END__
73              
74             =head1 NAME
75              
76             Egg::Helper::Util::Tester - Operation test of project.
77              
78             =head1 SYNOPSIS
79              
80             % cd /path/to/MyApp
81             % bin/myapp_tester.pl http://domainname/
82             DEBUG:
83             # ----------------------------------------------------------
84             # >> Egg - MyApp: startup !! - load plugins.
85             # = Egg::Plugin::ConfigLoader v3.00
86             # + Request Class: Egg::Request::CGI v3.00
87             # + Load Model: dbic-3.00
88             # + Load View : mason-3.00
89             # + Load Dispatch: MyApp::Dispatch v0.01
90             DEBUG: # >>>>> MyApp v0.01
91             # + Request Path : /
92             # + template file : index.tt
93             # >> simple bench = -------------------
94             * prepare : 0.004711 sec.
95             * dispatch : 0.000978 sec.
96             * action_start : 0.084614 sec.
97             * action_end : 0.000111 sec.
98             * finalize : 0.005493 sec.
99             * output : 0.000904 sec.
100             * finish : 0.003839 sec.
101             * ======= Total >> : 0.100650 sec.
102             # -------------------------------------
103              
104             =head1 DESCRIPTION
105              
106             It is a module to do the operation test of the project.
107              
108             It uses it from [PROJECT_LC]_tester.pl generated to 'bin' directory of the project.
109              
110             % cd /path/to/MyApp
111             % bin/myapp_tester.pl http://domainname/
112              
113             Please pass URI that wants to test to [PROJECT_LC]_tester.pl and start.
114              
115             * It doesn't correspond to the test of place POST current request.
116              
117             When '-a' option is put, the content of STDOUT comes to be output though the
118             content output to STDOUT is not displayed usually.
119              
120             =head1 SEE ALSO
121              
122             L<Egg::Release>,
123             L<Egg::Helper>,
124              
125             =head1 AUTHOR
126              
127             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
128              
129             =head1 COPYRIGHT AND LICENSE
130              
131             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
132              
133             This library is free software; you can redistribute it and/or modify
134             it under the same terms as Perl itself, either Perl version 5.8.6 or,
135             at your option, any later version of Perl 5 you may have available.
136              
137             =cut
138