From: t0m Date: Wed, 24 Jun 2009 20:03:15 +0000 (+0100) Subject: I think that these should be implemented as a role on the engine. So if I arrange... X-Git-Tag: 0.20~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=59abaf70d6f2f724a1a895f0d07cceb2a7aaeb87;p=gitmo%2FMooseX-Storage.git I think that these should be implemented as a role on the engine. So if I arrange to stuff an option into the pack and unpack calls, it'll work like magic, and you can also turn the features on for individual ->pack or ->unpack calls if you want to (once I move the functionality) --- diff --git a/lib/MooseX/Storage/Traits/DisableCycleDetection.pm b/lib/MooseX/Storage/Traits/DisableCycleDetection.pm index 9d62b00..a8fb9bd 100644 --- a/lib/MooseX/Storage/Traits/DisableCycleDetection.pm +++ b/lib/MooseX/Storage/Traits/DisableCycleDetection.pm @@ -4,6 +4,23 @@ use Moose::Role; our $VERSION = '0.18'; our $AUTHORITY = 'cpan:STEVAN'; +requires 'pack'; +requires 'unpack'; + +around 'pack' => sub { + my ($orig, $self, %args) = @_; + $args{engine_traits} ||= []; + push(@{$args{engine_traits}}, 'DisableCycleDetection'); + $self->$orig(%args); +}; + +around 'unpack' => sub { + my ($orig, $self, $data, %args) = @_; + $args{engine_traits} ||= []; + push(@{$args{engine_traits}}, 'DisableCycleDetection'); + $self->$orig($data, %args); +}; + 1; __END__ diff --git a/lib/MooseX/Storage/Traits/OnlyWhenBuilt.pm b/lib/MooseX/Storage/Traits/OnlyWhenBuilt.pm index a3b9752..7464364 100644 --- a/lib/MooseX/Storage/Traits/OnlyWhenBuilt.pm +++ b/lib/MooseX/Storage/Traits/OnlyWhenBuilt.pm @@ -4,6 +4,23 @@ use Moose::Role; our $VERSION = '0.18'; our $AUTHORITY = 'cpan:STEVAN'; +requires 'pack'; +requires 'unpack'; + +around 'pack' => sub { + my ($orig, $self, %args) = @_; + $args{engine_traits} ||= []; + push(@{$args{engine_traits}}, 'OnlyWhenBuilt'); + $self->$orig(%args); +}; + +around 'unpack' => sub { + my ($orig, $self, $data, %args) = @_; + $args{engine_traits} ||= []; + push(@{$args{engine_traits}}, 'OnlyWhenBuilt'); + $self->$orig($data, %args); +}; + 1; __END__