Apache-Voodoo

 view release on metacpan or  search on metacpan

lib/Apache/Voodoo/Debug/FirePHP.pm  view on Meta::CPAN

	my $structure_index = 1;
	if ($self->{messageIndex} == 1) {
		$self->setHeader('X-Wf-Protocol-1',WF_PROTOCOL);
		$self->setHeader('X-Wf-1-Plugin-1',WF_PLUGIN);

		if ($Type eq DUMP) {
			$structure_index = 2;
			$self->setHeader('X-Wf-1-Structure-2',WF_STRUCTURE2);
		}
		else {
			$self->setHeader('X-Wf-1-Structure-1',WF_STRUCTURE1);
		}
	}

	my $msg;
	if ($Type eq DUMP) {
		$msg = '{"'.$Label.'":'.$self->jsonEncode($Object).'}';
	}
	else {
		$meta{'Type'}  = $Type;
		$meta{'Label'} = $Label;

		$msg = '['.$self->jsonEncode(\%meta).','.$self->jsonEncode($Object).']';
	}

	# FirePHP wants the number of bytes, not characters.  So we can't use length() here, a 2 or 3 byte
	# character counts as 1 as far as length is concerned.
	my $l = length(unpack('b*',$msg))/8;

	if ($l < BLOCK_LENGTH) {
		# The message can be send in one block
		$self->setHeader(
			'X-Wf-1-'.$structure_index.'-1-'.$self->{'messageIndex'},
			$l . '|' . $msg . '|'
		);

		$self->{'messageIndex'}++;
	}
	else {
		# Message needs to be split into multiple parts
		my $c = ($l % BLOCK_LENGTH)?int($l/BLOCK_LENGTH)+1:$l/BLOCK_LENGTH;

		foreach (my $i=0; $i < $c; $i++) {
			my $part = substr($msg, $i*BLOCK_LENGTH, BLOCK_LENGTH);

			my $v;
			# length prefix on the first part
			$v .= $l if ($i==0);

			# the data
			$v .= '|'.$part.'|';

			# \ on the end of the line, on all but the last part
			$v .= '\\' if ($i < ($c-1));

			$self->setHeader('X-Wf-1-'.$structure_index.'-1-'.$self->{'messageIndex'}, $v);

			$self->{'messageIndex'}++;

			if ($self->{'messageIndex'} > 99999) {
				#throw new Exception('Maximum number (99,999) of messages reached!');
			}
		}
	}

	#$self->setHeader('X-Wf-1-Index',$self->{'messageIndex'}-1);

	return 1;
}

sub setHeader() {
	my $self  = shift;
	my $name  = shift;
	my $value = shift;

	$self->{mp}->header_out($name,$value);
}

sub jsonEncode {
	my $self   = shift;
	my $Object = shift;

	return $self->{'json'}->to_json($Object);
}

1;

################################################################################
# Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
# All rights reserved.
#
# You may use and distribute Apache::Voodoo under the terms described in the
# LICENSE file include in this package. The summary is it's a legalese version
# of the Artistic License :)
#
################################################################################



( run in 0.678 second using v1.01-cache-2.11-cpan-39bf76dae61 )