X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCGI%2FEx.pm;h=09e5139d26ac82b9fdd7b868506ed31ff7980a03;hb=febed4ec71f803b083c3e61b82b9464e9bfb0992;hp=8c5e6b07ba79d01e6264fd760ad70b7b2f900794;hpb=8abbacc82b52f460bef67c1923ae98873a95e123;p=chaz%2Fp5-CGI-Ex diff --git a/lib/CGI/Ex.pm b/lib/CGI/Ex.pm index 8c5e6b0..09e5139 100644 --- a/lib/CGI/Ex.pm +++ b/lib/CGI/Ex.pm @@ -24,7 +24,7 @@ use vars qw($VERSION use base qw(Exporter); BEGIN { - $VERSION = '2.08'; + $VERSION = '2.27'; $PREFERRED_CGI_MODULE ||= 'CGI'; @EXPORT = (); @EXPORT_OK = qw(get_form @@ -249,7 +249,7 @@ sub content_type { &print_content_type } # print_content_type(); # print_content_type('text/plain); sub print_content_type { - my ($self, $type) = ($#_ >= 1) ? @_ : ref($_[0]) ? (shift, undef) : (undef, shift); + my ($self, $type, $charset) = (@_ && ref $_[0]) ? @_ : (undef, @_); $self = __PACKAGE__->new if ! $self; if ($type) { @@ -257,6 +257,7 @@ sub print_content_type { } else { $type = 'text/html'; } + $type .= "; charset=$charset" if $charset && $charset =~ m|^[\w\-\.\:\+]+$|; if (my $r = $self->apache_request) { return if $r->bytes_sent; @@ -416,7 +417,7 @@ sub time_calc { return time + ($m->{lc($3)} || 1) * "$1$2"; } else { my @stat = stat $time; - die "Could not find file \"$time\" for time_calc" if $#stat == -1; + die "Could not find file \"$time\" for time_calc. You should pass one of \"now\", time(), \"[+-] \\d+ [smhdwMy]\" or a filename." if $#stat == -1; return $stat[9]; } } @@ -440,7 +441,9 @@ sub send_status { $r->send_http_header; $r->print($mesg); } else { - # not sure of best way to send the message in MP2 + $r->content_type('text/html'); + $r->print($mesg); + $r->rflush; } } else { print "Status: $code\r\n"; @@ -483,7 +486,7 @@ sub print_js { ### get file info my $stat; - if ($js_file && $js_file =~ m|^(\w+(?:/+\w+)*\.js)$|i) { + if ($js_file && $js_file =~ m|^/*(\w+(?:/+\w+)*\.js)$|i) { foreach my $path (@INC) { my $_file = "$path/$1"; next if ! -f $_file; @@ -918,6 +921,14 @@ else already printed content-type). Calling this sends the Content-type header. Trying to print -Econtent_type is an error. For clarity, the method -Eprint_content_type is available. + $cgix->print_content_type; + + # OR + $cgix->print_content_type('text/html'); + + # OR + $cgix->print_content_type('text/html', 'utf-8'); + =item C<-Eset_cookie> Arguments are the same as those to CGI->new->cookie({}). @@ -968,6 +979,10 @@ that the javascript will cache. Takes either a full filename, or a shortened name which will be looked for in @INC. (ie /full/path/to/my.js or CGI/Ex/validate.js or CGI::Ex::validate) + #!/usr/bin/perl + use CGI::Ex; + CGI::Ex->print_js($ENV{'PATH_INFO'}); + =item C<-Eswap_template> This is intended as a simple yet strong subroutine to swap @@ -1036,12 +1051,12 @@ See also L. See also L. -=head1 AUTHOR - -Paul Seamons - =head1 LICENSE This module may be distributed under the same terms as Perl itself. +=head1 AUTHOR + +Paul Seamons + =cut