package Apache::AxKit::Pipeline::Transformer;

use strict;
use vars qw/@ISA $VERSION %DEPENDS/;
use AxKit;
use Compress::Zlib;
use Apache::AxKit::Pipeline;

@ISA = 'Apache::AxKit::Pipeline';

$VERSION = 1.0; # this fixes a CPAN.pm bug. Bah!

sub get_strref{
	my ($self, $r ) = @_;
	# Allow passthru if required.
	# Note: pipeline should never normally be created this way
	# since pipeline creator shouldn't add this module in
	# if it's not required.
	return $self->upstream()->get_strref( $r );
}

sub get_bytes_ref{
	my ($self, $r) = @_;
	
	my $str_ref = $self->upstream()->get_bytes_ref( $r );

	my $stage = $self->stage();
	
    if (my $charset = $AxKit::Cfg->OutputCharset()) {
        my $ct = $r->content_type;
        $ct =~ s/charset=.*?(;|$)/charset=$charset/i;
        $r->content_type($ct);
    }	
	
	my ($transformer, $doit) = AxKit::get_output_transformer();
	
	my $str = ${$str_ref};
	if($doit) {
		AxKit::Debug(4, "Transfromer[$stage]: Running output transformers");
		$str = $transformer->( ${$str_ref} );
	}
	
	return \$str;		
}
    

sub output_binary{ 1 };

1;
