| 1 | package CGI::Application::Plugin::Apache::Request; | ||
| 2 | use strict; | ||
| 3 | use HTML::GenerateUtil; | ||
| 4 | use base 'Apache::Request'; | ||
| 5 | use Apache::Request; | ||
| 6 | use Apache::Cookie; | ||
| 7 | use Apache::URI; | ||
| 8 | |||
| 9 | sub new { | ||
| 10 | my($class, @args) = @_; | ||
| 11 | return bless $class->SUPER::new(@args), $class; | ||
| 12 | } | ||
| 13 | |||
| 14 | =pod | ||
| 15 | |||
| 16 | =head1 NAME | ||
| 17 | |||
| 18 | CGI::Application::Plugin::Apache::Request | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | This package is just a wrapper around Apache::Request to add L<CGI.pm|CGI> compatible | ||
| 23 | methods. The interface and usage is exactly the same as L<CGI.pm|CGI>. | ||
| 24 | |||
| 25 | =over 8 | ||
| 26 | |||
| 27 | =item delete() | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub delete { | ||
| 32 | my ($self, @args) = @_; | ||
| 33 | my $table = $self->parms(); | ||
| 34 | foreach my $arg (@args) { | ||
| 35 | delete $table->{$arg}; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | =item delete_all() | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | sub delete_all { | ||
| 44 | my $self = shift; | ||
| 45 | my $table = $self->parms(); | ||
| 46 | my @args = keys %$table; | ||
| 47 | foreach my $arg (@args) { | ||
| 48 | delete $table->{$arg}; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | =item cookie() | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | sub cookie { | ||
| 57 | my ($self, @args) = @_; | ||
| 58 | if($#args == 0) { | ||
| 59 | # if we just have a name of a cookie then retrieve the value of the cookie | ||
| 60 | my $cookies = Apache::Cookie->fetch(); | ||
| 61 | if( $cookies && $cookies->{$args[0]} ) { | ||
| 62 | return $cookies->{$args[0]}->value; | ||
| 63 | } else { | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | } else { | ||
| 67 | # else we have several values so try and create a new cookie | ||
| 68 | return Apache::Cookie->new($self, @args); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | =item Dump() | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | sub Dump { | ||
| 77 | my $self = shift; | ||
| 78 | my($param,$value,@result); | ||
| 79 | return '<ul></ul>' unless $self->param; | ||
| 80 | push(@result,"<ul>"); | ||
| 81 | foreach $param ($self->param) { | ||
| 82 | my $name = $self->escapeHTML($param); | ||
| 83 | push(@result,"<li><strong>$name</strong></li>"); | ||
| 84 | push(@result,"<ul>"); | ||
| 85 | foreach $value ($self->param($param)) { | ||
| 86 | $value = $self->escapeHTML($value); | ||
| 87 | push(@result,"<li>$value</li>"); | ||
| 88 | } | ||
| 89 | push(@result,"</ul>"); | ||
| 90 | } | ||
| 91 | push(@result,"</ul>"); | ||
| 92 | return join("\n",@result); | ||
| 93 | } | ||
| 94 | |||
| 95 | =item Vars() | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | sub Vars { | ||
| 100 | my $self = shift; | ||
| 101 | my @params = $self->param(); | ||
| 102 | my %Vars = (); | ||
| 103 | foreach my $param (@params) { | ||
| 104 | my @values = $self->param($param); | ||
| 105 | if( scalar @values == 1 ) { | ||
| 106 | $Vars{$param} = $values[0]; | ||
| 107 | } else { | ||
| 108 | $Vars{$param} = \@values; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | if(wantarray) { | ||
| 113 | return %Vars; | ||
| 114 | } else { | ||
| 115 | return \%Vars; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | =item escapeHTML() | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | sub escapeHTML { | ||
| 124 | my ($self, $value) = @_; | ||
| 125 | $value = HTML::GenerateUtil::escape_html($value, | ||
| 126 | ( | ||
| 127 | $HTML::GenerateUtil::EH_LFTOBR | ||
| 128 | | $HTML::GenerateUtil::EH_SPTONBSP | ||
| 129 | | $HTML::GenerateUtil::EH_LEAVEKNOWN | ||
| 130 | ) | ||
| 131 | ); | ||
| 132 | return $value; | ||
| 133 | } | ||
| 134 | |||
| 135 | =item upload() | ||
| 136 | |||
| 137 | =cut | ||
| 138 | |||
| 139 | sub upload { | ||
| 140 | my ($self, $file) = @_; | ||
| 141 | # if they want a specific one, then lets give them the file handle | ||
| 142 | if( $file ) { | ||
| 143 | my $upload = $self->SUPER::upload($file); | ||
| 144 | if( $upload ) { | ||
| 145 | return $upload->fh(); | ||
| 146 | } else { | ||
| 147 | return; | ||
| 148 | } | ||
| 149 | # else they want them all | ||
| 150 | } else { | ||
| 151 | my @files = $self->SUPER::upload(); | ||
| 152 | @files = map { $self->SUPER::upload($_)->fh() } @files; | ||
| 153 | return @files; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | 1; | ||
| 158 | |||
| 159 | __END__ |