mach 2003/12/10 14:43:08
Modified: lib Tag: axkit-pipeline-2 AxKit.pm Log: Cleaning up AxKit::Apache a bit. Revision Changes Path No revision No revision 1.53.2.4 +43 -36 xml-axkit/lib/AxKit.pm Index: AxKit.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/AxKit.pm,v retrieving revision 1.53.2.3 retrieving revision 1.53.2.4 diff -u -r1.53.2.3 -r1.53.2.4 --- AxKit.pm 31 Oct 2003 00:06:22 -0000 1.53.2.3 +++ AxKit.pm 10 Dec 2003 22:43:08 -0000 1.53.2.4 @@ -1,6 +1,6 @@ package AxKit; use strict; -use vars qw/$VERSION $Pipeline/; +use vars qw/$VERSION/; use DynaLoader (); use UNIVERSAL (); @@ -16,7 +16,6 @@ use Apache::AxKit::CharsetConv; use Apache::AxKit::PipeCtrl; use File::Basename (); -use Data::Dumper; use Compress::Zlib (); use Fcntl; @@ -70,7 +69,6 @@ return $AxKit::Cfg->{to_utf8}->convert($_[0]); } - sub _Debug { my $level = shift; if ($level <= $AxKit::DebugLevel) { @@ -261,6 +259,7 @@ my $ret = main_handler($r ); $r->status($rc); + return $ret; } @@ -270,6 +269,7 @@ # setup global pnotes. local $AxKit::Apache::PNOTES = $r->pnotes(); + bless $r, 'AxKit::Apache'; my $provider = Apache::AxKit::Provider->new_content_provider($r); my $retcode = eval { @@ -296,11 +296,6 @@ return $pipeline->send($r); - # restore $r - if (ref($r) eq 'AxKit::Apache') { - bless $r, 'Apache'; - tie *STDOUT, 'Apache', $r; - } }; my $E = $@; unless ($E) { @@ -312,7 +307,6 @@ # restore $r if it hasn't been restored already if (ref($r) eq 'AxKit::Apache') { bless $r, 'Apache'; - tie *STDOUT, 'Apache', $r; } if ($E->isa('Apache::AxKit::Exception::OK')) { @@ -431,6 +425,7 @@ AxKit::Debug(3, "get_axkit_uri($uri)"); my $apache = AxKit::Apache->request; + my $r; if ($uri =~ /^axkit:(\/.*)$/) { my $blurb = $1; @@ -447,6 +442,7 @@ } AxKit::Debug(4, "get_axkit_uri looking up abs (host): '$abs_uri'"); $r = $apache->lookup_uri(AxKit::FromUTF8($abs_uri)); + } else { my $abs_uri = $blurb; @@ -470,10 +466,14 @@ local($AxKit::Pipeline) = Apache::AxKit::PipeCtrl->new(); my $pipeline = build_pipeline($r, $provider, 1); # no output; - - my $str_ref = eval { $pipeline->get_strref($r, 0); }; - - my $result_code = $r->status(); + + bless $r, 'AxKit::Apache'; + + my $result_code; + + my $str_ref = eval { + $pipeline->get_strref( $r ); + }; if ($@) { my $E = $@; @@ -510,6 +510,8 @@ return $E->as_xml($r->filename); } } + + $result_code ||= $r->status(); if($result_code == 200 || $result_code eq OK) { return ${$str_ref}; @@ -686,39 +688,19 @@ return bless Apache->request, 'AxKit::Apache'; } -sub TIEHANDLE { - my($class, $r) = @_; - $r ||= Apache->request; -} - sub print { my $self = shift; - delete $self->pnotes()->{'dom_tree'}; - use bytes; - if ($self->notes('resetstring')) { - $self->pnotes('xml_string', ''); - $self->notes('resetstring', 0); - } - - my $current = $self->pnotes('xml_string'); - $self->pnotes('xml_string', $current . join('', @_)); + # This will go to the locally tied version of + # STDOUT. + print STDOUT @_; } -*PRINT = \&print; - sub send_http_header { my $self = shift; my ($content_type) = @_; - - return if $self->notes('headers_sent'); - if ($content_type) { $self->content_type($content_type); } - - $self->notes('headers_sent', 1); - - $self->SUPER::send_http_header; } sub pnotes { @@ -732,8 +714,33 @@ } return $PNOTES->{$key}; } + + +1; + +package AxKit::Buffer; +# Used for capturing STDOUT when we want to do that. + +sub TIEHANDLE{ + my $class = shift; + my $foo; + my $self = \$foo; + bless $self, $class; + return $self; +} + +sub PRINT{ + my $self = shift; + $$self = join(undef,$$self, @_ ); +} + +sub content{ + my $self = shift; + return $$self; +} 1; + package AxKit::ApacheDebug; use vars qw/@ISA/;