From: gfx Date: Fri, 9 Oct 2009 03:45:23 +0000 (+0900) Subject: Move non-useful, Moose-specific methods into t/lib/Test/Mouse.pm X-Git-Tag: 0.37_05~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=c9313657717f78bd96f0325c6aa1c93d0b0d41a5;hp=a300a259066daf8137272dbd4790771ef7cac211 Move non-useful, Moose-specific methods into t/lib/Test/Mouse.pm --- diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index 3e3a724..04e6cc1 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -56,6 +56,7 @@ sub add_attribute { my $name = shift; $self->{attributes}->{$name} = (@_ == 1) ? $_[0] : { @_ }; + return; } sub _check_required_methods{ @@ -244,17 +245,14 @@ sub combine { for my $modifier_type (qw/before after around/) { my $modifier = "${modifier_type}_method_modifiers"; + my $add_method_modifier = sub { my ($self, $method_name, $method) = @_; push @{ $self->{$modifier}->{$method_name} ||= [] }, $method; return; }; - my $has_method_modifiers = sub{ - my($self, $method_name) = @_; - my $m = $self->{$modifier}->{$method_name}; - return $m && @{$m} != 0; - }; + my $get_method_modifiers = sub { my ($self, $method_name) = @_; return @{ $self->{$modifier}->{$method_name} ||= [] } @@ -262,8 +260,9 @@ for my $modifier_type (qw/before after around/) { no strict 'refs'; *{ 'add_' . $modifier_type . '_method_modifier' } = $add_method_modifier; - *{ 'has_' . $modifier_type . '_method_modifiers' } = $has_method_modifiers; *{ 'get_' . $modifier_type . '_method_modifiers' } = $get_method_modifiers; + + # has_${modifier_type}_method_modifiers is moved into t::lib::Test::Mouse } sub add_override_method_modifier{ @@ -280,23 +279,11 @@ sub add_override_method_modifier{ $self->{override_method_modifiers}->{$method_name} = $method; } -sub has_override_method_modifier { - my ($self, $method_name) = @_; - return exists $self->{override_method_modifiers}->{$method_name}; -} - sub get_override_method_modifier { my ($self, $method_name) = @_; return $self->{override_method_modifiers}->{$method_name}; } -sub get_method_modifier_list { - my($self, $modifier_type) = @_; - - return keys %{ $self->{$modifier_type . '_method_modifiers'} }; -} - -# This is currently not passing all the Moose tests. sub does_role { my ($self, $role_name) = @_; @@ -312,9 +299,7 @@ sub does_role { return 0; } - 1; - __END__ =head1 NAME diff --git a/t/030_roles/008_role_conflict_edge_cases.t b/t/030_roles/008_role_conflict_edge_cases.t index f22db0e..9a44f30 100644 --- a/t/030_roles/008_role_conflict_edge_cases.t +++ b/t/030_roles/008_role_conflict_edge_cases.t @@ -6,6 +6,9 @@ use warnings; use Test::More tests => 32; use Test::Exception; +use lib 't/lib'; +use Test::Mouse; + =pod Check for repeated inheritance causing diff --git a/t/lib/Test/Mouse.pm b/t/lib/Test/Mouse.pm index e654cdf..93b4946 100644 --- a/t/lib/Test/Mouse.pm +++ b/t/lib/Test/Mouse.pm @@ -55,7 +55,8 @@ sub has_attribute_ok ($$;$) { # Moose compatible methods/functions -package Mouse::Meta::Module; +package + Mouse::Meta::Module; sub version { no strict 'refs'; ${shift->name.'::VERSION'} } sub authority { no strict 'refs'; ${shift->name.'::AUTHORITY'} } @@ -68,8 +69,35 @@ sub identifier { ); } +package + Mouse::Meta::Role; -package Mouse::Util::TypeConstraints; +for my $modifier_type (qw/before after around/) { + my $modifier = "${modifier_type}_method_modifiers"; + my $has_method_modifiers = sub{ + my($self, $method_name) = @_; + my $m = $self->{$modifier}->{$method_name}; + return $m && @{$m} != 0; + }; + + no strict 'refs'; + *{ 'has_' . $modifier_type . '_method_modifiers' } = $has_method_modifiers; +} + + +sub has_override_method_modifier { + my ($self, $method_name) = @_; + return exists $self->{override_method_modifiers}->{$method_name}; +} + +sub get_method_modifier_list { + my($self, $modifier_type) = @_; + + return keys %{ $self->{$modifier_type . '_method_modifiers'} }; +} + +package + Mouse::Util::TypeConstraints; use Mouse::Util::TypeConstraints (); @@ -86,7 +114,8 @@ sub export_type_constraints_as_functions { # TEST ONLY return; } -package Mouse::Meta::Attribute; +package + Mouse::Meta::Attribute; sub applied_traits{ $_[0]->{traits} } # TEST ONLY sub has_applied_traits{ exists $_[0]->{traits} } # TEST ONLY