From bcfde177dbb9f3748f59af067357e5902335ca46 Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Thu, 14 Jul 2005 13:01:34 +0000 Subject: Bug 283989: CGI.pl global init code should be moved to Bugzilla::CGI Patch By Max Kanat-Alexander r=wurblzap, a=justdave --- Bugzilla/Util.pm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Bugzilla/Util.pm') diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 83c9bf7d3..1ac25d1aa 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -33,6 +33,7 @@ use base qw(Exporter); detaint_signed html_quote url_quote value_quote xml_quote css_class_quote + i_am_cgi lsearch max min diff_arrays diff_strings trim wrap_comment find_wrap_point @@ -130,6 +131,12 @@ sub xml_quote { return $var; } +sub i_am_cgi () { + # I use SERVER_SOFTWARE because it's required to be + # defined for all requests in the CGI spec. + return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0; +} + sub lsearch { my ($list,$item) = (@_); my $count = 0; @@ -376,6 +383,9 @@ Bugzilla::Util - Generic utility functions for bugzilla value_quote($var); xml_quote($var); + # Functions that tell you about your environment + my $is_cgi = i_am_cgi(); + # Functions for searching $loc = lsearch(\@arr, $val); $val = max($a, $b, $c); @@ -480,6 +490,12 @@ This is similar to C, except that ' is escaped to '. This is kept separate from html_quote partly for compatibility with previous code (for ') and partly for future handling of non-ASCII characters. +=item C + +Tells you whether or not you are being run as a CGI script in a web +server. For example, it would return false if the caller is running +in a command-line script. + =back =head2 Searching -- cgit v1.2.3-24-g4f1b