[poe-commits] poe/lib/POE/Filter Reference.pm,1.32,1.33
Brought to you by:
rcaputo
From: <ap...@us...> - 2005-03-17 04:30:43
|
Update of /cvsroot/poe/poe/lib/POE/Filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19155/lib/POE/Filter Modified Files: Reference.pm Log Message: Patched it to cache the default freezer for performance reasons - brought up by bline, look at this ticket for more info - https://rt.cpan.org/Ticket/Display.html?id=11897 Index: Reference.pm =================================================================== RCS file: /cvsroot/poe/poe/lib/POE/Filter/Reference.pm,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Reference.pm 25 Nov 2004 19:37:23 -0000 1.32 --- Reference.pm 17 Mar 2005 04:30:31 -0000 1.33 *************** *** 16,32 **** #------------------------------------------------------------------------------ # Try to require one of the default freeze/thaw packages. ! ! sub _default_freezer { local $SIG{'__DIE__'} = 'DEFAULT'; - my $ret; foreach my $p (qw(Storable FreezeThaw YAML)) { eval { require "$p.pm"; import $p (); }; ! warn $@ if $@; ! return $p if $@ eq ''; } ! die "Filter::Reference requires Storable, FreezeThaw, or YAML"; } #------------------------------------------------------------------------------ # Try to acquire Compress::Zlib at runtime. --- 16,40 ---- #------------------------------------------------------------------------------ # Try to require one of the default freeze/thaw packages. ! use vars qw( $DEF_FREEZER $DEF_FREEZE $DEF_THAW ); ! BEGIN { local $SIG{'__DIE__'} = 'DEFAULT'; foreach my $p (qw(Storable FreezeThaw YAML)) { eval { require "$p.pm"; import $p (); }; ! if ( $@ ) { ! warn $@; ! next; ! } else { ! # Found a good freezer! ! $DEF_FREEZER = $p; ! last; ! } } ! die "Filter::Reference requires Storable, FreezeThaw, or YAML" if ! defined $DEF_FREEZER; } + # Some processing here + ( $DEF_FREEZE, $DEF_THAW ) = _get_methods( $DEF_FREEZER ); + #------------------------------------------------------------------------------ # Try to acquire Compress::Zlib at runtime. *************** *** 67,89 **** sub new { my($type, $freezer, $compression) = @_; ! $freezer ||= _default_freezer(); ! ! my($freeze, $thaw)=_get_methods($freezer); ! ! # not a reference... maybe a package? ! # and if it's a package, does it have the methods we want? ! # if not, we are going to try to load it ! ! unless(ref $freezer and $freeze and $thaw) { ! my $package = $freezer; ! $package =~ s(::)(\/)g; ! delete $INC{$package . ".pm"}; ! eval {local $^W=0; require "$package.pm"; import $freezer ();}; ! carp $@ if $@; ! ($freeze, $thaw)=_get_methods($freezer); ! } # Now get the methods we want --- 75,105 ---- sub new { my($type, $freezer, $compression) = @_; ! ! my( $freeze, $thaw ); ! if ( ! defined $freezer ) { ! # Okay, load the default one! ! $freezer = $DEF_FREEZER; ! $freeze = $DEF_FREEZE; ! $thaw = $DEF_THAW; ! } else { ! # What did we get? ! if ( ref $freezer ) { ! # It's an object, create an closure ! my( $freezetmp, $thawtmp ) = _get_methods( $freezer ); ! $freeze = sub { $freezetmp->( $freezer, @_ ) }; ! $thaw = sub { $thawtmp->( $freezer, @_ ) }; ! } else { ! # A package name? ! my $package = $freezer; ! $package =~ s(::)(\/)g; ! delete $INC{$package . ".pm"}; ! eval {local $^W=0; require "$package.pm"; import $freezer ();}; ! carp $@ if $@; ! ( $freeze, $thaw )= _get_methods( $freezer ); ! } ! } # Now get the methods we want *************** *** 94,105 **** return unless $freeze and $thaw; - # If it's an object, we use closures to create a $self->method() - my $truefreeze=$freeze; - my $truethaw=$thaw; - if(ref $freezer) { - $truefreeze=sub {$freeze->($freezer, @_)}; - $truethaw=sub {$thaw->($freezer, @_)}; - } - # Compression $compression ||= 0; --- 110,113 ---- *************** *** 115,120 **** my $self = bless { buffer => '', expecting => undef, ! thaw => $truethaw, ! freeze => $truefreeze, compress => $compression, }, $type; --- 123,128 ---- my $self = bless { buffer => '', expecting => undef, ! thaw => $thaw, ! freeze => $freeze, compress => $compression, }, $type; |