.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Test::CGI::Multipart 3pm" .TH Test::CGI::Multipart 3pm "2011-03-13" "perl v5.10.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::CGI::Multipart \- Test posting of multi\-part form data .SH "VERSION" .IX Header "VERSION" This document describes Test::CGI::Multipart version 0.0.3 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Test::CGI::Multipart; \& \& my $tcm = Test::CGI::Multipart; \& \& # specify the form parameters \& $tcm\->set_param(name=\*(Aqemail\*(Aq,value=>\*(Aqjim@hacker.com\*(Aq); \& $tcm\->set_param(name=>\*(Aqpets\*(Aq,value=> [\*(AqRex\*(Aq, \*(AqOscar\*(Aq, \*(AqBidgie\*(Aq, \*(AqFish\*(Aq]); \& $tcm\->set_param(name=>\*(Aqfirst_name\*(Aq,value=>\*(AqJim\*(Aq); \& $tcm\->set_param(name=>\*(Aqlast_name\*(Aq,value=>\*(AqHacker\*(Aq); \& $tcm\->upload_file( \& name=>\*(Aqfile1\*(Aq, \& file=>\*(Aqmade_up_filename.txt\*(Aq, \& value=>$content \& ); \& $tcm\->upload_file( \& name=>\*(Aqfile1\*(Aq, \& file=>\*(Aqmade_up_filename.blah\*(Aq, \& value=>$content_blah, \& type=>\*(Aqapplication/blah\*(Aq \& ); \& \& # Behind the scenes this will fake the browser and web server behaviour \& # with regard to environment variables, MIME format and standard input. \& my $cgi = $tcm\->create_cgi; \& \& # Okay now we have a CGI object which we can pass into the code \& # that needs testing and run the form handling various tests. .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" It is quite difficult to write test code to capture the behaviour of \s-1CGI\s0 or similar objects handling forms that include a file upload. Such code needs to harvest the parameters, build file content in \s-1MIME\s0 format, set the environment variables accordingly and pump it into the the standard input of the required \s-1CGI\s0 object. This module provides simple methods so that having prepared suitable content, the test script can simulate the submission of web forms including file uploads. .PP However we also recognise that a test script is not always the best place to prepare content. Rather a test script would rather specify requirements for a file a upload: type, size, mismatches between the file name and its contents and so on. This module cannot hope to provide such open ended functionality but it can provide extension mechanisms. .PP This module works with \s-1CGI\s0 (the default), CGI::Minimal and CGI::Simple. In principle it ought to work with all equivalent modules however each module has a slightly different interface when it comes to file uploads and so requires slightly different test code. .SH "INTERFACE" .IX Header "INTERFACE" Several of the methods below take named parameters. For convenience we define those parameters here: .ie n .IP """cgi""" 4 .el .IP "\f(CWcgi\fR" 4 .IX Item "cgi" This option defines the \s-1CGI\s0 module. It should be a scalar consisting only of alphanumeric characters and \f(CW\*(C`::\*(C'\fR. It defaults to '\s-1CGI\s0'. .ie n .IP """name""" 4 .el .IP "\f(CWname\fR" 4 .IX Item "name" This is the name of form parameter. It must be a scalar. .ie n .IP """value""" 4 .el .IP "\f(CWvalue\fR" 4 .IX Item "value" This is the value of the form parameter. It should either be a scalar or an array reference of scalars. .ie n .IP """file""" 4 .el .IP "\f(CWfile\fR" 4 .IX Item "file" Where a form parameter represents a file, this is the name of that file. .ie n .IP """type""" 4 .el .IP "\f(CWtype\fR" 4 .IX Item "type" The \s-1MIME\s0 type of the content. This defaults to 'text/plain'. .ie n .IP """ua""" 4 .el .IP "\f(CWua\fR" 4 .IX Item "ua" The \s-1HTTP_USER_AGENT\s0 environment variable. This defaults to 'Test::CGI::Multipart'. .SS "new" .IX Subsection "new" An instance of this class might best be thought of as a \*(L"\s-1CGI\s0 object factory\*(R". The constructor takes no parameters. .SS "create_cgi" .IX Subsection "create_cgi" This returns a \s-1CGI\s0 object created according to the specification encapsulated in the object. The exact mechanics are as follows: .IP "The parameters are packaged up in \s-1MIME\s0 format." 4 .IX Item "The parameters are packaged up in MIME format." .PD 0 .IP "The environment variables are set." 4 .IX Item "The environment variables are set." .IP "A pipe is created. The far end of the pipe is attached to our standard input and the \s-1MIME\s0 content is pushed through the pipe." 4 .IX Item "A pipe is created. The far end of the pipe is attached to our standard input and the MIME content is pushed through the pipe." .IP "The appropriate \s-1CGI\s0 class is required." 4 .IX Item "The appropriate CGI class is required." .IP "Uploads are enabled if the \s-1CGI\s0 class is CGI::Simple." 4 .IX Item "Uploads are enabled if the CGI class is CGI::Simple." .IP "Global variables are reset for \s-1CGI\s0 and CGI::Minimal." 4 .IX Item "Global variables are reset for CGI and CGI::Minimal." .IP "The \s-1CGI\s0 object is created and returned." 4 .IX Item "The CGI object is created and returned." .PD .PP As far as I can see this simulates what happens when a \s-1CGI\s0 script processes a multi-part \s-1POST\s0 form. One can specify a different \s-1CGI\s0 class using the \f(CW\*(C`cgi\*(C'\fR named parameter. One can set the \s-1HTTP_USER_AGENT\s0 environment variable with the \f(CW\*(C`ua\*(C'\fR parameter. .SS "set_param" .IX Subsection "set_param" This can be used to set a single form parameter. It takes two named arguments \f(CW\*(C`name\*(C'\fR and \f(CW\*(C`value\*(C'\fR. Note that this method overrides any previous settings including file uploads. .SS "get_param" .IX Subsection "get_param" This retrieves a single form parameter. It takes a single named parameter: \f(CW\*(C`name\*(C'\fR. The data returned will be a list either of scalar values or (in the case of a file upload) of HASHREFs. The HASHREFs would have the following fields: \f(CW\*(C`file\*(C'\fR, \f(CW\*(C`value\*(C'\fR and \f(CW\*(C`type\*(C'\fR representing the parameter name, the file name, the content and the \s-1MIME\s0 type respectively. .SS "get_names" .IX Subsection "get_names" This returns a list of stashed parameter names. .SS "upload_file" .IX Subsection "upload_file" In the absence of any defined callbacks, this method takes three mandatory named parameters: \f(CW\*(C`name\*(C'\fR, \f(CW\*(C`file\*(C'\fR and \f(CW\*(C`value\*(C'\fR and one optional parameter \&\f(CW\*(C`type\*(C'\fR. If there are any callbacks then the parameters are passed through each of the callbacks and must meet the standard parameter requirements by the time all the callbacks have been called. .PP Unlike the \f(CW\*(C`set_param\*(C'\fR method this will not override previous settings for this parameter but will add. However setting a normal parameter and then an upload on the same name will throw an error. .SS "register_callback" .IX Subsection "register_callback" Callbacks are used by the \f(CW\*(C`upload_file\*(C'\fR method, to allow a file to be specified by properties rather than strict content. This method takes a single named parameter called \f(CW\*(C`callback\*(C'\fR, which adds that callback to an internal array of callbacks. The idea being that the \f(CW\*(C`upload_file\*(C'\fR method can take any arguments you like so long as after all the callbacks have been applied, the parameters consist of \f(CW\*(C`name\*(C'\fR, \f(CW\*(C`file\*(C'\fR, \f(CW\*(C`value\*(C'\fR and possibly \f(CW\*(C`type\*(C'\fR. A callback should take and return a single hash reference. .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" .ie n .IP """unexpected data structure""" 4 .el .IP "\f(CWunexpected data structure\fR" 4 .IX Item "unexpected data structure" During the construction of the \s-1MIME\s0 data, the internal data structure turned out to have unexpected features. Since we control that data structure that should not happen. .ie n .IP """mismatch: is %s a file upload or not""" 4 .el .IP "\f(CWmismatch: is %s a file upload or not\fR" 4 .IX Item "mismatch: is %s a file upload or not" The parameter was being used for both for file upload and normal parameters. .SH "CONFIGURATION AND ENVIRONMENT" .IX Header "CONFIGURATION AND ENVIRONMENT" Test::CGI::Multipart requires no configuration files or environment variables. .PP However it should be noted that the module will overwrite the following environment variables: .IP "\s-1REQUEST_METHOD\s0" 4 .IX Item "REQUEST_METHOD" .PD 0 .IP "\s-1CONTENT_LENGTH\s0" 4 .IX Item "CONTENT_LENGTH" .IP "\s-1CONTENT_TYPE\s0" 4 .IX Item "CONTENT_TYPE" .IP "\s-1HTTP_USER_AGENT\s0" 4 .IX Item "HTTP_USER_AGENT" .PD .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" I would like to get this working with CGI::Lite::Request and Apache::Request if that makes sense. So far I have not managed that. .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" No bugs have been reported. .PP Please report any bugs or feature requests to \&\f(CW\*(C`bug\-test\-cgi\-multipart@rt.cpan.org\*(C'\fR, or through the web interface at . .PP This module depends upon MIME::Tools. Unfortunately that module does not handle newlines quite correctly. That seems to work fine for email but does not work with \s-1CGI\s0. I have looked at MIME::Fast and MIME::Lite but MIME::Tools combined with a hack seems the best that can be done at the moment. Sooner or later someone is going to hit the limitations of that hack. .SH "AUTHOR" .IX Header "AUTHOR" Nicholas Bamber \f(CW\*(C`\*(C'\fR .SH "LICENCE AND COPYRIGHT" .IX Header "LICENCE AND COPYRIGHT" Copyright (c) 2010, Nicholas Bamber \f(CW\*(C`\*(C'\fR. All rights reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. .SH "DISCLAIMER OF WARRANTY" .IX Header "DISCLAIMER OF WARRANTY" \&\s-1BECAUSE\s0 \s-1THIS\s0 \s-1SOFTWARE\s0 \s-1IS\s0 \s-1LICENSED\s0 \s-1FREE\s0 \s-1OF\s0 \s-1CHARGE\s0, \s-1THERE\s0 \s-1IS\s0 \s-1NO\s0 \s-1WARRANTY\s0 \&\s-1FOR\s0 \s-1THE\s0 \s-1SOFTWARE\s0, \s-1TO\s0 \s-1THE\s0 \s-1EXTENT\s0 \s-1PERMITTED\s0 \s-1BY\s0 \s-1APPLICABLE\s0 \s-1LAW\s0. \s-1EXCEPT\s0 \s-1WHEN\s0 \&\s-1OTHERWISE\s0 \s-1STATED\s0 \s-1IN\s0 \s-1WRITING\s0 \s-1THE\s0 \s-1COPYRIGHT\s0 \s-1HOLDERS\s0 \s-1AND/OR\s0 \s-1OTHER\s0 \s-1PARTIES\s0 \&\s-1PROVIDE\s0 \s-1THE\s0 \s-1SOFTWARE\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R" \s-1WITHOUT\s0 \s-1WARRANTY\s0 \s-1OF\s0 \s-1ANY\s0 \s-1KIND\s0, \s-1EITHER\s0 \&\s-1EXPRESSED\s0 \s-1OR\s0 \s-1IMPLIED\s0, \s-1INCLUDING\s0, \s-1BUT\s0 \s-1NOT\s0 \s-1LIMITED\s0 \s-1TO\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