Daniel Ringwalt
2007-11-28 02:57:52 UTC
This patch to HTML/Mason/FakeApache.pm:
1. has a working unparsed_uri()
2. has uri() and unparsed_uri() return the same value they would under
Apache::RequestRec
3. has a working filename()
for Mason components running under HTML::Mason::CGIHandler.
--- orig/FakeApache.pm
+++ new/FakeApache.pm
@@ -13,6 +13,7 @@
# In the future we'll probably want to switch this to Apache::Fake or similar
use HTML::Mason::MethodMaker(read_write => [qw(query)]);
+use HTML::Mason::Tools 'taint_is_on';
sub new {
my $class = shift;
@@ -75,11 +76,27 @@
sub uri {
my $self = shift;
- $self->{uri} ||= $self->{query}->script_name . $self->path_info || '';
+ return $self->{uri} if $self->{uri};
+ if (taint_is_on()) {
+ return $self->{query}->path_info();
+ }
+ $self->{uri} = $ENV{SCRIPT_URL};
}
-# Is this available in CGI?
-# sub filename {}
+sub unparsed_uri {
+ my $self = shift;
+
+ return $self->{unparsed_uri} if $self->{unparsed_uri};
+ if (taint_is_on()) {
+ return( $self->{unparsed_uri} = $self->uri . ($self->{query}
+ ->query_string and '?' . $self->{query}->query_string) );
+ }
+ $self->{unparsed_uri} = $ENV{REQUEST_URI};
+}
+
+sub filename {
+ $_[0]->{path_translated} ||= $_[0]->{query}->path_translated();
+}
# "The $r->location method will return the path of the
# <Location> section from which the current "Perl*Handler"
1. has a working unparsed_uri()
2. has uri() and unparsed_uri() return the same value they would under
Apache::RequestRec
3. has a working filename()
for Mason components running under HTML::Mason::CGIHandler.
--- orig/FakeApache.pm
+++ new/FakeApache.pm
@@ -13,6 +13,7 @@
# In the future we'll probably want to switch this to Apache::Fake or similar
use HTML::Mason::MethodMaker(read_write => [qw(query)]);
+use HTML::Mason::Tools 'taint_is_on';
sub new {
my $class = shift;
@@ -75,11 +76,27 @@
sub uri {
my $self = shift;
- $self->{uri} ||= $self->{query}->script_name . $self->path_info || '';
+ return $self->{uri} if $self->{uri};
+ if (taint_is_on()) {
+ return $self->{query}->path_info();
+ }
+ $self->{uri} = $ENV{SCRIPT_URL};
}
-# Is this available in CGI?
-# sub filename {}
+sub unparsed_uri {
+ my $self = shift;
+
+ return $self->{unparsed_uri} if $self->{unparsed_uri};
+ if (taint_is_on()) {
+ return( $self->{unparsed_uri} = $self->uri . ($self->{query}
+ ->query_string and '?' . $self->{query}->query_string) );
+ }
+ $self->{unparsed_uri} = $ENV{REQUEST_URI};
+}
+
+sub filename {
+ $_[0]->{path_translated} ||= $_[0]->{query}->path_translated();
+}
# "The $r->location method will return the path of the
# <Location> section from which the current "Perl*Handler"