> That sounds very smart indeed! Please do so - I'd love to have that patch!

Cool :) Attatched is the bare-bones patch.

And here are few things you might want to consider... :

1) in main_handler(), $E is checked against Error::Simple as well.
However, if $E is a Error::Simple object and $E->as_xml is called, my
patch would obviously break. But then again, process_error() used to
call $E->stacktrace_list() which is not in Error::Simple anyway, so I
guess this doesn't matter... (b/c Error::Simple never actually gets
raised ? ) ?

2) I seem to remember that you wanted to separate out the mod_perl
related stuff from AxKit specific functions. process_error() currently
uses $r to grab the filename out of it. So in order to allow both
mod_perl and non-mod_perl usage, I currently have $E->as_xml accept an
optional parameter, $r. If $r is present, then $r->filename is used.
Otherwise $E->file is used. I didn't know how you wanted to do this, so
let me know if that doesn't work... If this functionality is not
required, I could just grab Apache->request from as_xml().

3) xml_escape() is defined in AxKit.pm, so I just used
AxKit::xml_escape($str) from Apache::AxKit::Exception. I find this
rather ugly, but again, I didn't know how you wanted to handle it, so I
just used it as is. Perhaps an equivalent of HTML::Entities should be
uploaded to CPAN to handle these things for XML...

--d
Index: lib/AxKit.pm
===================================================================
RCS file: /home/cvspublic/xml-axkit/lib/AxKit.pm,v
retrieving revision 1.25
diff -u -r1.25 AxKit.pm
--- lib/AxKit.pm        28 Jun 2002 10:18:28 -0000      1.25
+++ lib/AxKit.pm        29 Jun 2002 17:12:38 -0000
@@ -518,24 +518,8 @@
     $AxKit::Cache = Apache::AxKit::Cache->new($r, 'error', '', '', '');
     
     $r->content_type("text/html; charset=UTF-8"); # set a default for errors
-    
-    my $error = '<error><file>' .
-            xml_escape($r->filename) . '</file><msg>' .
-            xml_escape($E->{-text}) . '</msg>' .
-            '<stack_trace><bt level="0">'.
-            '<file>' . xml_escape($E->{'-file'}) . '</file>' .
-            '<line>' . xml_escape($E->{'-line'}) . '</line>' .
-            '</bt>';
-    
-    my $i = 1;
-    for my $stack (@{$E->stacktrace_list}) {
-        $error .= '<bt level="' . $i++ . '">' .
-                '<file>' . xml_escape($stack->{'-file'}) . '</file>' .
-                '<line>' . xml_escape($stack->{'-line'}) . '</line>' .
-                '</bt>';
-    }
 
-    $error .= '</stack_trace></error>';
+    my $error = $E->as_xml($r);
 
     my $provider = Apache::AxKit::Provider::Scalar->new(
             $r, $error, $error_styles
Index: lib/Apache/AxKit/Exception.pm
===================================================================
RCS file: /home/cvspublic/xml-axkit/lib/Apache/AxKit/Exception.pm,v
retrieving revision 1.2
diff -u -r1.2 Exception.pm
--- lib/Apache/AxKit/Exception.pm       2 Apr 2002 16:27:54 -0000       1.2
+++ lib/Apache/AxKit/Exception.pm       29 Jun 2002 17:12:38 -0000
@@ -27,6 +27,37 @@
     return $E->{'stacktrace'} || [];
 }
 
+sub as_xml {
+    my $E = shift;
+
+    ## >> allow as_xml to be used with non-mod_perl applications as well... 
+    ## if the second argument is passed, and it's an Apache request
+    ## object, then the filename is retrieved from $r. Otherwise, we use
+    ## $E->file as the filename
+    my $r = shift if @_ && eval{ $_[0]->isa( 'Apache' ) };
+    my $filename =
+        $r ? $r->filename : $E->file;
+
+    my $error = '<error><file>' .
+            AxKit::xml_escape($filename) . '</file><msg>' .
+            AxKit::xml_escape($E->{-text}) . '</msg>' .
+            '<stack_trace><bt level="0">'.
+            '<file>' . AxKit::xml_escape($E->{'-file'}) . '</file>' .
+            '<line>' . AxKit::xml_escape($E->{'-line'}) . '</line>' .
+            '</bt>';
+    
+    my $i = 1;
+    for my $stack (@{$E->stacktrace_list}) {
+        $error .= '<bt level="' . $i++ . '">' .
+                '<file>' . AxKit::xml_escape($stack->{'-file'}) . '</file>' .
+                '<line>' . AxKit::xml_escape($stack->{'-line'}) . '</line>' .
+                '</bt>';
+    }
+
+    $error .= '</stack_trace></error>';
+    return $error;
+}
+
 use overload 'bool' => 'bool';
 
 sub bool {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to