* add support for Storage( traits => [...] ) to alter the behaviour of the
[gitmo/MooseX-Storage.git] / t / 009_do_not_serialize_lazy.t
diff --git a/t/009_do_not_serialize_lazy.t b/t/009_do_not_serialize_lazy.t
new file mode 100644 (file)
index 0000000..54331bf
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More 'no_plan';#tests => 6;
+use Test::Exception;
+
+BEGIN {
+    use_ok('MooseX::Storage');
+}
+
+{   package Point;
+    use Moose;
+    use MooseX::Storage;
+
+    with Storage( traits => [qw|OnlyWhenBuilt|] );
+
+    has 'x' => (is => 'rw', lazy_build => 1 );
+    has 'y' => (is => 'rw', lazy_build => 1 );
+    has 'z' => (is => 'rw', builder => '_build_z' );
+    
+    
+    sub _build_x { 'x' }
+    sub _build_y { 'y' }
+    sub _build_z { 'z' }
+
+}
+
+my $p = Point->new( 'x' => $$ );
+ok( $p,                         "New object created" );
+
+my $href = $p->pack;
+
+ok( $href,                      "   Object packed" );
+is( $href->{'x'}, $$,           "       x => $$" );
+is( $href->{'z'}, 'z',          "       z => z" );
+ok( not(exists($href->{'y'})),  "       y does not exist" );
+
+is_deeply( 
+    $href, 
+    { '__CLASS__' => 'Point',
+      'x' => $$,
+      'z' => 'z'
+    },                          "   Deep check passed" );