From: Stevan Little Date: Mon, 31 Dec 2007 16:19:56 +0000 (+0000) Subject: moving stuff around and some cleanup X-Git-Tag: 0_35~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bca012825920c9018a249be00e0702eb03992179;p=gitmo%2FMoose.git moving stuff around and some cleanup --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index ef60f78..8adb280 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -132,13 +132,14 @@ sub add_attribute { $self->get_attribute_map->{$name} = $attr_desc; } -sub _clean_up_required_methods { - my $self = shift; - foreach my $method ($self->get_required_method_list) { - $self->remove_required_methods($method) - if $self->has_method($method); - } -} +# DEPRECATED +# sub _clean_up_required_methods { +# my $self = shift; +# foreach my $method ($self->get_required_method_list) { +# $self->remove_required_methods($method) +# if $self->has_method($method); +# } +# } ## ------------------------------------------------------------------ ## method modifiers @@ -357,19 +358,22 @@ sub alias_method { ## ------------------------------------------------------------------ sub apply { - my ($self, $other) = @_; - + my ($self, $other, @args) = @_; + + (blessed($other)) + || confess "You must pass in an blessed instance"; + if ($other->isa('Moose::Meta::Role')) { require Moose::Meta::Role::Application::ToRole; - return Moose::Meta::Role::Application::ToRole->new->apply($self, $other); + return Moose::Meta::Role::Application::ToRole->new->apply($self, $other, @args); } elsif ($other->isa('Moose::Meta::Class')) { require Moose::Meta::Role::Application::ToClass; - return Moose::Meta::Role::Application::ToClass->new->apply($self, $other); + return Moose::Meta::Role::Application::ToClass->new->apply($self, $other, @args); } else { require Moose::Meta::Role::Application::ToInstance; - return Moose::Meta::Role::Application::ToInstance->new->apply($self, $other); + return Moose::Meta::Role::Application::ToInstance->new->apply($self, $other, @args); } } diff --git a/lib/Moose/Meta/Role/Application.pm b/lib/Moose/Meta/Role/Application.pm index 7274f70..cae9e7c 100644 --- a/lib/Moose/Meta/Role/Application.pm +++ b/lib/Moose/Meta/Role/Application.pm @@ -32,9 +32,10 @@ sub apply_attributes { die "Abstract Method" } sub apply_methods { die "Abstract Method" } sub apply_override_method_modifiers { die "Abstract Method" } sub apply_method_modifiers { die "Abstract Method" } -sub apply_before_method_modifiers { die "Abstract Method" } -sub apply_around_method_modifiers { die "Abstract Method" } -sub apply_after_method_modifiers { die "Abstract Method" } + +sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) } +sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) } +sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) } 1; diff --git a/lib/Moose/Meta/Role/Application/RoleSummation.pm b/lib/Moose/Meta/Role/Application/RoleSummation.pm index 408b331..cc7f7b2 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -157,10 +157,6 @@ sub apply_method_modifiers { } } -sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) } -sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) } -sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) } - 1; __END__ @@ -196,12 +192,6 @@ bindings and 'disabling' the conflicting bindings =item B -=item B - -=item B - -=item B - =item B =back diff --git a/lib/Moose/Meta/Role/Application/ToClass.pm b/lib/Moose/Meta/Role/Application/ToClass.pm index a30c49f..8890aec 100644 --- a/lib/Moose/Meta/Role/Application/ToClass.pm +++ b/lib/Moose/Meta/Role/Application/ToClass.pm @@ -156,10 +156,6 @@ sub apply_method_modifiers { } } -sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) } -sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) } -sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) } - 1; __END__ @@ -192,12 +188,6 @@ Moose::Meta::Role::Application::ToClass =item B -=item B - -=item B - -=item B - =item B =back diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index 399bc72..3e5d427 100644 --- a/lib/Moose/Meta/Role/Application/ToRole.pm +++ b/lib/Moose/Meta/Role/Application/ToRole.pm @@ -126,10 +126,6 @@ sub apply_method_modifiers { } } -sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) } -sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) } -sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) } - 1; @@ -163,12 +159,6 @@ Moose::Meta::Role::Application::ToRole =item B -=item B - -=item B - -=item B - =item B =back diff --git a/t/030_roles/030_role_parameterized.t b/t/030_roles/030_role_parameterized.t new file mode 100644 index 0000000..7a3da7f --- /dev/null +++ b/t/030_roles/030_role_parameterized.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More no_plan => 1; +use Test::Exception; + +BEGIN { + use_ok('Moose'); +} + +=pod + +{ + package Scalar; + use Moose::Role; + + BEGIN { parameter T => { isa => 'Moose::Meta::TypeConstraint' } }; + + has 'val' => (is => 'ro', isa => T); + + requires 'eq'; + + sub not_eq { ! (shift)->eq(shift) } +} + +is_deeply( + Scalar->meta->parameters, + { T => { isa => 'Moose::Meta::TypeConstraint' } }, + '... got the right parameters in the role' +); + +{ + package Integers; + use Moose; + use Moose::Util::TypeConstraints; + + with Scalar => { T => find_type_constraint('Int') }; + + sub eq { shift == shift } +} + +=cut +