- move Serialize.pm to Serialize/Storable.pm
David Kamholz [Sat, 11 Feb 2006 21:19:31 +0000 (21:19 +0000)]
- add it to Core
- add basic test for it

lib/DBIx/Class/Core.pm
lib/DBIx/Class/Serialize/Storable.pm [moved from lib/DBIx/Class/Serialize.pm with 77% similarity]
t/basicrels/21serialize.t [new file with mode: 0644]
t/helperrels/21serialize.t [new file with mode: 0644]
t/run/21serialize.tl [new file with mode: 0644]

index 303d1cc..455e741 100644 (file)
@@ -7,6 +7,7 @@ no warnings 'qw';
 use base qw/DBIx::Class/;
 
 __PACKAGE__->load_components(qw/
+  Serialize::Storable
   InflateColumn
   Relationship
   PK
similarity index 77%
rename from lib/DBIx/Class/Serialize.pm
rename to lib/DBIx/Class/Serialize/Storable.pm
index 345b99c..48c4597 100644 (file)
@@ -1,18 +1,17 @@
-package DBIx::Class::Serialize;
+package DBIx::Class::Serialize::Storable;
 use strict;
-use Storable qw/freeze thaw/;
+use Storable;
 
 sub STORABLE_freeze {
     my ($self,$cloning) = @_;
-    #return if $cloning;
     my $to_serialize = { %$self };
     delete $to_serialize->{result_source};
-    return (freeze($to_serialize));
+    return (Storable::freeze($to_serialize));
 }
 
 sub STORABLE_thaw {
     my ($self,$cloning,$serialized) = @_;
-    %$self = %{ thaw($serialized) };
+    %$self = %{ Storable::thaw($serialized) };
     $self->result_source($self->result_source_instance);
 }
 
@@ -22,12 +21,12 @@ __END__
 
 =head1 NAME 
 
-    DBIx::Class::Serialize - hooks for Storable freeze/thaw (EXPERIMENTAL)
+    DBIx::Class::Serialize::Storable - hooks for Storable freeze/thaw (EXPERIMENTAL)
 
 =head1 SYNOPSIS
 
     # in a table class definition
-    __PACKAGE__->load_components(qw/Serialize/);
+    __PACKAGE__->load_components(qw/Serialize::Storable/);
     
     # meanwhile, in a nearby piece of code
     my $obj = $schema->resultset('Foo')->find(12);
diff --git a/t/basicrels/21serialize.t b/t/basicrels/21serialize.t
new file mode 100644 (file)
index 0000000..60e401d
--- /dev/null
@@ -0,0 +1,7 @@
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBICTest::BasicRels;
+
+require "t/run/21serialize.tl";
+run_tests(DBICTest->schema);
diff --git a/t/helperrels/21serialize.t b/t/helperrels/21serialize.t
new file mode 100644 (file)
index 0000000..0db9775
--- /dev/null
@@ -0,0 +1,7 @@
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBICTest::HelperRels;
+
+require "t/run/21serialize.tl";
+run_tests(DBICTest->schema);
diff --git a/t/run/21serialize.tl b/t/run/21serialize.tl
new file mode 100644 (file)
index 0000000..7c746f2
--- /dev/null
@@ -0,0 +1,14 @@
+use Storable;
+
+sub run_tests {
+my $schema = shift;
+
+plan tests => 1;
+
+my $artist = $schema->resultset('Artist')->find(1);
+my $copy = eval { Storable::dclone($artist) };
+is_deeply($copy, $artist, 'serialize row object works');
+
+}
+
+1;