X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=lib%2FCGI%2FEx.pm;h=bc44ab4ca563d088bcfae39e092417a7a4d53b1b;hp=ed1b511981e607eb439bd267356f843f747a00c4;hb=ed00221d27dfab1e82ec2ea040ab4c399a91c545;hpb=ba92ea5b36cbcd9c03016491dfb06dfc74baf409 diff --git a/lib/CGI/Ex.pm b/lib/CGI/Ex.pm index ed1b511..bc44ab4 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.16'; + $VERSION = '2.24'; $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; @@ -485,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; @@ -920,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({}). @@ -970,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