Index: /trunk/t/htdocs/19-filename/two-level.asp =================================================================== --- /trunk/t/htdocs/19-filename/two-level.asp (revision 92) +++ /trunk/t/htdocs/19-filename/two-level.asp (revision 92) @@ -0,0 +1,1 @@ +<% $Response->Include('one-level.asp'); %> Index: /trunk/t/htdocs/19-filename/stringy.asp =================================================================== --- /trunk/t/htdocs/19-filename/stringy.asp (revision 92) +++ /trunk/t/htdocs/19-filename/stringy.asp (revision 92) @@ -0,0 +1,12 @@ +<% + + my $string = " +<\% + use Data::Dumper; + print Data::Dumper->Dump(\[\[\$Response->CurrentFile()\]\],\['got'\]); +\%\> +"; + + $Response->Include(\$string); + +%> Index: /trunk/t/htdocs/19-filename/one-level.asp =================================================================== --- /trunk/t/htdocs/19-filename/one-level.asp (revision 92) +++ /trunk/t/htdocs/19-filename/one-level.asp (revision 92) @@ -0,0 +1,4 @@ +<% #> -*-cperl-*- + use Data::Dumper; + print Data::Dumper->Dump([[$Response->CurrentFile()]],['got']); +%> Index: /trunk/t/19-filename.t =================================================================== --- /trunk/t/19-filename.t (revision 92) +++ /trunk/t/19-filename.t (revision 92) @@ -0,0 +1,51 @@ +# -*-cperl-*- +use strict; +use warnings FATAL => 'all'; + +use Apache::Test qw(); +use Apache::TestRequest qw(GET); + +use lib './t/lib'; +use lib '../t/lib'; +use MungoTestUtils; +use Test::More; +use HTTP::Cookies; +use Time::HiRes qw(gettimeofday); + +$| = 1; + +# 19-filename.t +# Goal: Exercise Mungo's ability to determine the current filename + +my $test_count = 0; +my %tests = ( + 'one-level' => { + label => "One-level", + eval_dump => [ + '/19-filename/one-level.asp', + ], + todo => "", + #hardskip => 1, + }, + 'two-level' => { + label => "Two-level", + eval_dump => [ + '/19-filename/one-level.asp', + '/19-filename/two-level.asp', + ], + todo => "", + #hardskip => 1, + }, + 'stringy' => { + label => "Stringy", + eval_dump => [ + 'ANON', + '/19-filename/stringy.asp', + ], + todo => "", + #hardskip => 1, + } + ); + +perform_page_tests('/19-filename/', \%tests, \$test_count); +done_testing($test_count); Index: /trunk/MANIFEST =================================================================== --- /trunk/MANIFEST (revision 85) +++ /trunk/MANIFEST (revision 92) @@ -123,5 +123,4 @@ t/htdocs/13-errors/compile-use.asp t/htdocs/13-errors/compile-use-source-dump.asp - t/16-cache-compiled.t t/htdocs/16-cache-compiled/echo-compile-time.asp @@ -137,2 +136,6 @@ t/htdocs/18-quiet/bad-use.asp t/htdocs/18-quiet/mungo-error-doc.txt +t/19-filename.t +t/htdocs/19-filename/one-level.asp +t/htdocs/19-filename/two-level.asp +t/htdocs/19-filename/stringy.asp Index: /trunk/lib/Mungo.pm =================================================================== --- /trunk/lib/Mungo.pm (revision 82) +++ /trunk/lib/Mungo.pm (revision 92) @@ -245,5 +245,5 @@ use Apache2::RequestRec; use Apache2::RequestUtil; - use Apache2::Const qw ( OK NOT_FOUND DECLINED ); + use Apache2::Const qw ( OK NOT_FOUND DECLINED SERVER_ERROR); "; if($@) { @@ -428,4 +428,24 @@ } +sub CurrentFile { + my $self = shift; + my @file_stack; + + # Unwind the stack. Each time we hit a package whose name + # begins with Mungo::FilePage, demangle the name and push onto our list. + my $frame_count = 0; + while (my @frame = caller($frame_count)) { + $frame_count++; + my $package = $frame[0]; + if ($package =~ /Mungo::(File|Mem)Page/) { + my $awkwardly_built_string = $self->demangle_name($package . '::__content'); + $awkwardly_built_string =~ s{Mungo::(File|Mem)Page\((.+)\)}{$2}; + push @file_stack, $awkwardly_built_string; + } + } + print STDERR "have file_stack:\n" . Dumper(\@file_stack); + + return wantarray() ? @file_stack : $file_stack[0]; +} # Private? Index: /trunk/lib/Mungo/Response.pm =================================================================== --- /trunk/lib/Mungo/Response.pm (revision 82) +++ /trunk/lib/Mungo/Response.pm (revision 92) @@ -30,4 +30,8 @@ $Response->AddHeader('header_name' => $value); %> + + + <% my $file = $Response->CurrentFile(); %> + @@ -98,4 +102,6 @@ use Mungo::Utils; use HTML::Entities; +use Apache2::Const qw ( OK NOT_FOUND DECLINED SERVER_ERROR); + our $AUTOLOAD; @@ -196,4 +202,19 @@ } +=head2 $file = $Response->CurrentFile(); + +=head2 @nested_files = $Response->CurrentFile(); + +Returns the path on the filesystem from which the currently executing Mungo code originated. In the second form, the call stack is unwound, and all files are returned, with the deepest-nested one first. + +If the Mungo code originated from a string reference rather than a file, the file entry will read 'ANON'. + +=cut + +sub CurrentFile { + my $self = shift; + return $self->{Mungo}->CurrentFile(); +} + =head2 $Response->i18nHandler($coderef); @@ -367,4 +388,7 @@ print '
'.Dumper($@).'
'; } + + # Set response code to 500. Fixes trac16 + $self->{Mungo}->{data}->{ApacheResponseCode} = SERVER_ERROR; }