Skip to content

Commit

Permalink
Moved Reference's inclusion of Zlib to runtime; replaced length() on …
Browse files Browse the repository at this point in the history
…Reference packets (was dropped in previous patch)
  • Loading branch information
rcaputo committed Jan 25, 2000
1 parent 73f16c9 commit 488cb1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
49 changes: 30 additions & 19 deletions lib/POE/Filter/Reference.pm
Expand Up @@ -24,24 +24,29 @@ sub _default_freezer {
}

#------------------------------------------------------------------------------
# Try to acquire Compress::Zlib.

my $zlib_error = '';
BEGIN {
eval 'use Compress::Zlib qw(compress uncompress);';
if ($@) {
$zlib_error = $@;
eval <<' EOE';
sub compress { @_ }
sub uncompress { @_ }
sub CAN_COMPRESS () { 0 }
EOE
}
else {
eval <<' EOE';
sub CAN_COMPRESS () { 1 }
EOE
# Try to acquire Compress::Zlib at runtime.

my $zlib_status = undef;
sub _include_zlib {
local $SIG{'__DIE__'} = 'DEFAULT';

unless (defined $zlib_status) {
eval { require 'Compress::Zlib';
import Compress::Zlib qw(compress uncompress);
};
if ($@) {
$zlib_status = $@;
eval <<' EOE';
sub compress { @_ }
sub uncompress { @_ }
EOE
}
else {
$zlib_status = '';
}
}

$zlib_status;
}

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -74,8 +79,13 @@ sub new {

# Compression
$compression ||= 0;
if ($compression and !CAN_COMPRESS) {
carp "Compress::Zlib load failed with error: $zlib_error";
if ($compression) {
my $zlib_status = &_include_zlib();
if ($zlib_status ne '') {
warn "Compress::Zlib load failed with error: $zlib_status\n";
carp "Filter::Reference compression option ignored";
$compression = 0;
}
}

my $self = bless { buffer => '',
Expand Down Expand Up @@ -122,6 +132,7 @@ sub put {
my @raw = map {
my $frozen = $self->{freeze}->($_);
$frozen = compress($frozen) if $self->{compress};
length($frozen) . "\0" . $frozen;
} @$references;
\@raw;
}
Expand Down
4 changes: 4 additions & 0 deletions samples/filterchange.perl
Expand Up @@ -176,6 +176,7 @@ sub received
if($send)
{
print "Cause [$$] send '$send'\n";
print "Cause [$$] (running $send )\n";
$send=eval($send);
die $@ if $@;
# print "Cause [$$] send '", quotemeta($send), "'\n";
Expand Down Expand Up @@ -427,3 +428,6 @@ package main;
print "$me [$$] POE->run\n";
$poe_kernel->run();
print "$me [$$] Exit\n";



0 comments on commit 488cb1a

Please sign in to comment.