DemoRedirect.pm

filter: Statementstmt 44.6% 21 / 47 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 33.3% 1 / 3 totaltotal 40.3% 27 / 67 CC 4 SCAR 16.1
CC
4
Cov
39%
main
12.0
main_dispatch
6.0
get_amendment_message
2.0
CRAP 5.0
« CGI/Portable/AppSplitScreen.pm ↑ Summary
1 =head1 NAME
2  
3 DemoRedirect - Demo of CGI::Portable sending a redirection header.
4  
5 =cut
6  
7 ######################################################################
8  
9 package DemoRedirect;
10 1 require 5.004;
11  
12 # Copyright (c) 1999-2004, Darren R. Duncan. All rights reserved. This module
13 # is free software; you can redistribute it and/or modify it under the same terms
14 # as Perl itself. However, I do request that this copyright information and
15 # credits remain attached to the file. If you modify this module and
16 # redistribute a changed version then please attach a note listing the
17 # modifications. This module is available "as-is" and the author can not be held
18 # accountable for any problems resulting from its use.
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 $VERSION = '0.50';
24  
25 ######################################################################
26  
27 =head1 DEPENDENCIES
28  
29 =head2 Perl Version
30  
31 5.004
32  
33 =head2 Standard Modules
34  
35 I<none>
36  
37 =head2 Nonstandard Modules
38  
39 CGI::Portable 0.50
40 CGI::Portable::AppStatic 0.50
41  
42 =cut
43  
44 ######################################################################
45  
46 1 ▶use CGI::Portable 0.50;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use CGI::Portable::AppStatic 0.50;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 @ISA = qw(CGI::Portable::AppStatic);
49  
50 ######################################################################
51  
52 =head1 SYNOPSIS
53  
54 =head2 Redirect To A Custom Url In User Query Parameter 'url'
55  
56 #!/usr/bin/perl
57 use strict;
58 use warnings;
59  
60 require CGI::Portable;
61 my $globals = CGI::Portable->new();
62  
63 require CGI::Portable::AdapterCGI;
64 my $io = CGI::Portable::AdapterCGI->new();
65 $io->fetch_user_input( $globals );
66  
67 my %CONFIG = ();
68  
69 $globals->set_prefs( \%CONFIG );
70 $globals->call_component( 'DemoRedirect' );
71  
72 $io->send_user_output( $globals );
73  
74 1;
75  
76 =head1 DESCRIPTION
77  
78 This Perl 5 object class is part of a demonstration of CGI::Portable in use.
79 It is one of a set of "application components" that takes its settings and user
80 input through CGI::Portable and uses that class to send its user output.
81 This demo module set can be used together to implement a web site complete with
82 static html pages, e-mail forms, guest books, segmented text document display,
83 usage tracking, and url-forwarding. Of course, true to the intent of
84 CGI::Portable, each of the modules in this demo set can be used independantly
85 of the others.
86  
87 =head1 SYNTAX
88  
89 This class does not export any functions or methods, so you need to call them
90 using object notation. This means using B<Class-E<gt>function()> for functions
91 and B<$object-E<gt>method()> for methods. If you are inheriting this class for
92 your own modules, then that often means something like B<$self-E<gt>method()>.
93  
94 =head1 PUBLIC FUNCTIONS AND METHODS
95  
96 =head2 main( GLOBALS )
97  
98 You invoke this method to run the application component that is encapsulated by
99 this class. The required argument GLOBALS is an CGI::Portable object that
100 you have previously configured to hold the instance settings and user input for
101 this class. When this method returns then the encapsulated application will
102 have finished and you can get its user output from the CGI::Portable object.
103  
104 =head1 PREFERENCES HANDLED BY THIS MODULE
105  
106 I<There are no preferences. Just set the query parameter named "url" to the
107 destination that you want the script to forward you to. However, this module
108 does subclass CGI::Portable::AppStatic, so you can optionally set the
109 high_http_status_code and high_http_window_target preferences that it handles.>
110  
111 =cut
112  
113 ######################################################################
114  
115 # Names of properties for objects of parent class are declared here:
116 1 my $KEY_SITE_GLOBALS = 'site_globals'; # hold global site values
117  
118 # Constant values used by this class:
119 1 my $UIPN_DEST_URL = 'url'; # look in the user query for destination
120  
121 ######################################################################
122  
123 0 ▶sub main {
Subroutine main: not called CC=3 SCAR=24.8
Pod documented
124 0 my ($class, $globals) = @_;
125 0 ▶ my $self = bless( {}, ref($class) || $class );
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
126  
127 0 ▶ UNIVERSAL::isa( $globals, 'CGI::Portable' ) or
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($globals, "CGI::Portable") or die "initializer is not a valid CGI::Portable object" 0 0 0
128 die "initializer is not a valid CGI::Portable object";
129  
130 0 $self->set_static_low_replace( $globals );
131  
132 0 $self->{$KEY_SITE_GLOBALS} = $globals;
133 0 $self->main_dispatch();
134  
135 0 $self->set_static_high_replace( $globals );
136 0 $self->set_static_attach_unordered( $globals );
137 0 $self->set_static_attach_ordered( $globals );
138 0 $self->set_static_search_and_replace( $globals );
139 }
140  
141 ######################################################################
142  
143 0 ▶sub main_dispatch {
Subroutine main_dispatch: not called CC=2 SCAR=17.9
Pod undocumented
144 0 my $self = shift( @_ );
145 0 my $globals = $self->{$KEY_SITE_GLOBALS};
146 0 my $dest_url = $globals->user_query_param( $UIPN_DEST_URL );
147
148 0 ▶ unless( $dest_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dest_url) 0 0 0
149 0 $globals->page_title( 'No Url Provided' );
150  
151 0 $globals->set_page_body( <<__endquote );
152 0 <h1>@{[$globals->page_title()]}</h1>
153  
154 <p>I'm sorry, but this redirection page requires a query parameter named
155 "$UIPN_DEST_URL", whose value is an url. No url was provided, so I
156 can't redirect you to it. If you got this error while clicking
157 on one of the links on this website, then the problem is likely
158 on this end. In the latter case...</p>
159  
160 0 @{[$self->get_amendment_message()]}
161 __endquote
162  
163 0 return( 1 );
164 }
165  
166 0 $globals->http_status_code( '301 Moved' );
167 0 $globals->http_redirect_url( $dest_url );
168 }
169  
170 ######################################################################
171  
172 0 ▶sub get_amendment_message {
Subroutine get_amendment_message: not called CC=1 SCAR=6.9
Pod undocumented
173 0 my ($self) = shift( @_ );
174 0 my $globals = $self->{$KEY_SITE_GLOBALS};
175 0 return( <<__endquote );
176 <p>This should be temporary, the result of a transient server problem or an
177 0 update being performed at the moment. Click @{[$globals->recall_html('here')]}
178 to automatically try again. If the problem persists, please try again later,
179 0 or send an @{[$globals->maintainer_email_html('e-mail')]} message about the
180 problem, so it can be fixed.</p>
181 __endquote
182 }
183  
184 ######################################################################
185  
186 1 1;
187 __END__
« CGI/Portable/AppSplitScreen.pm ↑ Summary