Actually do something useful with the engine_traits parameter, by appling a role...
t0m [Wed, 24 Jun 2009 21:18:29 +0000 (22:18 +0100)]
lib/MooseX/Storage/Basic.pm
lib/MooseX/Storage/Engine/Trait/DisableCycleDetection.pm [new file with mode: 0644]
lib/MooseX/Storage/Engine/Trait/OnlyWhenBuilt.pm [new file with mode: 0644]

index cfdbb1f..a803e74 100644 (file)
@@ -7,14 +7,14 @@ our $VERSION   = '0.18';
 our $AUTHORITY = 'cpan:STEVAN';
 
 sub pack {
-    my ( $self, @args ) = @_;
-    my $e = $self->_storage_get_engine_class->new( object => $self );
-    $e->collapse_object(@args);
+    my ( $self, %args ) = @_;
+    my $e = $self->_storage_get_engine_class(%args)->new( object => $self );
+    $e->collapse_object(%args);
 }
 
 sub unpack {
     my ($class, $data, %args) = @_;
-    my $e = $class->_storage_get_engine_class->new(class => $class);
+    my $e = $class->_storage_get_engine_class(%args)->new(class => $class);
     
     $class->_storage_construct_instance( 
         $e->expand_object($data, %args), 
@@ -23,7 +23,25 @@ sub unpack {
 }
 
 sub _storage_get_engine_class {
-    'MooseX::Storage::Engine';
+    my ($self, %args) = @_;
+
+    my $default = 'MooseX::Storage::Engine';
+
+    return $default
+        unless (
+            exists $args{engine_traits} 
+         && ref($args{engine_traits}) eq 'ARRAY'
+         && scalar(@{$args{engine_traits}})
+    );
+    
+    my @roles = map { sprintf("%s::Trait::%s", $default, $_) }
+        @{$args{engine_traits}};
+    
+    Moose::Meta::Class->create_anon_class(
+        superclasses => [$default],
+        roles => [ @roles ],
+        cache => 1,
+    )->name;
 }
 
 sub _storage_construct_instance {
diff --git a/lib/MooseX/Storage/Engine/Trait/DisableCycleDetection.pm b/lib/MooseX/Storage/Engine/Trait/DisableCycleDetection.pm
new file mode 100644 (file)
index 0000000..717e243
--- /dev/null
@@ -0,0 +1,5 @@
+package MooseX::Storage::Engine::Trait::DisableCycleDetection;
+use Moose::Role;
+
+1;
+
diff --git a/lib/MooseX/Storage/Engine/Trait/OnlyWhenBuilt.pm b/lib/MooseX/Storage/Engine/Trait/OnlyWhenBuilt.pm
new file mode 100644 (file)
index 0000000..163be53
--- /dev/null
@@ -0,0 +1,7 @@
+package MooseX::Storage::Engine::Trait::OnlyWhenBuilt;
+use Moose::Role;
+
+our $VERSION = 1;
+
+1;
+