CGI-Debug

 view release on metacpan or  search on metacpan

Debug.pm  view on Meta::CPAN

	return $info;
}

sub report_params
{
    return &key_values( 'Parameters', { map{ $_, [&CGI::param($_)] } &CGI::param } );
}

sub report_cookies
{
    return &key_values( 'Cookies', { map{ $_, &CGI::cookie($_) } &CGI::cookie() } );
}

sub report_environment
{
    return &key_values( 'Environment', \%ENV );
}

sub header_control
{
    my $outfile = "";

Debug.pm  view on Meta::CPAN

    use CGI::Debug( on => 'fatals' );

Allways show complete debugging info:
    use CGI::Debug( report => 'everything', on => 'anything' );

Send debug data as mail to file owner:
    use CGI::Debug( to => 'mail' );

=head1 CONTROL PARAMETERS

Cookie control variables makes it possible to control the debugging
environment from a program in another browser window. This would be
prefereble with complex web pages (framesets, etc). The page is viewd
as normal in one window. All debugging data is shown i another window,
that also provides controls to alter the debugging environment. (But
this external debugging program is not yet implemented.)

Environment control variables makes it more easy to globaly set the
debugging environment for a web site. It is also a way for the target
program to control the CGI::Debug module actions.

The four methods can be mixed. (Cookies, enviroment, import parameters
and defaults.) The module will try to make sense with whatever you
give it. The possibilites of control are more limitied in the Cookie /
ENV version.

=head2 report errors

  Cookie / ENV: CGI-Debug-report=errors

  Import: report => 'errors'
	  report => [ 'errors', ... ]

Report the content of STDERR. 

This will allways be reported. This control is for saying that none of
the other defualt things will be reported. This will only override the
default. Other report controls will be accumulated.

=head2 report empty_body

  Cookie / ENV: CGI-Debug-report=empty_body

  Import: report => 'empty_body'
	  report => [ 'empty_body', ... ]

Report if HTTP-body is empty.

This requires that "header control" is set.

=head2 report time

  Cookie / ENV: CGI-Debug-report=time

  Import: report => 'time'
	  report => [ 'time', ... ]

Report the elapsed time from beginning to end of execution.

If Time::Hires is found, this will be given with subsecond precision.

=head2 report params

  Cookie / ENV: CGI-Debug-report=params

  Import: report => 'params'
	  report => [ 'params', ... ]

Report a table of all name/value pairs, as given by the CGI module.

Multiple values will be reported as distinct pairs, in order.  Values
will be truncated to the "set param_length" number of chars. The total
length is shown for each value.

=head2 report cookies

  Cookie / ENV: CGI-Debug-report=cookies

  Import: report => 'cookies'
	  report => [ 'cookies', ... ]

Report a table of all cookies, as given by the CGI module.

Multiple values will be reported as distinct pairs, in order.  Values
will be truncated to the "set param_length" number of chars. The total
length is shown for each value.

=head2 report environment

  Cookie / ENV: CGI-Debug-report=environment

  Import: report => 'environment'
	  report => [ 'environment', ... ]

Report a table of all environment varialbes
INCLUDING empty_body, time, params, cookies.

=head2 report everything

  Cookie / ENV: CGI-Debug-report=everything

  Import: report => 'everything'
	  report => [ 'everything', ... ]

Report environment and all what that includes.

(The plan is for this control to include the contorl of HTML
compliance.)

=head2 report internals

  Cookie / ENV: CGI-Debug-report=internals

  Import: report => 'internals'
	  report => [ 'internals', ... ]

Report data for the debugging of the module itself, including
everything else.  Data::Dumper will be used, if found.

If the module itself dies, you will probably not get any output at al.
You can check for errors in the file /tmp/CGI-Debug-error-$$.  In
order to see what error CGI::Debug is generating, you could changing
$DEBUG to 2 or more, in the module file itself. Please email the
author about any problems.


=head2 on fatals

  Cookie / ENV: CGI-Debug-on=fatals

  Import: on => 'fatals'

Only deliver report on fatal errors.

This will ignore warnings. CGI::Debug checks the exit value.  Reports
will also be delivered if an empty body is detected, in case "header
control" is set.

=head2 on warnings

  Cookie / ENV: CGI-Debug-on=warnings

  Import: on => 'warnings'

Only deliver report on fatals or if there was any output to STDERR.

=head2 on anything

  Cookie / ENV: CGI-Debug-on=anything

  Import: on => 'anything'

Always deliver reports, even if there was no errors.

=head2 to browser

  Cookie / ENV: CGI-Debug-to=browser

  Import: to => 'browser'
          to => [ 'browser', ... ]
          to => { 'browser' => 1, ... }

Send report to browser.

The report will come after any program output. The module will assume
the page is in text/html, unless "header control" is set, in case this
will be checked. (In none HTML mode, the header and delimiter will be
ASCII.)

There is many cases in which faulty or bad HTML will hide the
report. This could be controled with "report html_compliance" (which is
not yet implemented).

=head2 to log

  Cookie / ENV: CGI-Debug-to=log

  Import: to => 'log'
          to => [ 'log', ... ]
          to => { 'log' => 1, ... }

Send report to the standard error log.

This will easily result in a huge log.

=head2 to file

  Cookie / ENV: CGI-Debug-to=file
                CGI-Debug-to-file=filename

  Import: to => 'file'
          to => [ 'file', ... ]
          to => { 'file' => 'filename', ... }
          to => { 'file' => [ 'filename1', 'filename2', ... ] ... }

Save report to filename.

Default filename is "/tmp/CGI-Debug-error.txt". The file will be
overwritten by the next report. This solution is to be used for
debugging with an external program. (To be used with cookies.)

This will not work well with framesets that generates multipple
reports at a time. The action of this control may change in future
versions.

=head2 to mail

  Cookie / ENV: CGI-Debug-to=mail
                CGI-Debug-to-mail=mailaddress

  Import: to => 'mail'
          to => [ 'mail', ... ]
          to => { 'mail' => 'mailaddress', ... }
          to => { 'mail' => [ 'mailaddress1', 'mailaddress2', ... ] ... }

Send report with email.

The default mailaddress is the owner of the cgi program.  This

Debug.pm  view on Meta::CPAN

the default behaviour of Mail::Send, set the enviroment variables, as
described in the POD for Mail::Mailer, either for the HTTP server, or
before "use CGI::Debug" in a BEGIN block.

The idea is to specify an email address that will be used if anybody
besides yourself is getting an error. You will not get your own
errors as email if you overide that action with a control cookie.

=head2 header control

  Cookie / ENV: CGI-Debug-header=control

  Import: header => 'control'

Controls that the HTTP-header is correct.

This control will follow the HTTP RFC to the point. It reports if the
header is ok, if the content-type is text/html, and the length of the
HTTP-body. That information will be used by other parts of
CGI::Debug.  This is done by redirecting STDOUT to a temporary file.
This is the only control that must be set in the beginning of the
program.  All other controls can be changed during before the end of
the program.

=head2 header ignore

  Cookie / ENV: CGI-Debug-header=ignore

  Import: header => 'ignore'

Assume that the HTTP-header is correct and specifies text/html.

This will tell CGI::Debug to ignore the STDOUT. A server generated
error response will result if the program compile ok but does not
produce a valid HTTP-header.

=head2 header minimal

  Cookie / ENV: CGI-Debug-header=minimal

  Import: header => 'minimal'

Generates a simple text/html HTTP-header for you.

This is the only action that CHANGES THE BEHAVIOUR of your program.
You will have to insert your own header if you remove the CGI::Debug
row. But this action will guarantee that you have a valid header,
without the need to save STDOUT to a temporary file.

=head2 set param_length

  Cookie / ENV: CGI-Debug-set-param_length=value

  Import: set => { param_length => 'value', ... }

Set the max length of the parameter values.

The default length is 60 chars. This is used for query parameters,
cookies and environment. The purpose is to give you a table that looks
good.

=head2 set error_document

  Cookie / ENV: CGI-Debug-set-error_document=value

  Import: set => { error_document => 'value', ... }

Set what page to redirect to if there was an error report, not sent to
browser.

This will show up in the browser if the error is going somewhere
else.  If no page is specified, a short generic CGI error response
will show up. But if the CGI program succeeded in printing a valid
http header and something in the body, that will be showed instead,

README  view on Meta::CPAN

works, you can just remove the line.

It's highly configurable. Choose what functions to use.

 Report
 o  warnings
 o  runtime errors
 o  compilation errors
 o  faulty HTTP headers
 o  Form data
 o  Cookies
 o  Enviroment
 o  Elapsed time in subseconds

 Report
 o  to Browser
 o  to error log
 o  to file
 o  as mail to owner and/or others

 Report

t/control.t  view on Meta::CPAN

----------
game    =   5[ch]...
game    =   8[ch]...
weather =   4[du]...\n\n";
$params_l3 = "
Parameters
----------
game    =   5[che]...
game    =   8[che]...
weather =   4[dul]...\n\n";
$cookies = "\nCookies\n-------\n\n";
$enviroment = "
Environment
-----------
PATH_INFO       =  15[/somewhere/else]
PATH_TRANSLATED =  25[/usr/local/somewhere/else]
QUERY_STRING    =  37[game=chess&game=checkers&weather=dull]
REQUEST_METHOD  =   3[GET]
SCRIPT_NAME     =  16[/cgi-bin/foo.cgi]
SERVER_NAME     =  26[the.good.ship.lollypop.com]
SERVER_PORT     =   4[8080]



( run in 1.084 second using v1.01-cache-2.11-cpan-e9199f4ba4c )