File Coverage

blib/lib/CGI/Builder/GetPageName.pm
Criterion Covered Total %
statement 6 9 66.6
branch 0 2 0.0
condition 0 6 0.0
subroutine 2 3 66.6
pod 1 1 100.0
total 9 21 42.8


line stmt bran cond sub pod time code
1             package CGI::Builder::GetPageName;
2              
3 1     1   30949 use strict;
  1         3  
  1         42  
4 1     1   5 use vars qw/$VERSION/;
  1         3  
  1         247  
5              
6             $VERSION = '0.03';
7              
8             $Carp::Internal{+__PACKAGE__}++;
9             $Carp::Internal{__PACKAGE__.'::_'}++;
10              
11             # Override
12             sub get_page_name {
13 0     0 1   my $s = shift;
14             my $p
15             = $s->cgi->param($s->cgi_page_param)
16 0   0       || do {
17             my $path = $ENV{PATH_INFO} || '/';
18             my @path_entries = split( '/' , $path );
19             join( '_' , @path_entries[1..$#path_entries] );
20             }
21             ;
22              
23 0 0 0       $s->page_name( $p ) if defined( $p ) && length( $p );
24              
25             }
26              
27              
28             1;
29              
30             =head1 NAME
31              
32             CGI::Builder::GetPageName - GetPageName from path info.
33              
34             =head1 DESCRIPTION
35              
36             This extention allow you to set page name from $ENV{PATH_INFO} instead of
37             p(Qerystring). You can check SYNOPSYS out and you will know what this mean. :-)
38              
39             This class is extention of CGI::Builder, I love CGI::Builder.
40              
41             =head1 SYNOPSYS
42              
43             start.cgi
44              
45             #!/usr/bin/perl -w
46              
47             use strict;
48             use Your::CGI::Builder;
49            
50             my $app = Your::CGI::Builder->new();
51             $app->process();
52            
53             # you can set page name this way if you want but in this way
54             # you do not need to use this extention :-p
55             #$app->process( 'page_name' );
56            
57             __END__
58              
59             Your CGI::Builder Package.
60              
61             package Your::CGI::Builder;
62            
63             use CGI::Builder qw/
64             CGI::Builder::GetPageName
65             /;
66            
67             sub PH_foo_bar {
68             my $s = shift;
69             $s->page_content( 'my URL is http://localhost/script.cgi/foo/bar/?foo=whatever !!!!' );
70             }
71            
72             sub PH_hoge {
73             my $s = shift;
74             $s->page_content = 'my URL is http://localhost/script.cgi/hoge/ !!!' ;
75             }
76              
77             =head1 MORE FUN?
78              
79             Use ScriptAlias !!! This allow you to hide .cgi extension. Very fun.
80              
81              
82             ScriptAlias /secure /var/www/httpdoc/secure.cgi
83              
84             # You have this start script.
85             http://localhost/secure.cgi
86              
87             # You set script alias so , you can also access with this URL.
88             http://localhost/secure
89            
90             # Then now...
91             sub PH_foo_bar {
92             my $s = shift;
93             $s->page_content = 'my URL is http://localhost/secure/foo/bar/?foo=whatever !!!' ;
94             }
95              
96             =head1 OVERRIDE MODULES
97              
98             =head2 get_page_name
99              
100             I override this method but I guess you do not need to care.
101              
102             =head1 SEE ALSO
103              
104             CGI::Builder
105              
106             =head1 CREDITS
107              
108             Thanks to Domizio Demichelis for everything!
109              
110             =head1 AUTHOR
111              
112             Tomohiro Teranishi
113              
114             =head1 COPYRIGHT
115              
116             This program is distributed under the Artistic License
117              
118             =cut