#!/opt/perl524 use strict; use warnings; main() unless caller(); sub main { use CGI; my $cgi = CGI->new; if ( !$cgi->param ) { print $cgi->header, my_form( 'action_url' => $cgi->url() ); exit; } my $num1 = $cgi->param('num1') || ''; my $num2 = $cgi->param('num2') || ''; # Next, add the value of the incoming parameters and display a result (not shown here) # my $sum = add_two_numbers( $num1, $num2 ); # Then print a result to the web browser and display a fresh form under the result (not shown here) exit; } ## end sub main sub add_two_numbers { my ( $num1, $num2 ) = @_; return $num1 + $num2; } sub my_form { my %params = @_; my $action_url = $params{'action_url'} || ''; die "No URL specified for the 'action' attribute of the form, can't continue" if ( !$action_url ); my $form = qq| Add Two Numbers

Add Two Numbers

Enter some first number:

Enter some second number:

|; } ## end sub my_form #### #!/opt/perl524 use strict; use warnings; use Test::More ('no_plan'); my $SCRIPT_LOCAL_LOCATION = 'C:\Users\davel\Documents\scripts\add_two_numbers_modified_as_main.cgi'; require_ok($SCRIPT_LOCAL_LOCATION) or exit; ok( add_two_numbers( 3, 17 ) == 20, "3 plus 17 produces 20" ); done_testing(); #### ok 1 - require 'C:\Users\davel\Documents\scripts\add_two_numbers_modified_as_main.cgi'; ok 2 - 3 plus 17 produces 20 1..2 #### #!/opt/perl524 use strict; use warnings; main() if ( !caller() ); sub main { use CGI; my $cgi = CGI->new; if ( !$cgi->param ) { print $cgi->header, my_form( 'action_url' => $cgi->url() ); exit; } my $num1 = $cgi->param('num1') || ''; my $num2 = $cgi->param('num2') || ''; # Next, add the value of the incoming parameters and display a result (not shown here) # my $sum = add_two_numbers( $num1, $num2 ); # Then print a result to the web browser and display a fresh form under the result (not shown here) exit; } ## end sub main sub add_two_numbers { my ( $num1, $num2 ) = @_; return $num1 + $num2; } sub my_form { my %params = @_; my $action_url = $params{'action_url'} || ''; die "No URL specified for the 'action' attribute of the form, can't continue" if ( !$action_url ); my $form = qq| Add Two Numbers

Add Two Numbers

Enter some first number:

Enter some second number:

|; } ## end sub my_form ##
## not ok 1 - require 'C:\Users\davel\Documents\scripts\add_two_numbers_modified_as_main.cgi'; # Failed test 'require 'C:\Users\davel\Documents\scripts\add_two_numbers_modified_as_main.cgi';' # at C:\Users\davel\Documents\scripts\add_two_numbers_modified_as_main.cgi.t line 11. # Tried to require ''C:\Users\davel\Documents\scripts\add_two_numbers_modified_as_main.cgi''. # Error: C:\Users\davel\Documents\scripts\add_two_numbers_modified_as_main.cgi did not return a true value at (eval 8) line 2. 1..1 # Looks like you failed 1 test of 1.