P4CGI.html #1

  • //
  • guest/
  • jay_han/
  • perforce/
  • utils/
  • p4db/
  • P4DB_2.01/
  • P4CGI.html
  • View
  • Commits
  • Open Download .zip Download (14 KB)
<HTML>
<HEAD>
<TITLE>P4CGI - Support for CGI's that interface p4. Written specifically for P4DB</TITLE>
<LINK REV="made" HREF="mailto:feedback@suse.de">
</HEAD>

<BODY>

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SUBROUTINES">SUBROUTINES</A>
	<UL>

		<LI><A HREF="#cgi">cgi</A>
		<LI><A HREF="#p4call">p4call</A>
		<LI><A HREF="#p4readform">p4readform</A>
		<LI><A HREF="#start_page">start_page</A>
		<LI><A HREF="#end_page">end_page</A>
		<LI><A HREF="#bail">bail</A>
		<LI><A HREF="#signalError">signalError</A>
		<LI><A HREF="#start_table">start_table</A>
		<LI><A HREF="#end_table">end_table</A>
		<LI><A HREF="#table_row">table_row</A>
		<LI><A HREF="#table_header">table_header</A>
		<LI><A HREF="#ul_list">ul_list</A>
		<LI><A HREF="#dl_list">dl_list</A>
		<LI><A HREF="#fixSpecChar">fixSpecChar</A>
		<LI><A HREF="#rmTabs">rmTabs</A>
		<LI><A HREF="#ahref">ahref</A>
		<LI><A HREF="#image">image</A>
		<LI><A HREF="#magic">magic</A>
		<LI><A HREF="#fixspaces">fixspaces</A>
	</UL>

</UL>
<!-- INDEX END -->

<HR>
<P>
<H1><A NAME="NAME">NAME</A></H1>
<P>
P4CGI - Support for CGI's that interface p4. Written specifically for P4DB

<P>
<HR>
<H1><A NAME="SUBROUTINES">SUBROUTINES</A></H1>
<P>
<HR>
<H2><A NAME="cgi">cgi</A></H2>
<P>
<CODE>&amp;P4CGI::cgi()</CODE>



<P>
Return CGI reference 

<P>
Example:

<P>
<PRE>    my $file = P4CGI::cgi()-&gt;param(&quot;file&quot;) ;
    print &quot;File parameter value: $file\n&quot; ;
</PRE>
<P>
<HR>
<H2><A NAME="p4call">p4call</A></H2>
<P>
<CODE>&amp;P4CGI::p4call(</CODE><STRONG>result</STRONG><CODE>,</CODE><STRONG>command</STRONG><CODE>)</CODE>



<P>
Request data from p4. Calls p4 with command <STRONG>command</STRONG> and returns data in <STRONG>result</STRONG>.

<P>
This function is really three different functions depeding in the type of
the
<STRONG>result</STRONG> parameter.

<DL>
<DT><STRONG><A NAME="item_result">result</A></STRONG><DD>
<P>
This parameter can be of three different types:

<DL>
<DT><STRONG><A NAME="item_Filehandle">Filehandle (typeglob)</A></STRONG><DD>
<P>
Data from command can be read from filehandle. NOTE! File must be closed by
caller.

<DT><STRONG><A NAME="item_Reference">Reference to array</A></STRONG><DD>
<P>
Returns result from command into array (newlines stripped)

<DT><STRONG>Reference to scalar</STRONG><DD>
<P>
Returns result from command into scalar. (lines separated by newline)

</DL>
<P>
Any other type of parameter will abort operation

<DT><STRONG><A NAME="item_command">command</A></STRONG><DD>
<P>
Command to send to p4 command line client.

</DL>
<P>
Example:

<P>
<PRE>    my $d ;
    &amp;P4CGI::p4call(\$d,&quot;changes -m 1&quot;) ;
    $d =~ /Change (\d+)/ or &amp;bail(&quot;No contact with P4 server&quot;) ;
    $lastChange=$1 ;    
</PRE>
<P>
<HR>
<H2><A NAME="p4readform">p4readform</A></H2>
<P>
<CODE>&amp;P4CGI::p4readform(</CODE><STRONG>command</STRONG>,<STRONG>resulthash</STRONG><CODE>)</CODE>



<P>
Reads output from a P4 command and assumes the data is a form (e.g.
``client -o'').

<P>
The form is stored in a hash and the function returns an array containing
all field names in the order they appeared. The hash will contain the field
names as key and field values as data.

<DL>
<DT><STRONG>command</STRONG><DD>
<P>
Command to send to p4 command line client.

<DT><STRONG><A NAME="item_resulthash">resulthash</A></STRONG><DD>
<P>
Reference to a hash to receive reults

</DL>
<P>
Example:

<P>
<PRE>    my %fields ;
    my @fields = &amp;P4CGI::p4readforml(&quot;client -o&quot;,\%fields) ;
    my $f ;
    foreach $f (@fields) {
        print &quot;field $f: $fields{$f}\n&quot; ;
    }
</PRE>
<P>
<HR>
<H2><A NAME="start_page">start_page</A></H2>
<P>
<CODE>&amp;P4CGI::start_page(</CODE><STRONG>title</STRONG>[<CODE>,</CODE><STRONG>legend</STRONG>]<CODE>)</CODE>



<P>
Start a page. Print http header and first part of HTML.

<DL>
<DT><STRONG><A NAME="item_title">title</A></STRONG><DD>
<P>
Title of page

<DT><STRONG><A NAME="item_legend">legend (Optional)</A></STRONG><DD>
<P>
Short help text to be displayed at top of page

</DL>
<P>
Example:

<P>
<PRE> my $start = P4CGI::start_page(&quot;Title of page&quot;,
                               &amp;P4CGI::dl_list(&quot;This&quot;,&quot;Goto this&quot;,
                                               &quot;That&quot;,&quot;Goto that&quot;)) ;
 print $start ;
</PRE>
<P>
<HR>
<H2><A NAME="end_page">end_page</A></H2>
<P>
<CODE>&amp;P4CGI::end_page()</CODE>



<P>
End a page. Print HTML trailer.

<P>
Example:

<P>
<PRE> print P4CGI::end_page() ;
</PRE>
<P>
<HR>
<H2><A NAME="bail">bail</A></H2>
<P>
<CODE>&amp;P4CGI::bail(</CODE><STRONG>message</STRONG><CODE>)</CODE>



<P>
Report an error. This routine will emit HTML code for an error message,
print the error log and exit.

<P>
This rouine is intended to report internal errors in the code (much like
<CODE>assert(3)</CODE> in c). 

<DL>
<DT><STRONG><A NAME="item_message">message
Message that will be displayed to user</A></STRONG><DD>
</DL>
<P>
Example:

<P>
<PRE> unless(defined $must_be_defined) { 
     &amp;P4CGI::bail(&quot;was not defined&quot;) ; 
 } ;
</PRE>
<P>
<HR>
<H2><A NAME="signalError">signalError</A></H2>
<P>
<CODE>&amp;P4CGI::signalError(</CODE><STRONG>message</STRONG><CODE>)</CODE>



<P>
Report an operator error in a reasonable fashion. SignalError can be called
before or after <CODE>start_page()</CODE> but if it is called before
<CODE>start_page()</CODE> a ``default'' page header will appear. It is
recommended to call <CODE>signalError()</CODE> after
<CODE>start_page()</CODE> to make it more obvious to the operator what the
problem was.

<DL>
<DT><STRONG>message
Message that will be displayed to user</STRONG><DD>
</DL>
<P>
Example:

<P>
<PRE> unless(defined $must_be_defined) { 
     &amp;P4CGI::signalError(&quot;was not defined&quot;) ; 
 } ;
</PRE>
<P>
<HR>
<H2><A NAME="start_table">start_table</A></H2>
<P>
<CODE>&amp;P4CGI::start_table(</CODE><STRONG>table_attribute_text</STRONG><CODE>)</CODE>



<P>
Start a table with optional table attributes

<DL>
<DT><STRONG><A NAME="item_table_attribute_text">table_attribute_text</A></STRONG><DD>
<P>
This text will be inserted as attributes to table tag

</DL>
<P>
Example:

<P>
<PRE>    print P4CGI::start_table(&quot;align=center border&quot;) ;
</PRE>
<P>
<HR>
<H2><A NAME="end_table">end_table</A></H2>
<P>
<CODE>&amp;P4CGI::end_table()</CODE>



<P>
Return end of table string. (trivial function included mostly for symmetry)

<P>
<HR>
<H2><A NAME="table_row">table_row</A></H2>
<P>
<CODE>&amp;P4CGI::table_row(</CODE><STRONG>options</STRONG><CODE>,</CODE><STRONG>listOfValues</STRONG><CODE>)</CODE>



<P>
Insert a row in table.

<DL>
<DT><STRONG><A NAME="item_options">options</A></STRONG><DD>
<P>
A list of key/value pairs (a hash will do just fine) containing options for
the row. 

<P>
The key must start with a ``-''.

<P>
Most key/value pairs are treated as attributes to the &lt;TR&gt;-tag. The
following keys are recognized as special:

<DL>
<DT><STRONG><A NAME="item__type">-type</A></STRONG><DD>
<P>
Type of cells. Default is &lt;TD&gt;-type. 

<DT><STRONG><A NAME="item__anykey">-anykey</A></STRONG><DD>
<P>
<EM>anykey</EM> will be assumed to be a row option and will be inserted in the TR-tag. The
value for the option is the key value, unless value is empty or undefined,
in which case the option anykey is assumed to have no value.

</DL>
<DT><STRONG><A NAME="item_listOfValues">listOfValues</A></STRONG><DD>
<P>
Row data. Remaining values are assumed to be data for each cell. The data
is typically the text in the cell but can also be:

<DL>
<DT><STRONG><A NAME="item_undef">undef</A></STRONG><DD>
<P>
An undefined value indicates that the next cell spans more than one column. 

<DT><STRONG>Reference to a hash</STRONG><DD>
<P>
The hash contains two keys: ``-text'' for cell text and ``-type'' for cell
type. All other key/value pairs are treated as attributes to the &lt;TD&gt;
or &lt;TH&gt; tag.

</DL>
</DL>
<P>
Example:

<P>
<PRE> print P4CGI::start_table(&quot;align=center&quot;) ;
                                   ### print header row
 print P4CGI::table_row(-type   =&gt; &quot;th&quot;,
                        -valign =&gt; &quot;top&quot;,
                        -align  =&gt; &quot;left&quot;,
                        &quot;Heading 1&quot;,&quot;Heading 2&quot;,undef,&quot;Heading 3&quot;) ;
                                   ### print data
 my %h = (-text    =&gt; &quot;text in hash&quot;, 
          -bgcolor =&gt; &quot;blue&quot;) ;
 print P4CGI::table_row(-valign  =&gt; &quot;top&quot;,
                        -bgcolor =&gt; &quot;white&quot;,
                        &quot;Cell 1&quot;,
                        {-text    =&gt; &quot;Cell 2&quot;,
                         -bgcolor =&gt; &quot;red&quot;},
                        \%h,
                        &quot;Cell 3-2&quot;) ;
 print P4CGI::end_table() ;
</PRE>
<P>
<HR>
<H2><A NAME="table_header">table_header</A></H2>
<P>
<CODE>&amp;P4CGI::table_header(</CODE><STRONG>list of label/hint</STRONG><CODE>)</CODE>



<P>
Create a table header row with a a description and an optional hint for
each column. 

<DL>
<DT><STRONG><A NAME="item_list">list of label/hint</A></STRONG><DD>
<P>
A list of column labels optionally followed by a '/' and a hint.

</DL>
<P>
Example:

<P>
<PRE> print P4CGI::start_table(&quot;align=center&quot;) ;
                                   ### print header row
 print P4CGI::table_header(&quot;File/click for story&quot;,&quot;Revision/click to view&quot;) ;
                                   ### print data
 my %h = (-text    =&gt; &quot;text in hash&quot;, 
          -bgcolor =&gt; &quot;blue&quot;) ;
 print P4CGI::table_row(-valign  =&gt; &quot;top&quot;,
                        -bgcolor =&gt; &quot;white&quot;,
                        &quot;Cell 1&quot;,
                        {-text    =&gt; &quot;Cell 2&quot;,
                         -bgcolor =&gt; &quot;red&quot;},
                        \%h,
                        &quot;Cell 3-2&quot;) ;
 print P4CGI::end_table() ;
</PRE>
<P>
<HR>
<H2><A NAME="ul_list">ul_list</A></H2>
<P>
<CODE>&amp;P4CGI::ul_list(</CODE><STRONG>list</STRONG><CODE>)</CODE>



<P>
Return a bulleted list.

<DL>
<DT><STRONG>list</STRONG><DD>
<P>
Lits of data to print as bulleted list

</DL>
<P>
Example:

<P>
<PRE> print P4CGI::ul_list(&quot;This&quot;,&quot;is&quot;,&quot;a&quot;,&quot;bulleted&quot;,&quot;list&quot;) ;
</PRE>
<P>
<HR>
<H2><A NAME="dl_list">dl_list</A></H2>
<P>
<CODE>&amp;P4CGI::dl_list(</CODE><STRONG>list_of_pairs</STRONG><CODE>)</CODE>



<P>
Returns a definition list.

<DL>
<DT><STRONG><A NAME="item_list_of_pairs">list_of_pairs</A></STRONG><DD>
<P>
List of data pairs to print as a definition list. A hash will do just fine,
only you have no control over the order in the list. 

</DL>
<P>
Example:

<P>
<PRE> print P4CGI::dl_list(&quot;This&quot;,&quot;Description of this&quot;,
                      &quot;That&quot;,&quot;Description of that&quot;) ;
</PRE>
<P>
<HR>
<H2><A NAME="fixSpecChar">fixSpecChar</A></H2>
<P>
<CODE>&amp;P4CGI::fixSpecChar(</CODE><STRONG>str</STRONG><CODE>)</CODE>



<P>
Convert all '&gt;' to ``<CODE>&amp;gt;</CODE>'', '&lt;' to ``<CODE>&amp;lt;</CODE>'' and '&amp;' to ``<CODE>&amp;amp;</CODE>''.

<DL>
<DT><STRONG><A NAME="item_str">str</A></STRONG><DD>
<P>
String to convert

</DL>
<P>
Example:

<P>
<PRE>    my $cvstr = &amp;P4CGI::fixSpecChar(&quot;String containing &lt;,&gt; and &amp;&quot;) ;
</PRE>
<P>
<HR>
<H2><A NAME="rmTabs">rmTabs</A></H2>
<P>
<CODE>&amp;P4CGI::rmTabs(</CODE><STRONG>str</STRONG><CODE>)</CODE>



<P>
Returns <STRONG>str</STRONG> with all tabs converted to spaces

<DL>
<DT><STRONG>str</STRONG><DD>
<P>
String to convert

</DL>
<P>
<HR>
<H2><A NAME="ahref">ahref</A></H2>
<P>
<CODE>&amp;P4CGI::ahref(</CODE><STRONG>options</STRONG><CODE>,</CODE><STRONG>parameters</STRONG><CODE>,</CODE><STRONG>text</STRONG><CODE>)</CODE>



<P>
Returns a &lt;A HREF...&gt;...&lt;/A&gt; tag pair.

<DL>
<DT><STRONG>options</STRONG><DD>
<P>
Optional list of option-value pairs. Valid options are:

<DL>
<DT><STRONG><A NAME="item__url">-url</A></STRONG><DD>
<P>
Url for link. Default is current.

<DT><STRONG><A NAME="item__anchor">-anchor</A></STRONG><DD>
<P>
Anchor in url. Default is none.

</DL>
<P>
Any non-valid option marks the end of the options

<DT><STRONG><A NAME="item_parameters">parameters</A></STRONG><DD>
<P>
Optional list of parameters for link.

<DT><STRONG><A NAME="item_text">text</A></STRONG><DD>
<P>
The last parameter is used as text for link. 

</DL>
<P>
Example:

<P>
<PRE>    print &amp;P4CGI::ahref(&quot;Back to myself&quot;) ; # link to this. No parameters.
</PRE>
<P>
<PRE>    print &amp;P4CGI::ahref(&quot;-url&quot;,&quot;www.perforce.com&quot;,
                        &quot;To perforce&quot;) ; # link to perforce
</PRE>
<P>
<PRE>    print &amp;P4CGI::ahref(&quot;-anchor&quot;,&quot;THERE&quot;,
                        &quot;Go there&quot;) ; # link to anchor THERE
</PRE>
<P>
<PRE>    print &amp;P4CGI::ahref(&quot;-url&quot;,&quot;changeList.cgi&quot;,
                        &quot;FSPC=//.../doc/...&quot;,
                        &quot;Changes for all documentation&quot;) ; # url with parameter
</PRE>
<P>
<HR>
<H2><A NAME="image">image</A></H2>
<P>
<CODE>&amp;P4CGI::image(</CODE><STRONG>image</STRONG>[<CODE>,</CODE><STRONG>text</STRONG>]<CODE>)</CODE>



<P>
Returns &lt;IMG&gt;-tag

<P>
Example:

<P>
<PRE>    &amp;P4CGI::image(&quot;picture.gif&quot;,&quot;Picture Here&quot;) ;
</PRE>
<P>
<HR>
<H2><A NAME="magic">magic</A></H2>
<P>
<CODE>&amp;P4CGI::magic(</CODE><STRONG>text</STRONG><CODE>)</CODE>



<P>
Returns <STRONG>text</STRONG> with some magic ``patterns'' substituted with links.

<P>
Currently the pattern ``change <EM>number</EM>'' (and some variants) is replaced with a link to the change browser.

<P>
Example:

<P>
<PRE>    my $t = &quot;Integrated change 4711 to this codeline&quot; ;
</PRE>
<P>
<PRE>    print &amp;P4CGI::magic($t) ; # inserts a link to change 4711
</PRE>
<P>
<HR>
<H2><A NAME="fixspaces">fixspaces</A></H2>
<P>
<CODE>&amp;P4CGI::fixspaces(</CODE><STRONG>text</STRONG><CODE>)</CODE>



<P>
Returns <STRONG>text</STRONG> with characters like space substituted with ``%&lt;ASCII value&gt;''.

<P>
Example:

<P>
<PRE>    my $t = &quot;/File with spaces&quot; ;
</PRE>
<P>
<PRE>    print &amp;P4CGI::fixspaces($t) ; # prints: /File%20with%20spaces
</PRE>
</BODY>

</HTML>
# Change User Description Committed
#1 2778 Jay Han creating guest branch per tutorial http://public.perforce.com/public/tutorial.html
//guest/perforce_software/utils/p4db/P4DB_2.01/P4CGI.html
#1 1884 rmg Update to the current (2.01) P4DB.