[Bps-public-commit] r14225 - in Data-Plist: . lib/Data/Plist

kyoki at bestpractical.com kyoki at bestpractical.com
Thu Jul 17 14:18:56 EDT 2008


Author: kyoki
Date: Thu Jul 17 14:18:56 2008
New Revision: 14225

Modified:
   Data-Plist/   (props changed)
   Data-Plist/lib/Data/Plist/BinaryReader.pm
   Data-Plist/lib/Data/Plist/BinaryWriter.pm
   Data-Plist/t/binary-write.t

Log:
 r29727 at nyx:  kyoki | 2008-07-17 14:18:56 -0400
 added a few more tests. caching is still broken


Modified: Data-Plist/lib/Data/Plist/BinaryReader.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/BinaryReader.pm	(original)
+++ Data-Plist/lib/Data/Plist/BinaryReader.pm	Thu Jul 17 14:18:56 2008
@@ -264,7 +264,7 @@
         or $OffsetTableOffset > $end
         or $OffsetTableOffset + $NumObjects * $OffsetSize > $end )
     {
-        die "Invalid offset table address\n";
+        die "Invalid offset table address (overlap with header or footer:\n OTO: $OffsetTableOffset\n NO: $NumObjects\n OS: $OffsetSize\n e: $end)\n";
     }
 
     # get the offset table

Modified: Data-Plist/lib/Data/Plist/BinaryWriter.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/BinaryWriter.pm	(original)
+++ Data-Plist/lib/Data/Plist/BinaryWriter.pm	Thu Jul 17 14:18:56 2008
@@ -4,6 +4,7 @@
 use warnings;
 use YAML;
 use Math::BigInt;
+use Digest::MD5;
 
 use base qw/Data::Plist::Writer/;
 
@@ -17,6 +18,7 @@
     $self->{fh}    = $fh;
     $self->{index} = [];
     $self->{size}  = $self->count($object);
+    $self->{objcache}= {};
     if ( $self->{size} >= 2**8 ) {
         $self->{refsize} = 2;
     }
@@ -43,8 +45,11 @@
     my ($arrayref) = @_;
     my $type       = $arrayref->[0];
     my $method     = "write_" . $type;
+    my $digest     = Digest::MD5::md5_hex( YAML::Dump( $arrayref->[1] ) );
     die "Can't $method" unless $self->can($method);
-    return $self->$method( $arrayref->[1] );
+    $self->{objcache}{$digest} = $self->$method( $arrayref->[1] )
+      unless ( exists $self->{objcache}{$digest} );
+    return $self->{objcache}{$digest};
 }
 
 sub make_type {

Modified: Data-Plist/t/binary-write.t
==============================================================================
--- Data-Plist/t/binary-write.t	(original)
+++ Data-Plist/t/binary-write.t	Thu Jul 17 14:18:56 2008
@@ -58,7 +58,10 @@
 round_trip(-1.985, 50);
 
 # Date
-round_trip(DateTime->new(year => 2001, month => 1, day => 17), 50);
+round_trip(DateTime->new(year => 2008, month => 7, day => 23), 50);
+
+# Caching
+round_trip({'kitteh' => 'Angleton', 'Laundry' => 'Angleton'}, 73);
 
 sub round_trip {
     my ( $input, $expected_size ) = @_;



More information about the Bps-public-commit mailing list