=cut
###----------------------------------------------------------------###
-# Copyright 2007 - Paul Seamons #
+# Copyright 2003-2012 - Paul Seamons #
# Distributed under the Perl Artistic License without warranty #
###----------------------------------------------------------------###
use base qw(Exporter);
BEGIN {
- $VERSION = '2.11';
+ $VERSION = '2.37';
$PREFERRED_CGI_MODULE ||= 'CGI';
@EXPORT = ();
@EXPORT_OK = qw(get_form
my $val = $form->{$key};
$key =~ s/([^\w.\-\ ])/sprintf('%%%02X', ord $1)/eg;
$key =~ y/ /+/;
- foreach (ref($val) ? @$val : $val) {
+ foreach (ref($val) eq 'ARRAY' ? @$val : $val) {
my $_val = $_; # make a copy
$_val =~ s/([^\w.\-\ ])/sprintf('%%%02X', ord $1)/eg;
$_val =~ y/ /+/;
my %hash = ();
foreach my $key ($obj->cookie) {
my @val = $obj->cookie($key);
- $hash{$key} = ($#val == -1) ? next : ($#val == 0) ? $val[0] : \@val;
+ $hash{$key} = ($#val == -1) ? "" : ($#val == 0) ? $val[0] : \@val;
}
return $self->{'cookies'} = \%hash;
}
# 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) {
} else {
$type = 'text/html';
}
+ $type .= "; charset=$charset" if $charset && $charset =~ m|^[\w\-\.\:\+]+$|;
if (my $r = $self->apache_request) {
return if $r->bytes_sent;
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];
}
}
### 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;
header. Trying to print -E<gt>content_type is an error. For clarity,
the method -E<gt>print_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<-E<gt>set_cookie>
Arguments are the same as those to CGI->new->cookie({}).
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<-E<gt>swap_template>
This is intended as a simple yet strong subroutine to swap
See also L<CGI::Ex::Validate>.
-=head1 AUTHOR
-
-Paul Seamons
-
=head1 LICENSE
This module may be distributed under the same terms as Perl itself.
+=head1 AUTHOR
+
+Paul Seamons <perl at seamons dot com>
+
=cut