Changeset 92

Show
Ignore:
Timestamp:
12/21/09 19:57:32 (4 years ago)
Author:
clinton
Message:

Add ability to determine current Mungo file, resolves trac29, tid10892 tid10737

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MANIFEST

    r85 r92  
    123123t/htdocs/13-errors/compile-use.asp 
    124124t/htdocs/13-errors/compile-use-source-dump.asp 
    125  
    126125t/16-cache-compiled.t 
    127126t/htdocs/16-cache-compiled/echo-compile-time.asp 
     
    137136t/htdocs/18-quiet/bad-use.asp 
    138137t/htdocs/18-quiet/mungo-error-doc.txt 
     138t/19-filename.t 
     139t/htdocs/19-filename/one-level.asp 
     140t/htdocs/19-filename/two-level.asp 
     141t/htdocs/19-filename/stringy.asp 
  • trunk/lib/Mungo.pm

    r82 r92  
    245245  use Apache2::RequestRec; 
    246246  use Apache2::RequestUtil; 
    247   use Apache2::Const qw ( OK NOT_FOUND DECLINED ); 
     247  use Apache2::Const qw ( OK NOT_FOUND DECLINED SERVER_ERROR); 
    248248"; 
    249249if($@) { 
     
    428428} 
    429429 
     430sub CurrentFile { 
     431    my $self = shift; 
     432    my @file_stack; 
     433 
     434    # Unwind the stack.  Each time we hit a package whose name 
     435    # begins with Mungo::FilePage, demangle the name and push onto our list. 
     436    my $frame_count = 0; 
     437    while (my @frame = caller($frame_count)) { 
     438        $frame_count++; 
     439        my $package = $frame[0]; 
     440        if ($package =~ /Mungo::(File|Mem)Page/) { 
     441            my $awkwardly_built_string = $self->demangle_name($package . '::__content'); 
     442            $awkwardly_built_string =~ s{Mungo::(File|Mem)Page\((.+)\)}{$2}; 
     443            push @file_stack, $awkwardly_built_string; 
     444        } 
     445    } 
     446    print STDERR "have file_stack:\n" . Dumper(\@file_stack); 
     447 
     448    return wantarray() ? @file_stack : $file_stack[0]; 
     449} 
    430450 
    431451# Private? 
  • trunk/lib/Mungo/Response.pm

    r82 r92  
    3030     $Response->AddHeader('header_name' => $value); 
    3131  %> 
     32 
     33  <!-- path of the current file (handy for debugging) --> 
     34  <% my $file = $Response->CurrentFile(); %> 
     35 
    3236 
    3337  <!-- Halt processing and jump out of the handler --> 
     
    98102use Mungo::Utils; 
    99103use HTML::Entities; 
     104use Apache2::Const qw ( OK NOT_FOUND DECLINED SERVER_ERROR); 
     105 
    100106our $AUTOLOAD; 
    101107 
     
    196202} 
    197203 
     204=head2 $file = $Response->CurrentFile(); 
     205 
     206=head2 @nested_files = $Response->CurrentFile(); 
     207 
     208Returns 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.   
     209 
     210If the Mungo code originated from a string reference rather than a file, the file entry will read 'ANON'. 
     211 
     212=cut 
     213 
     214sub CurrentFile { 
     215    my $self = shift; 
     216    return $self->{Mungo}->CurrentFile(); 
     217} 
     218 
    198219=head2 $Response->i18nHandler($coderef); 
    199220 
     
    367388    print '<pre>'.Dumper($@).'</pre>'; 
    368389  } 
     390 
     391  # Set response code to 500.  Fixes trac16 
     392  $self->{Mungo}->{data}->{ApacheResponseCode} = SERVER_ERROR; 
    369393} 
    370394