We will debug here the script cookie.cgi. Open the script in the editor and enable "Internal server" and "Run with server". Run this script a few to understand how it creates a session with the user using cookies. Let's say we want to debug the script after some animals have been selected and the submit has been pressed, so more animals can be added in the contents.

 

Using the remote debugger

 

Run the script, and select some animals in the list box. Before pressing the "Add" button, go back to the editor and change the first line of the script adding a -d parameter, for example:

 

#!/usr/local/bin/perl -d

 

Save afterwards. The -d parameter tell's perl to invoke the debugger the next time this script runs. In our case, this script will run when we press the "Add" button. Now go to menu Debug / Listen for remote debugger. This will initialize OptiPerl's debugger, and it will wait for the script to run. Press now the "Add" button. You should get a "Connected" status in the debugger log window. Upon connecting, the debugger will download the source code, and open it in the editor in a new tab, where you can trace it.

 

icon_exclaim You will notice that the downloaded copy is an exact copy of the cookie.cgi you have in the editor. So why did it have to open it again? Actually it was not opened; the debugger is now connected to perl, and it downloaded the source code. Remember that listening for a remote debugger, means that optiperl will just wait for a debugger and then use it to debug a remote script. OptiPerl does not know which script that will be, and it might not even have it's source code, if the debugger is on a different computer that yours. That is why it must download it's source code so it can display it to you. Note that using remote debugging enables you to debug a script ever by running it on your web host via an internet connection.

 

Using the local debugger

 

You can also start the debugger directly on the script. This is easier to do then the above, but does not enable you to use the submit button of the web browser. You will need to manually enter the information expected using the query editor. Open the query editor, and enable the POST and COOKIE methods. Disable all other. Select the POST method, and enter the following pairs:

 

new_animals = baboon

new_animals = gnu

action = Add

 

The above emulates selecting "baboon" and "gnu" and pressing "Add"

 

The cookie field contains the animals of the current session, which we can edit also. Enter something like:

 

animals = baboon&1&bear&1

 

Before starting the debugger, see what happens when you press run (make sure you remove first the -d parameter added above). You should get in the current contents: 2 baboon, 1 gnu, 1 bear. This the cookie of the session, plus the animals we added with the "add" button.

 

Now try starting the debugger and tracing the script. Notice that the @new array and %zoo hash is filled correctly with the data from the query editor.

 

 

Top  Previous  Next