From: Tomas Doran Date: Mon, 29 Sep 2008 13:51:36 +0000 (+0000) Subject: Fix issue I'm seeing in MX::Storage when using it in multiple roles which I combine. X-Git-Tag: 0.15^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Ftags%2F0.15;p=gitmo%2FMooseX-Storage.git Fix issue I'm seeing in MX::Storage when using it in multiple roles which I combine. --- diff --git a/Changes b/Changes index dab836b..94a33ef 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ Revision history for MooseX-Storage +0.15 + * MooseX::Storage + - Remove use of deprecated alias_method routine + which was causing issues when you used multiple + Roles which used MooseX::Storage (t0m). + 0.14 * MooseX::Storage::Engine - cycles are now tracked by refaddr instead diff --git a/lib/MooseX/Storage.pm b/lib/MooseX/Storage.pm index 376ebad..810b764 100644 --- a/lib/MooseX/Storage.pm +++ b/lib/MooseX/Storage.pm @@ -4,7 +4,7 @@ use Moose qw(confess); use MooseX::Storage::Meta::Attribute::DoNotSerialize; -our $VERSION = '0.14'; +our $VERSION = '0.15'; our $AUTHORITY = 'cpan:STEVAN'; sub import { @@ -15,47 +15,49 @@ sub import { ($pkg->can('meta')) || confess "This package can only be used in Moose based classes"; - $pkg->meta->alias_method('Storage' => sub { - my %params = @_; + $pkg->meta->add_method('Storage' => __PACKAGE__->meta->find_method_by_name('_injected_storage_role_generator')); +} + +sub _injected_storage_role_generator { + my %params = @_; - if (exists $params{'base'}) { - $params{'base'} = ('Base::' . $params{'base'}); - } - else { - $params{'base'} = 'Basic'; - } + if (exists $params{'base'}) { + $params{'base'} = ('Base::' . $params{'base'}); + } + else { + $params{'base'} = 'Basic'; + } - my @roles = ( - ('MooseX::Storage::' . $params{'base'}), - ); + my @roles = ( + ('MooseX::Storage::' . $params{'base'}), + ); - # NOTE: - # you don't have to have a format - # role, this just means you dont - # get anything other than pack/unpack - push @roles => 'MooseX::Storage::Format::' . $params{'format'} - if exists $params{'format'}; + # NOTE: + # you don't have to have a format + # role, this just means you dont + # get anything other than pack/unpack + push @roles => 'MooseX::Storage::Format::' . $params{'format'} + if exists $params{'format'}; + # NOTE: + # many IO roles don't make sense unless + # you have also have a format role chosen + # too, the exception being StorableFile + if (exists $params{'io'}) { # NOTE: - # many IO roles don't make sense unless - # you have also have a format role chosen - # too, the exception being StorableFile - if (exists $params{'io'}) { - # NOTE: - # we dont need this code anymore, cause - # the role composition will catch it for - # us. This allows the StorableFile to work - #(exists $params{'format'}) - # || confess "You must specify a format role in order to use an IO role"; - push @roles => 'MooseX::Storage::IO::' . $params{'io'}; - } + # we dont need this code anymore, cause + # the role composition will catch it for + # us. This allows the StorableFile to work + #(exists $params{'format'}) + # || confess "You must specify a format role in order to use an IO role"; + push @roles => 'MooseX::Storage::IO::' . $params{'io'}; + } - Class::MOP::load_class($_) - || die "Could not load role (" . $_ . ") for package ($pkg)" - foreach @roles; + Class::MOP::load_class($_) + || die "Could not load role (" . $_ . ")" + foreach @roles; - return @roles; - }); + return @roles; } 1; diff --git a/t/200_combined_in_roles.t b/t/200_combined_in_roles.t new file mode 100755 index 0000000..f36e1ac --- /dev/null +++ b/t/200_combined_in_roles.t @@ -0,0 +1,23 @@ +#/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 1; +use Test::Exception; + +{ + package ClassOne; + use Moose::Role; + use MooseX::Storage; +} +{ + package ClassTwo; + use Moose::Role; + use MooseX::Storage; +} + +lives_ok { + package CombineClasses; + use Moose; + with qw/ClassOne ClassTwo/; +} 'Can include two roles which both use MooseX::Storage'; +