| 1 | =head1 NAME | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | DemoMailForm - Demo of CGI::Portable that implements an e-mail | ||||||||||||||||||||
| 4 | submission form with unlimited questions. | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =cut | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | ###################################################################### | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | package DemoMailForm; | ||||||||||||||||||||
| 11 | 1 | require 5.004; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # Copyright (c) 1999-2004, Darren R. Duncan. All rights reserved. This module | ||||||||||||||||||||
| 14 | # is free software; you can redistribute it and/or modify it under the same terms | ||||||||||||||||||||
| 15 | # as Perl itself. However, I do request that this copyright information and | ||||||||||||||||||||
| 16 | # credits remain attached to the file. If you modify this module and | ||||||||||||||||||||
| 17 | # redistribute a changed version then please attach a note listing the | ||||||||||||||||||||
| 18 | # modifications. This module is available "as-is" and the author can not be held | ||||||||||||||||||||
| 19 | # accountable for any problems resulting from its use. | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 1 | ▶ | use vars qw($VERSION @ISA); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 1 | $VERSION = '0.50'; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | ###################################################################### | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 DEPENDENCIES | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head2 Perl Version | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 5.004 | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head2 Standard Modules | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | Fcntl | ||||||||||||||||||||
| 37 | Symbol | ||||||||||||||||||||
| 38 | Net::SMTP 2.15 (earlier versions may work) | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head2 Nonstandard Modules | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | CGI::Portable 0.50 | ||||||||||||||||||||
| 43 | CGI::Portable::AppStatic 0.50 | ||||||||||||||||||||
| 44 | CGI::MultiValuedHash 1.09 | ||||||||||||||||||||
| 45 | HTML::FormTemplate 2.021 | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | ###################################################################### | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | ▶ | use Fcntl qw(:DEFAULT :flock); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | 1 | ▶ | use Symbol; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | ▶ | use CGI::Portable 0.50; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | 1 | ▶ | use CGI::Portable::AppStatic 0.50; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 1 | @ISA = qw(CGI::Portable::AppStatic); | |||||||||||||||||||
| 56 | 1 | ▶ | use CGI::MultiValuedHash 1.09; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 1 | ▶ | use HTML::FormTemplate 2.021; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | ###################################################################### | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head1 SYNOPSIS | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =head2 Use Default Question | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | #!/usr/bin/perl | ||||||||||||||||||||
| 66 | use strict; | ||||||||||||||||||||
| 67 | use warnings; | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | require CGI::Portable; | ||||||||||||||||||||
| 70 | my $globals = CGI::Portable->new(); | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | require CGI::Portable::AdapterCGI; | ||||||||||||||||||||
| 73 | my $io = CGI::Portable::AdapterCGI->new(); | ||||||||||||||||||||
| 74 | $io->fetch_user_input( $globals ); | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | $globals->default_application_title( 'Demo Email Form' ); | ||||||||||||||||||||
| 77 | $globals->default_maintainer_name( 'Tony Simons' ); | ||||||||||||||||||||
| 78 | $globals->default_maintainer_email_address( 'tony@aardvark.net' ); | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | my %CONFIG = (); | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | $globals->set_prefs( \%CONFIG ); | ||||||||||||||||||||
| 83 | $globals->call_component( 'DemoMailForm' ); | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | $io->send_user_output( $globals ); | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1; | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =head2 Use Custom Questions Defined Here | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | my %CONFIG = ( | ||||||||||||||||||||
| 92 | custom_fd => 1, | ||||||||||||||||||||
| 93 | field_defn => [ | ||||||||||||||||||||
| 94 | { | ||||||||||||||||||||
| 95 | visible_title => "What's your age?", | ||||||||||||||||||||
| 96 | type => 'textfield', | ||||||||||||||||||||
| 97 | name => 'age', | ||||||||||||||||||||
| 98 | is_required => 1, | ||||||||||||||||||||
| 99 | validation_rule => '\d', | ||||||||||||||||||||
| 100 | error_message => 'You must enter a number.', | ||||||||||||||||||||
| 101 | }, { | ||||||||||||||||||||
| 102 | visible_title => "What's the combination?", | ||||||||||||||||||||
| 103 | type => 'checkbox_group', | ||||||||||||||||||||
| 104 | name => 'words', | ||||||||||||||||||||
| 105 | 'values' => ['eenie', 'meenie', 'minie', 'moe'], | ||||||||||||||||||||
| 106 | default => ['eenie', 'minie'], | ||||||||||||||||||||
| 107 | labels => [qw( This That And Another )], | ||||||||||||||||||||
| 108 | }, { | ||||||||||||||||||||
| 109 | visible_title => "Who do you love?", | ||||||||||||||||||||
| 110 | type => 'textfield', | ||||||||||||||||||||
| 111 | name => 'name', | ||||||||||||||||||||
| 112 | }, { | ||||||||||||||||||||
| 113 | visible_title => "What's your favorite colour?", | ||||||||||||||||||||
| 114 | type => 'popup_menu', | ||||||||||||||||||||
| 115 | name => 'color', | ||||||||||||||||||||
| 116 | 'values' => ['red', 'green', 'blue', 'chartreuse'], | ||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||
| 118 | ], | ||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head2 Use Custom Questions Defined In Perl File | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | use Cwd; | ||||||||||||||||||||
| 124 | $globals->file_path_root( cwd() ); # let us default to current working dir | ||||||||||||||||||||
| 125 | $globals->file_path_delimiter( $^O=~/Mac/i ? ":" : $^O=~/Win/i ? "\\" : "/" ); | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | my %CONFIG = ( | ||||||||||||||||||||
| 128 | custom_fd => 1, | ||||||||||||||||||||
| 129 | field_defn => 'survey_questions.txt', # do Perl code to make array ref | ||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =head2 Use Custom Questions Defined In simple Boulder File | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | use Cwd; | ||||||||||||||||||||
| 135 | $globals->file_path_root( cwd() ); # let us default to current working dir | ||||||||||||||||||||
| 136 | $globals->file_path_delimiter( $^O=~/Mac/i ? ":" : $^O=~/Win/i ? "\\" : "/" ); | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | my %CONFIG = ( | ||||||||||||||||||||
| 139 | custom_fd => 1, | ||||||||||||||||||||
| 140 | field_defn => 'survey_questions.txt', # file in simple Boulder format | ||||||||||||||||||||
| 141 | fd_in_seqf => 1, | ||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head2 Customize Subject Of Your Emails | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | my %CONFIG = ( | ||||||||||||||||||||
| 147 | email_subj => 'Another Survey Response', | ||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head2 Customize Webpage Intro Text | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | my %CONFIG = ( | ||||||||||||||||||||
| 153 | msg_new_title => 'Leave A Message', # custom title for new messages | ||||||||||||||||||||
| 154 | msg_new_head => <<__endquote, # custom heading for new messages | ||||||||||||||||||||
| 155 | <h1>Leave A Message</h1> | ||||||||||||||||||||
| 156 | <p>Please leave a message after the beep. Answer the questions as faithfully | ||||||||||||||||||||
| 157 | and truthfully as you can, as we have a lie detector set up and any false | ||||||||||||||||||||
| 158 | answers will be met with spam.</p> | ||||||||||||||||||||
| 159 | __endquote | ||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | =head1 DESCRIPTION | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | This Perl 5 object class is part of a demonstration of CGI::Portable in use. | ||||||||||||||||||||
| 165 | It is one of a set of "application components" that takes its settings and user | ||||||||||||||||||||
| 166 | input through CGI::Portable and uses that class to send its user output. | ||||||||||||||||||||
| 167 | This demo module set can be used together to implement a web site complete with | ||||||||||||||||||||
| 168 | static html pages, e-mail forms, guest books, segmented text document display, | ||||||||||||||||||||
| 169 | usage tracking, and url-forwarding. Of course, true to the intent of | ||||||||||||||||||||
| 170 | CGI::Portable, each of the modules in this demo set can be used independantly | ||||||||||||||||||||
| 171 | of the others. | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =head1 SYNTAX | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | This class does not export any functions or methods, so you need to call them | ||||||||||||||||||||
| 176 | using object notation. This means using B<Class-E<gt>function()> for functions | ||||||||||||||||||||
| 177 | and B<$object-E<gt>method()> for methods. If you are inheriting this class for | ||||||||||||||||||||
| 178 | your own modules, then that often means something like B<$self-E<gt>method()>. | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | =head1 PUBLIC FUNCTIONS AND METHODS | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =head2 main( GLOBALS ) | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | You invoke this method to run the application component that is encapsulated by | ||||||||||||||||||||
| 185 | this class. The required argument GLOBALS is an CGI::Portable object that | ||||||||||||||||||||
| 186 | you have previously configured to hold the instance settings and user input for | ||||||||||||||||||||
| 187 | this class. When this method returns then the encapsulated application will | ||||||||||||||||||||
| 188 | have finished and you can get its user output from the CGI::Portable object. | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =head1 PREFERENCES HANDLED BY THIS MODULE | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | I<This POD is coming when I get the time to write it.> | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | custom_fd # if true, we use a custom list of | ||||||||||||||||||||
| 195 | # questions in the form; otherwise, we simply have a "message" field. | ||||||||||||||||||||
| 196 | field_defn # instruc for how to make form fields | ||||||||||||||||||||
| 197 | # If array ref, this is taken literally as list of definitions. | ||||||||||||||||||||
| 198 | # Otherwise, this is name of a file containing the definitions. | ||||||||||||||||||||
| 199 | # Field definitions are processed by HTML::FormTemplate, so please see | ||||||||||||||||||||
| 200 | # its POD to know what options you have in your forms. | ||||||||||||||||||||
| 201 | fd_in_seqf # if true, above file is of the | ||||||||||||||||||||
| 202 | # format that is a simplified form of Boulder; else it is Perl code | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | email_subj # if set, use when sending e-mails | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | msg_new_title # custom title for new messages | ||||||||||||||||||||
| 207 | msg_new_head # custom heading for new messages | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | =cut | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | ###################################################################### | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | # Names of properties for objects of this class are declared here: | ||||||||||||||||||||
| 214 | 1 | my $KEY_SITE_GLOBALS = 'site_globals'; # hold global site values | |||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | # Keys for items in site page preferences: | ||||||||||||||||||||
| 217 | 1 | my $PKEY_CUSTOM_FD = 'custom_fd'; # if true, we use a custom list of | |||||||||||||||||||
| 218 | # questions in the form; otherwise, we simply have a "message" field. | ||||||||||||||||||||
| 219 | 1 | my $PKEY_FIELD_DEFN = 'field_defn'; # instruc for how to make form fields | |||||||||||||||||||
| 220 | # If array ref, this is taken literally as list of definitions. | ||||||||||||||||||||
| 221 | # Otherwise, this is name of a file containing the definitions. | ||||||||||||||||||||
| 222 | # Field definitions are processed by HTML::FormTemplate, so please see | ||||||||||||||||||||
| 223 | # its POD to know what options you have in your forms. | ||||||||||||||||||||
| 224 | 1 | my $PKEY_FD_IN_SEQF = 'fd_in_seqf'; # if true, above file is of the | |||||||||||||||||||
| 225 | # format that is a simplified form of Boulder; else it is Perl code | ||||||||||||||||||||
| 226 | 1 | my $PKEY_EMAIL_SUBJ = 'email_subj'; # if set, use when sending e-mails | |||||||||||||||||||
| 227 | 1 | my $PKEY_MSG_NEW_TITLE = 'msg_new_title'; # custom title for new messages | |||||||||||||||||||
| 228 | 1 | my $PKEY_MSG_NEW_HEAD = 'msg_new_head'; # custom heading for new messages | |||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | # Names of the fields in our html form: | ||||||||||||||||||||
| 231 | 1 | my $FFN_NAMEREAL = 'namereal'; # user's real name | |||||||||||||||||||
| 232 | 1 | my $FFN_EMAIL = 'email'; # user's e-mail address | |||||||||||||||||||
| 233 | 1 | my $FFN_WANTCOPY = 'wantcopy'; # true if sender wants a copy | |||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | # This is where the user's message goes, by default. | ||||||||||||||||||||
| 236 | 1 | my @DEF_FORM_QUESTIONS = ( { | |||||||||||||||||||
| 237 | visible_title => "Your Message", | ||||||||||||||||||||
| 238 | type => 'textarea', | ||||||||||||||||||||
| 239 | name => 'message', | ||||||||||||||||||||
| 240 | rows => 5, | ||||||||||||||||||||
| 241 | columns => 50, | ||||||||||||||||||||
| 242 | is_required => 1, | ||||||||||||||||||||
| 243 | error_message => 'You must enter a message.', | ||||||||||||||||||||
| 244 | } ); | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | # Constant values used in this class go here: | ||||||||||||||||||||
| 247 | 1 | my $EMPTY_FIELD_ECHO_STRING = '(no answer)'; | |||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | ###################################################################### | ||||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | 0 | ▶ | sub main { | ||||||||||||||||||
|
Subroutine
main: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 252 | 0 | my ($class, $globals) = @_; | |||||||||||||||||||
| 253 | 0 | ▶ | my $self = bless( {}, ref($class) || $class ); | ||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 254 | |||||||||||||||||||||
| 255 | 0 | ▶ | UNIVERSAL::isa( $globals, 'CGI::Portable' ) or | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 256 | die "initializer is not a valid CGI::Portable object"; | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | 0 | $self->set_static_low_replace( $globals ); | |||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | 0 | $self->{$KEY_SITE_GLOBALS} = $globals; | |||||||||||||||||||
| 261 | 0 | $self->main_dispatch(); | |||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | 0 | $self->set_static_high_replace( $globals ); | |||||||||||||||||||
| 264 | 0 | $self->set_static_attach_unordered( $globals ); | |||||||||||||||||||
| 265 | 0 | $self->set_static_attach_ordered( $globals ); | |||||||||||||||||||
| 266 | 0 | $self->set_static_search_and_replace( $globals ); | |||||||||||||||||||
| 267 | } | ||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | ###################################################################### | ||||||||||||||||||||
| 270 | |||||||||||||||||||||
| 271 | 0 | ▶ | sub main_dispatch { | ||||||||||||||||||
|
Subroutine
main_dispatch: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 272 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 273 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 274 | |||||||||||||||||||||
| 275 | SWITCH: { | ||||||||||||||||||||
| 276 | 0 | my $ra_field_defs = $self->get_field_definitions(); # sets err on probl | |||||||||||||||||||
| 277 | 0 | ▶ | if( $globals->get_error() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 278 | 0 | $self->no_questions_error(); | |||||||||||||||||||
| 279 | 0 | $globals->add_no_error(); # clears it now dealt with | |||||||||||||||||||
| 280 | 0 | last SWITCH; | |||||||||||||||||||
| 281 | } | ||||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | 0 | my $form = HTML::FormTemplate->new(); | |||||||||||||||||||
| 284 | 0 | $form->form_submit_url( $globals->recall_url() ); | |||||||||||||||||||
| 285 | 0 | $form->field_definitions( $ra_field_defs ); | |||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | 0 | $form->user_input( $globals->user_post() )->trim_bounding_whitespace(); | |||||||||||||||||||
| 288 | |||||||||||||||||||||
| 289 | 0 | ▶ | if( $form->new_form() ) { # if we're called first time | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 290 | 0 | $self->new_message( $form ); | |||||||||||||||||||
| 291 | 0 | last SWITCH; | |||||||||||||||||||
| 292 | } | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | 0 | ▶ | if( $form->validate_form_input() ) { # if there were errors | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 295 | 0 | $self->invalid_input( $form ); | |||||||||||||||||||
| 296 | 0 | last SWITCH; | |||||||||||||||||||
| 297 | } | ||||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | 0 | ▶ | $self->send_mail_to_me( $form ) or last SWITCH; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 300 | |||||||||||||||||||||
| 301 | 0 | $self->mail_me_ok( $form ); | |||||||||||||||||||
| 302 | |||||||||||||||||||||
| 303 | 0 | ▶ | if( $globals->user_post_param( $FFN_WANTCOPY ) eq 'on' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 304 | 0 | $self->send_mail_to_writer( $form ); | |||||||||||||||||||
| 305 | } | ||||||||||||||||||||
| 306 | } | ||||||||||||||||||||
| 307 | } | ||||||||||||||||||||
| 308 | |||||||||||||||||||||
| 309 | ###################################################################### | ||||||||||||||||||||
| 310 | |||||||||||||||||||||
| 311 | 0 | ▶ | sub get_field_definitions { | ||||||||||||||||||
|
Subroutine
get_field_definitions: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 312 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 313 | 0 | my @field_definitions = (); | |||||||||||||||||||
| 314 | |||||||||||||||||||||
| 315 | 0 | push( @field_definitions, | |||||||||||||||||||
| 316 | { | ||||||||||||||||||||
| 317 | visible_title => "Your Name", | ||||||||||||||||||||
| 318 | type => 'textfield', | ||||||||||||||||||||
| 319 | name => $FFN_NAMEREAL, | ||||||||||||||||||||
| 320 | size => 30, | ||||||||||||||||||||
| 321 | is_required => 1, | ||||||||||||||||||||
| 322 | error_message => 'You must enter your name.', | ||||||||||||||||||||
| 323 | exclude_in_echo => 1, | ||||||||||||||||||||
| 324 | }, { | ||||||||||||||||||||
| 325 | visible_title => "Your E-mail", | ||||||||||||||||||||
| 326 | type => 'textfield', | ||||||||||||||||||||
| 327 | name => $FFN_EMAIL, | ||||||||||||||||||||
| 328 | size => 30, | ||||||||||||||||||||
| 329 | is_required => 1, | ||||||||||||||||||||
| 330 | validation_rule => '\S\@\S', | ||||||||||||||||||||
| 331 | help_message => 'E-mails are in the form "user@domain".', | ||||||||||||||||||||
| 332 | error_message => 'You must enter your e-mail.', | ||||||||||||||||||||
| 333 | exclude_in_echo => 1, | ||||||||||||||||||||
| 334 | }, { | ||||||||||||||||||||
| 335 | visible_title => "Keep A Copy", | ||||||||||||||||||||
| 336 | type => 'checkbox', | ||||||||||||||||||||
| 337 | name => $FFN_WANTCOPY, | ||||||||||||||||||||
| 338 | nolabel => 1, | ||||||||||||||||||||
| 339 | help_message => "If checked, a copy of this message is e-mailed to you.", | ||||||||||||||||||||
| 340 | exclude_in_echo => 1, | ||||||||||||||||||||
| 341 | }, | ||||||||||||||||||||
| 342 | ); | ||||||||||||||||||||
| 343 | |||||||||||||||||||||
| 344 | 0 | push( @field_definitions, @{$self->get_question_field_defs()} ); | |||||||||||||||||||
| 345 | |||||||||||||||||||||
| 346 | 0 | push( @field_definitions, | |||||||||||||||||||
| 347 | { | ||||||||||||||||||||
| 348 | type => 'submit', | ||||||||||||||||||||
| 349 | label => 'Send', | ||||||||||||||||||||
| 350 | }, { | ||||||||||||||||||||
| 351 | type => 'reset', | ||||||||||||||||||||
| 352 | label => 'Clear', | ||||||||||||||||||||
| 353 | }, | ||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||
| 355 | |||||||||||||||||||||
| 356 | 0 | return( \@field_definitions ); | |||||||||||||||||||
| 357 | } | ||||||||||||||||||||
| 358 | |||||||||||||||||||||
| 359 | ###################################################################### | ||||||||||||||||||||
| 360 | |||||||||||||||||||||
| 361 | 0 | ▶ | sub get_question_field_defs { | ||||||||||||||||||
|
Subroutine
get_question_field_defs: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 362 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 363 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 364 | 0 | my $rh_prefs = $globals->get_prefs_ref(); | |||||||||||||||||||
| 365 | |||||||||||||||||||||
| 366 | # check if we are using default or custom questions | ||||||||||||||||||||
| 367 | 0 | ▶ | unless( $rh_prefs->{$PKEY_CUSTOM_FD} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 368 | 0 | return( \@DEF_FORM_QUESTIONS ); # using default | |||||||||||||||||||
| 369 | } | ||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | 0 | my $field_defn = $rh_prefs->{$PKEY_FIELD_DEFN}; | |||||||||||||||||||
| 372 | |||||||||||||||||||||
| 373 | # check if we have actual custom questions or filename to them | ||||||||||||||||||||
| 374 | # check if question file is executable Perl or not | ||||||||||||||||||||
| 375 | 0 | ▶ | unless( $rh_prefs->{$PKEY_FD_IN_SEQF} ) { # it is Perl file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 376 | 0 | return( $globals->resolve_prefs_node_to_array( $field_defn ) ); | |||||||||||||||||||
| 377 | } | ||||||||||||||||||||
| 378 | |||||||||||||||||||||
| 379 | # we will now get questions from a simple Boulder formatted file | ||||||||||||||||||||
| 380 | 0 | ▶ | return( $self->fetch_all_records( $field_defn ) || [] ); | ||||||||||||||||||
|
Condition0%0/2
$self->fetch_all_records($field_defn) || []
MC/DC0%0/1
$self->fetch_all_records($field_defn) || []
$self->fetch_all_records($field_defn)
Truth table0%0/2
A
A= $self->fetch_all_records($field_defn)
| |||||||||||||||||||||
| 381 | } | ||||||||||||||||||||
| 382 | |||||||||||||||||||||
| 383 | ###################################################################### | ||||||||||||||||||||
| 384 | |||||||||||||||||||||
| 385 | 0 | ▶ | sub no_questions_error { | ||||||||||||||||||
|
Subroutine
no_questions_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 386 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 387 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 388 | |||||||||||||||||||||
| 389 | 0 | $globals->page_title( "Error Starting MailForm" ); | |||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | 0 | $globals->set_page_body( <<__endquote ); | |||||||||||||||||||
| 392 | 0 | <h1>@{[$globals->page_title()]}</h1> | |||||||||||||||||||
| 393 | |||||||||||||||||||||
| 394 | <p>I'm sorry, but an error has occurred while trying to start | ||||||||||||||||||||
| 395 | the Mail Form. We are missing critical settings information | ||||||||||||||||||||
| 396 | that is required to operate. Specifically, we don't know what | ||||||||||||||||||||
| 397 | questions we are supposed to ask you. Here are some details about | ||||||||||||||||||||
| 398 | what caused this problem:</p> | ||||||||||||||||||||
| 399 | |||||||||||||||||||||
| 400 | 0 | <p>@{[$globals->get_error()]}</p> | |||||||||||||||||||
| 401 | |||||||||||||||||||||
| 402 | 0 | @{[$self->get_amendment_message()]} | |||||||||||||||||||
| 403 | __endquote | ||||||||||||||||||||
| 404 | } | ||||||||||||||||||||
| 405 | |||||||||||||||||||||
| 406 | ###################################################################### | ||||||||||||||||||||
| 407 | |||||||||||||||||||||
| 408 | 0 | ▶ | sub new_message { | ||||||||||||||||||
|
Subroutine
new_message: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 409 | 0 | my ($self, $form) = @_; | |||||||||||||||||||
| 410 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 411 | |||||||||||||||||||||
| 412 | 0 | ▶ | $globals->page_title( $globals->pref( $PKEY_MSG_NEW_TITLE ) || | ||||||||||||||||||
|
Condition0%0/2
$globals->pref($PKEY_MSG_NEW_TITLE) || 'Send Me An E-mail'
MC/DC0%0/1
$globals->pref($PKEY_MSG_NEW_TITLE) || 'Send Me An E-mail'
$globals->pref($PKEY_MSG_NEW_TITLE)
Truth table0%0/2
A
A= $globals->pref($PKEY_MSG_NEW_TITLE)
| |||||||||||||||||||||
| 413 | "Send Me An E-mail" ); | ||||||||||||||||||||
| 414 | |||||||||||||||||||||
| 415 | 0 | ▶ | $globals->set_page_body( | ||||||||||||||||||
|
Condition0%0/2
$globals->pref($PKEY_MSG_NEW_HEAD) || "<h1>@{[$globals->page_title];}</h1>\n\n<p>This form is provided as an easy way for you to send me a private \ne-mail message, when you wish to contact me and/or give me your \nthoughts on this site. This is also a good forum to report any bugs \nyou have discovered, so I can fix them as soon as possible.</p>\n"
MC/DC0%0/1
$globals->pref($PKEY_MSG_NEW_HEAD) || "<h1>@{[$globals->page_title];}</h1>\n\n<p>This form is provided as an easy way for you to send me a private \ne-mail message, when you wish to contact me and/or give me your \nthoughts on this site. This is also a good forum to report any bugs \nyou have discovered, so I can fix them as soon as possible.</p>\n"
$globals->pref($PKEY_MSG_NEW_HEAD)
Truth table0%0/2
A
A= $globals->pref($PKEY_MSG_NEW_HEAD)
| |||||||||||||||||||||
| 416 | $globals->pref( $PKEY_MSG_NEW_HEAD ) || <<__endquote ); | ||||||||||||||||||||
| 417 | 0 | <h1>@{[$globals->page_title()]}</h1> | |||||||||||||||||||
| 418 | |||||||||||||||||||||
| 419 | <p>This form is provided as an easy way for you to send me a private | ||||||||||||||||||||
| 420 | e-mail message, when you wish to contact me and/or give me your | ||||||||||||||||||||
| 421 | thoughts on this site. This is also a good forum to report any bugs | ||||||||||||||||||||
| 422 | you have discovered, so I can fix them as soon as possible.</p> | ||||||||||||||||||||
| 423 | __endquote | ||||||||||||||||||||
| 424 | |||||||||||||||||||||
| 425 | 0 | $globals->append_page_body( <<__endquote ); | |||||||||||||||||||
| 426 | 0 | <p>The fields indicated with a '@{[$form->required_field_marker()]}' | |||||||||||||||||||
| 427 | are required.</p> | ||||||||||||||||||||
| 428 | |||||||||||||||||||||
| 429 | 0 | @{$form->make_html_input_form( 1, 1 )} | |||||||||||||||||||
| 430 | |||||||||||||||||||||
| 431 | <p>It may take from 1 to 30 seconds to process this form, so please be | ||||||||||||||||||||
| 432 | patient and don't click Send multiple times. A confirmation message | ||||||||||||||||||||
| 433 | will appear if everything worked.</p> | ||||||||||||||||||||
| 434 | __endquote | ||||||||||||||||||||
| 435 | } | ||||||||||||||||||||
| 436 | |||||||||||||||||||||
| 437 | ###################################################################### | ||||||||||||||||||||
| 438 | |||||||||||||||||||||
| 439 | 0 | ▶ | sub invalid_input { | ||||||||||||||||||
|
Subroutine
invalid_input: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 440 | 0 | my ($self, $form) = @_; | |||||||||||||||||||
| 441 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 442 | |||||||||||||||||||||
| 443 | 0 | $globals->page_title( "Information Missing" ); | |||||||||||||||||||
| 444 | |||||||||||||||||||||
| 445 | 0 | $globals->set_page_body( <<__endquote ); | |||||||||||||||||||
| 446 | 0 | <h1>@{[$globals->page_title()]}</h1> | |||||||||||||||||||
| 447 | |||||||||||||||||||||
| 448 | <p>Your message could not be sent because some of the fields were not | ||||||||||||||||||||
| 449 | correctly filled in, which are indicated with a | ||||||||||||||||||||
| 450 | 0 | '@{[$form->bad_input_marker()]}'. Fields with a | |||||||||||||||||||
| 451 | 0 | '@{[$form->required_field_marker()]}' are required and can not be left | |||||||||||||||||||
| 452 | empty. Please make sure you have entered your name and e-mail address | ||||||||||||||||||||
| 453 | correctly, and then try sending it again.</p> | ||||||||||||||||||||
| 454 | |||||||||||||||||||||
| 455 | 0 | @{$form->make_html_input_form( 1, 1 )} | |||||||||||||||||||
| 456 | |||||||||||||||||||||
| 457 | <p>It may take from 1 to 30 seconds to process this form, so please be | ||||||||||||||||||||
| 458 | patient and don't click Send multiple times. A confirmation message | ||||||||||||||||||||
| 459 | will appear if everything worked.</p> | ||||||||||||||||||||
| 460 | __endquote | ||||||||||||||||||||
| 461 | } | ||||||||||||||||||||
| 462 | |||||||||||||||||||||
| 463 | ###################################################################### | ||||||||||||||||||||
| 464 | |||||||||||||||||||||
| 465 | 0 | ▶ | sub send_mail_to_me { | ||||||||||||||||||
|
Subroutine
send_mail_to_me: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 466 | 0 | my ($self, $form) = @_; | |||||||||||||||||||
| 467 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 468 | |||||||||||||||||||||
| 469 | 0 | ▶ | my $err_msg = $self->send_email_message( | ||||||||||||||||||
|
Condition0%0/2
$globals->pref($PKEY_EMAIL_SUBJ) || $globals->default_application_title . ' -- Private Mail Message'
MC/DC0%0/1
$globals->pref($PKEY_EMAIL_SUBJ) || $globals->default_application_title . ' -- Private Mail Message'
$globals->pref($PKEY_EMAIL_SUBJ)
Truth table0%0/2
A
A= $globals->pref($PKEY_EMAIL_SUBJ)
| |||||||||||||||||||||
| 470 | $globals->default_maintainer_name(), | ||||||||||||||||||||
| 471 | $globals->default_maintainer_email_address(), | ||||||||||||||||||||
| 472 | $globals->user_post_param( $FFN_NAMEREAL ), | ||||||||||||||||||||
| 473 | $globals->user_post_param( $FFN_EMAIL ), | ||||||||||||||||||||
| 474 | $globals->pref( $PKEY_EMAIL_SUBJ ) || | ||||||||||||||||||||
| 475 | $globals->default_application_title().' -- Private Mail Message', | ||||||||||||||||||||
| 476 | $form->make_text_input_echo( 0, $EMPTY_FIELD_ECHO_STRING ), | ||||||||||||||||||||
| 477 | <<__endquote. | ||||||||||||||||||||
| 478 | It is the result of a form submission from a site visitor, | ||||||||||||||||||||
| 479 | 0 | "@{[$globals->user_post_param( $FFN_NAMEREAL )]}" <@{[$globals->user_post_param( $FFN_EMAIL )]}>. | |||||||||||||||||||
| 480 | 0 | ▶ | From: @{[$globals->client_ip()]} @{[$globals->client_domain()]}. | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 481 | __endquote | ||||||||||||||||||||
| 482 | ($globals->user_post_param( $FFN_WANTCOPY ) ? | ||||||||||||||||||||
| 483 | "The visitor also requested a copy be sent to them.\n" : | ||||||||||||||||||||
| 484 | "The visitor did not request a copy be sent to them.\n"), | ||||||||||||||||||||
| 485 | ); | ||||||||||||||||||||
| 486 | |||||||||||||||||||||
| 487 | 0 | ▶ | if( $err_msg ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 488 | 0 | $globals->add_error( $err_msg ); | |||||||||||||||||||
| 489 | |||||||||||||||||||||
| 490 | 0 | $globals->page_title( "Error Sending Mail" ); | |||||||||||||||||||
| 491 | |||||||||||||||||||||
| 492 | 0 | $globals->set_page_body( <<__endquote ); | |||||||||||||||||||
| 493 | 0 | <h1>@{[$globals->page_title()]}</h1> | |||||||||||||||||||
| 494 | |||||||||||||||||||||
| 495 | <p>I'm sorry, but an error has occurred while trying to e-mail your | ||||||||||||||||||||
| 496 | message to me. As a result I will not see it.</p> | ||||||||||||||||||||
| 497 | |||||||||||||||||||||
| 498 | <p>This problem can occur if you enter a nonexistant or unreachable | ||||||||||||||||||||
| 499 | e-mail address into the e-mail field, in which case, please enter a | ||||||||||||||||||||
| 500 | working e-mail address and try clicking 'Send' again. You can check | ||||||||||||||||||||
| 501 | if that is the problem by checking the following error string:</p> | ||||||||||||||||||||
| 502 | |||||||||||||||||||||
| 503 | <p>$err_msg</p> | ||||||||||||||||||||
| 504 | |||||||||||||||||||||
| 505 | 0 | @{[$self->get_amendment_message()]} | |||||||||||||||||||
| 506 | |||||||||||||||||||||
| 507 | 0 | @{$form->make_html_input_form( 1, 1 )} | |||||||||||||||||||
| 508 | |||||||||||||||||||||
| 509 | <p>It may take from 1 to 30 seconds to process this form, so please be | ||||||||||||||||||||
| 510 | patient and don't click Send multiple times. A confirmation message | ||||||||||||||||||||
| 511 | will appear if everything worked.</p> | ||||||||||||||||||||
| 512 | __endquote | ||||||||||||||||||||
| 513 | |||||||||||||||||||||
| 514 | 0 | $globals->add_no_error(); | |||||||||||||||||||
| 515 | 0 | return( 0 ); | |||||||||||||||||||
| 516 | } | ||||||||||||||||||||
| 517 | |||||||||||||||||||||
| 518 | 0 | return( 1 ); | |||||||||||||||||||
| 519 | } | ||||||||||||||||||||
| 520 | |||||||||||||||||||||
| 521 | ###################################################################### | ||||||||||||||||||||
| 522 | |||||||||||||||||||||
| 523 | 0 | ▶ | sub mail_me_ok { | ||||||||||||||||||
|
Subroutine
mail_me_ok: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 524 | 0 | my ($self, $form) = @_; | |||||||||||||||||||
| 525 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 526 | |||||||||||||||||||||
| 527 | 0 | $globals->page_title( "Your Message Has Been Sent" ); | |||||||||||||||||||
| 528 | |||||||||||||||||||||
| 529 | 0 | $globals->set_page_body( <<__endquote ); | |||||||||||||||||||
| 530 | 0 | <h1>@{[$globals->page_title()]}</h1> | |||||||||||||||||||
| 531 | |||||||||||||||||||||
| 532 | <p>This is what the message said:</p> | ||||||||||||||||||||
| 533 | |||||||||||||||||||||
| 534 | <p><strong>To:</strong> | ||||||||||||||||||||
| 535 | 0 | @{[$globals->default_maintainer_name()]} | |||||||||||||||||||
| 536 | 0 | <@{[$globals->default_maintainer_email_address()]}> | |||||||||||||||||||
| 537 | <br /><strong>From:</strong> | ||||||||||||||||||||
| 538 | 0 | @{[$globals->user_post_param( $FFN_NAMEREAL )]} | |||||||||||||||||||
| 539 | 0 | <@{[$globals->user_post_param( $FFN_EMAIL )]}> | |||||||||||||||||||
| 540 | <br /><strong>Subject:</strong> | ||||||||||||||||||||
| 541 | 0 | ▶ | @{[$globals->pref( $PKEY_EMAIL_SUBJ ) || | ||||||||||||||||||
|
Condition0%0/2
$globals->pref($PKEY_EMAIL_SUBJ) || $globals->default_application_title . ' -- Private Mail Message'
MC/DC0%0/1
$globals->pref($PKEY_EMAIL_SUBJ) || $globals->default_application_title . ' -- Private Mail Message'
$globals->pref($PKEY_EMAIL_SUBJ)
Truth table0%0/2
A
A= $globals->pref($PKEY_EMAIL_SUBJ)
| |||||||||||||||||||||
| 542 | $globals->default_application_title().' -- Private Mail Message']}</p> | ||||||||||||||||||||
| 543 | |||||||||||||||||||||
| 544 | 0 | @{[$form->make_html_input_echo( 1, 1, $EMPTY_FIELD_ECHO_STRING )]} | |||||||||||||||||||
| 545 | __endquote | ||||||||||||||||||||
| 546 | } | ||||||||||||||||||||
| 547 | |||||||||||||||||||||
| 548 | ###################################################################### | ||||||||||||||||||||
| 549 | |||||||||||||||||||||
| 550 | 0 | ▶ | sub send_mail_to_writer { | ||||||||||||||||||
|
Subroutine
send_mail_to_writer: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 551 | 0 | my ($self, $form) = @_; | |||||||||||||||||||
| 552 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 553 | |||||||||||||||||||||
| 554 | 0 | ▶ | my $err_msg = $self->send_email_message( | ||||||||||||||||||
|
Condition0%0/2
$globals->pref($PKEY_EMAIL_SUBJ) || $globals->default_application_title . ' -- Private Mail Message'
MC/DC0%0/1
$globals->pref($PKEY_EMAIL_SUBJ) || $globals->default_application_title . ' -- Private Mail Message'
$globals->pref($PKEY_EMAIL_SUBJ)
Truth table0%0/2
A
A= $globals->pref($PKEY_EMAIL_SUBJ)
| |||||||||||||||||||||
| 555 | $globals->user_post_param( $FFN_NAMEREAL ), | ||||||||||||||||||||
| 556 | $globals->user_post_param( $FFN_EMAIL ), | ||||||||||||||||||||
| 557 | $globals->default_maintainer_name(), | ||||||||||||||||||||
| 558 | $globals->default_maintainer_email_address(), | ||||||||||||||||||||
| 559 | $globals->pref( $PKEY_EMAIL_SUBJ ) || | ||||||||||||||||||||
| 560 | $globals->default_application_title().' -- Private Mail Message', | ||||||||||||||||||||
| 561 | $form->make_text_input_echo( 0, $EMPTY_FIELD_ECHO_STRING ), | ||||||||||||||||||||
| 562 | <<__endquote, | ||||||||||||||||||||
| 563 | It is the result of a form submission from a site visitor, | ||||||||||||||||||||
| 564 | 0 | "@{[$globals->user_post_param( $FFN_NAMEREAL )]}" <@{[$globals->user_post_param( $FFN_EMAIL )]}>. | |||||||||||||||||||
| 565 | 0 | From: @{[$globals->client_ip()]} @{[$globals->client_domain()]}. | |||||||||||||||||||
| 566 | __endquote | ||||||||||||||||||||
| 567 | ); | ||||||||||||||||||||
| 568 | |||||||||||||||||||||
| 569 | 0 | ▶ | if( $err_msg ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 570 | 0 | $globals->add_error( $err_msg ); | |||||||||||||||||||
| 571 | 0 | $globals->append_page_body( <<__endquote ); | |||||||||||||||||||
| 572 | <p>However, something went wrong when trying to send you a copy: | ||||||||||||||||||||
| 573 | $err_msg.</p> | ||||||||||||||||||||
| 574 | __endquote | ||||||||||||||||||||
| 575 | 0 | $globals->add_no_error(); | |||||||||||||||||||
| 576 | |||||||||||||||||||||
| 577 | } else { | ||||||||||||||||||||
| 578 | 0 | $globals->append_page_body( <<__endquote ); | |||||||||||||||||||
| 579 | <p>Also, a copy was successfully sent to you at | ||||||||||||||||||||
| 580 | 0 | '@{[$globals->user_post_param( $FFN_EMAIL )]}'.</p> | |||||||||||||||||||
| 581 | __endquote | ||||||||||||||||||||
| 582 | } | ||||||||||||||||||||
| 583 | } | ||||||||||||||||||||
| 584 | |||||||||||||||||||||
| 585 | ###################################################################### | ||||||||||||||||||||
| 586 | |||||||||||||||||||||
| 587 | 0 | ▶ | sub fetch_all_records { | ||||||||||||||||||
|
Subroutine
fetch_all_records: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 588 | 0 | my ($self, $filename, $read_and_write) = @_; | |||||||||||||||||||
| 589 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 590 | |||||||||||||||||||||
| 591 | 0 | my $fh = gensym; | |||||||||||||||||||
| 592 | |||||||||||||||||||||
| 593 | 0 | ▶ | $self->open_and_lock( $fh, $filename, $read_and_write ) or return( undef ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 594 | |||||||||||||||||||||
| 595 | 0 | ▶ | seek( $fh, 0, 0 ) or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 596 | 0 | $globals->add_virtual_filename_error( "seek start of", $filename ); | |||||||||||||||||||
| 597 | 0 | return( undef ); | |||||||||||||||||||
| 598 | }; | ||||||||||||||||||||
| 599 | |||||||||||||||||||||
| 600 | 0 | ▶ | my $ra_record_list = CGI::MultiValuedHash->batch_from_file( $fh, 1 ) or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 601 | 0 | $globals->add_virtual_filename_error( "read record from", $filename ); | |||||||||||||||||||
| 602 | 0 | return( undef ); | |||||||||||||||||||
| 603 | }; | ||||||||||||||||||||
| 604 | |||||||||||||||||||||
| 605 | 0 | ▶ | $self->unlock_and_close( $fh, $filename ) or return( undef ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 606 | |||||||||||||||||||||
| 607 | 0 | ▶ | return( wantarray ? @{$ra_record_list} : $ra_record_list ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 608 | } | ||||||||||||||||||||
| 609 | |||||||||||||||||||||
| 610 | ###################################################################### | ||||||||||||||||||||
| 611 | |||||||||||||||||||||
| 612 | 0 | ▶ | sub open_and_lock { | ||||||||||||||||||
|
Subroutine
open_and_lock: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 613 | 0 | my ($self, $fh, $filename, $read_and_write) = @_; | |||||||||||||||||||
| 614 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 615 | |||||||||||||||||||||
| 616 | 0 | my $physical_path = $globals->physical_filename( $filename ); | |||||||||||||||||||
| 617 | 0 | ▶ | my $flags = $read_and_write ? O_RDWR|O_CREAT : O_RDONLY; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 618 | 0 | my $perms = 0666; | |||||||||||||||||||
| 619 | |||||||||||||||||||||
| 620 | 0 | ▶ | sysopen( $fh, $physical_path, $flags, $perms ) or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 621 | 0 | $globals->add_virtual_filename_error( "open", $filename ); | |||||||||||||||||||
| 622 | 0 | return( undef ); | |||||||||||||||||||
| 623 | }; | ||||||||||||||||||||
| 624 | |||||||||||||||||||||
| 625 | 0 | ▶ | flock( $fh, $read_and_write ? LOCK_EX : LOCK_SH ) or do { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 626 | 0 | $globals->add_virtual_filename_error( "lock", $filename ); | |||||||||||||||||||
| 627 | 0 | return( undef ); | |||||||||||||||||||
| 628 | }; | ||||||||||||||||||||
| 629 | |||||||||||||||||||||
| 630 | 0 | return( 1 ); | |||||||||||||||||||
| 631 | } | ||||||||||||||||||||
| 632 | |||||||||||||||||||||
| 633 | ###################################################################### | ||||||||||||||||||||
| 634 | |||||||||||||||||||||
| 635 | 0 | ▶ | sub unlock_and_close { | ||||||||||||||||||
|
Subroutine
unlock_and_close: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 636 | 0 | my ($self, $fh, $filename) = @_; | |||||||||||||||||||
| 637 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 638 | |||||||||||||||||||||
| 639 | 0 | ▶ | flock( $fh, LOCK_UN ) or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 640 | 0 | $globals->add_virtual_filename_error( "unlock", $filename ); | |||||||||||||||||||
| 641 | 0 | return( undef ); | |||||||||||||||||||
| 642 | }; | ||||||||||||||||||||
| 643 | |||||||||||||||||||||
| 644 | 0 | ▶ | close( $fh ) or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 645 | 0 | $globals->add_virtual_filename_error( "close", $filename ); | |||||||||||||||||||
| 646 | 0 | return( undef ); | |||||||||||||||||||
| 647 | }; | ||||||||||||||||||||
| 648 | |||||||||||||||||||||
| 649 | 0 | return( 1 ); | |||||||||||||||||||
| 650 | } | ||||||||||||||||||||
| 651 | |||||||||||||||||||||
| 652 | ###################################################################### | ||||||||||||||||||||
| 653 | |||||||||||||||||||||
| 654 | 0 | ▶ | sub send_email_message { | ||||||||||||||||||
|
Subroutine
send_email_message: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||
| 655 | 0 | my ($self, $to_name, $to_email, $from_name, $from_email, | |||||||||||||||||||
| 656 | $subject, $body, $body_head_addition) = @_; | ||||||||||||||||||||
| 657 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 658 | |||||||||||||||||||||
| 659 | 0 | my $EMAIL_HEADER_STRIP_PATTERN = '[,<>()"\'\n]'; #for names and addys | |||||||||||||||||||
| 660 | 0 | $to_name =~ s/$EMAIL_HEADER_STRIP_PATTERN//g; | |||||||||||||||||||
| 661 | 0 | $to_email =~ s/$EMAIL_HEADER_STRIP_PATTERN//g; | |||||||||||||||||||
| 662 | 0 | $from_name =~ s/$EMAIL_HEADER_STRIP_PATTERN//g; | |||||||||||||||||||
| 663 | 0 | $from_email =~ s/$EMAIL_HEADER_STRIP_PATTERN//g; | |||||||||||||||||||
| 664 | 0 | ▶ | $globals->is_debug() and $subject .= " -- debug"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 665 | |||||||||||||||||||||
| 666 | 0 | my $body_header = <<__endquote. | |||||||||||||||||||
| 667 | -------------------------------------------------- | ||||||||||||||||||||
| 668 | 0 | This e-mail was sent at @{[$self->today_date_utc()]} | |||||||||||||||||||
| 669 | 0 | by the web site "@{[$globals->default_application_title()]}", | |||||||||||||||||||
| 670 | 0 | ▶ | which is located at "@{[$globals->url_base()]}". | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 671 | __endquote | ||||||||||||||||||||
| 672 | $body_head_addition. | ||||||||||||||||||||
| 673 | ($globals->is_debug() ? "Debugging is currently turned on.\n" : | ||||||||||||||||||||
| 674 | '').<<__endquote; | ||||||||||||||||||||
| 675 | -------------------------------------------------- | ||||||||||||||||||||
| 676 | __endquote | ||||||||||||||||||||
| 677 | |||||||||||||||||||||
| 678 | 0 | my $body_footer = <<__endquote; | |||||||||||||||||||
| 679 | |||||||||||||||||||||
| 680 | |||||||||||||||||||||
| 681 | -------------------------------------------------- | ||||||||||||||||||||
| 682 | END OF MESSAGE | ||||||||||||||||||||
| 683 | __endquote | ||||||||||||||||||||
| 684 | |||||||||||||||||||||
| 685 | 0 | my $host = $globals->default_smtp_host(); | |||||||||||||||||||
| 686 | 0 | my $timeout = $globals->default_smtp_timeout(); | |||||||||||||||||||
| 687 | 0 | my $error_msg = ''; | |||||||||||||||||||
| 688 | |||||||||||||||||||||
| 689 | TRY: { | ||||||||||||||||||||
| 690 | 0 | my $smtp; | |||||||||||||||||||
| 691 | |||||||||||||||||||||
| 692 | 0 | eval { require Net::SMTP; }; | |||||||||||||||||||
| 693 | 0 | ▶ | if( $@ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 694 | 0 | $error_msg = "can't open program module 'Net::SMTP'"; | |||||||||||||||||||
| 695 | 0 | last TRY; | |||||||||||||||||||
| 696 | } | ||||||||||||||||||||
| 697 | |||||||||||||||||||||
| 698 | 0 | ▶ | unless( $smtp = Net::SMTP->new( $host, Timeout => $timeout ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 699 | 0 | $error_msg = "can't connect to smtp host: $host"; | |||||||||||||||||||
| 700 | 0 | last TRY; | |||||||||||||||||||
| 701 | } | ||||||||||||||||||||
| 702 | |||||||||||||||||||||
| 703 | 0 | ▶ | unless( $smtp->verify( $from_email ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 704 | 0 | $error_msg = "invalid address: @{[$smtp->message()]}"; | |||||||||||||||||||
| 705 | 0 | last TRY; | |||||||||||||||||||
| 706 | } | ||||||||||||||||||||
| 707 | |||||||||||||||||||||
| 708 | 0 | ▶ | unless( $smtp->verify( $to_email ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 709 | 0 | $error_msg = "invalid address: @{[$smtp->message()]}"; | |||||||||||||||||||
| 710 | 0 | last TRY; | |||||||||||||||||||
| 711 | } | ||||||||||||||||||||
| 712 | |||||||||||||||||||||
| 713 | 0 | ▶ | unless( $smtp->mail( "$from_name <$from_email>" ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 714 | 0 | $error_msg = "from: @{[$smtp->message()]}"; | |||||||||||||||||||
| 715 | 0 | last TRY; | |||||||||||||||||||
| 716 | } | ||||||||||||||||||||
| 717 | |||||||||||||||||||||
| 718 | 0 | ▶ | unless( $smtp->to( "$to_name <$to_email>" ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 719 | 0 | $error_msg = "to: @{[$smtp->message()]}"; | |||||||||||||||||||
| 720 | 0 | last TRY; | |||||||||||||||||||
| 721 | } | ||||||||||||||||||||
| 722 | |||||||||||||||||||||
| 723 | 0 | $smtp->data( <<__endquote ); | |||||||||||||||||||
| 724 | From: $from_name <$from_email> | ||||||||||||||||||||
| 725 | To: $to_name <$to_email> | ||||||||||||||||||||
| 726 | Subject: $subject | ||||||||||||||||||||
| 727 | Content-Type: text/plain; charset=us-ascii | ||||||||||||||||||||
| 728 | |||||||||||||||||||||
| 729 | $body_header | ||||||||||||||||||||
| 730 | $body | ||||||||||||||||||||
| 731 | $body_footer | ||||||||||||||||||||
| 732 | __endquote | ||||||||||||||||||||
| 733 | |||||||||||||||||||||
| 734 | 0 | $smtp->quit(); | |||||||||||||||||||
| 735 | } | ||||||||||||||||||||
| 736 | |||||||||||||||||||||
| 737 | 0 | return( $error_msg ); | |||||||||||||||||||
| 738 | } | ||||||||||||||||||||
| 739 | |||||||||||||||||||||
| 740 | ###################################################################### | ||||||||||||||||||||
| 741 | |||||||||||||||||||||
| 742 | 0 | ▶ | sub today_date_utc { | ||||||||||||||||||
|
Subroutine
today_date_utc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 743 | 0 | my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time); | |||||||||||||||||||
| 744 | 0 | $year += 1900; # year counts from 1900 AD otherwise | |||||||||||||||||||
| 745 | 0 | $mon += 1; # ensure January is 1, not 0 | |||||||||||||||||||
| 746 | 0 | my @parts = ($year, $mon, $mday, $hour, $min, $sec); | |||||||||||||||||||
| 747 | 0 | return( sprintf( "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d UTC", @parts ) ); | |||||||||||||||||||
| 748 | } | ||||||||||||||||||||
| 749 | |||||||||||||||||||||
| 750 | ###################################################################### | ||||||||||||||||||||
| 751 | |||||||||||||||||||||
| 752 | 0 | ▶ | sub get_amendment_message { | ||||||||||||||||||
|
Subroutine
get_amendment_message: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 753 | 0 | my ($self) = shift( @_ ); | |||||||||||||||||||
| 754 | 0 | my $globals = $self->{$KEY_SITE_GLOBALS}; | |||||||||||||||||||
| 755 | 0 | return( <<__endquote ); | |||||||||||||||||||
| 756 | <p>This should be temporary, the result of a transient server problem or an | ||||||||||||||||||||
| 757 | 0 | update being performed at the moment. Click @{[$globals->recall_html('here')]} | |||||||||||||||||||
| 758 | to automatically try again. If the problem persists, please try again later, | ||||||||||||||||||||
| 759 | 0 | or send an @{[$globals->maintainer_email_html('e-mail')]} message about the | |||||||||||||||||||
| 760 | problem, so it can be fixed.</p> | ||||||||||||||||||||
| 761 | __endquote | ||||||||||||||||||||
| 762 | } | ||||||||||||||||||||
| 763 | |||||||||||||||||||||
| 764 | ###################################################################### | ||||||||||||||||||||
| 765 | |||||||||||||||||||||
| 766 | 1 | 1; | |||||||||||||||||||
| 767 | __END__ | ||||||||||||||||||||