From: Stevan Little Date: Mon, 31 Dec 2007 20:46:38 +0000 (+0000) Subject: cleaning up and working on the spec a bit X-Git-Tag: 0_35~39 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=709c321c3bdc9a36769c9a2b24723b5315439fd3;p=gitmo%2FMoose.git cleaning up and working on the spec a bit --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index d9825e0..bd3e691 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -68,7 +68,7 @@ foreach my $action ( get_list => 'get_required_method_list', existence => 'requires_method', } - }, + }, { name => 'attribute_map', attr_reader => 'get_attribute_map', @@ -350,9 +350,6 @@ sub alias_method { $self->add_package_symbol("&${method_name}" => $body); } -#sub reset_package_cache_flag { () } -#sub update_package_cache_flag { () } - ## ------------------------------------------------------------------ ## role construction ## ------------------------------------------------------------------ @@ -365,15 +362,15 @@ sub apply { if ($other->isa('Moose::Meta::Role')) { require Moose::Meta::Role::Application::ToRole; - return Moose::Meta::Role::Application::ToRole->new->apply($self, $other, @args); + return Moose::Meta::Role::Application::ToRole->new(@args)->apply($self, $other); } elsif ($other->isa('Moose::Meta::Class')) { require Moose::Meta::Role::Application::ToClass; - return Moose::Meta::Role::Application::ToClass->new->apply($self, $other, @args); + return Moose::Meta::Role::Application::ToClass->new(@args)->apply($self, $other); } else { require Moose::Meta::Role::Application::ToInstance; - return Moose::Meta::Role::Application::ToInstance->new->apply($self, $other, @args); + return Moose::Meta::Role::Application::ToInstance->new(@args)->apply($self, $other); } } diff --git a/lib/Moose/Meta/Role/Application.pm b/lib/Moose/Meta/Role/Application.pm index b6c8a6e..a71f65c 100644 --- a/lib/Moose/Meta/Role/Application.pm +++ b/lib/Moose/Meta/Role/Application.pm @@ -7,14 +7,14 @@ use metaclass; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -# no need to get fancy here ... -sub new { bless {} => (shift) } +sub new { (shift)->meta->new_object(@_) } sub apply { my $self = shift; $self->check_role_exclusions(@_); $self->check_required_methods(@_); + $self->check_required_attributes(@_); $self->apply_attributes(@_); $self->apply_methods(@_); @@ -28,6 +28,8 @@ sub apply { sub check_role_exclusions { die "Abstract Method" } sub check_required_methods { die "Abstract Method" } +sub check_required_attributes { die "Abstract Method" } + sub apply_attributes { die "Abstract Method" } sub apply_methods { die "Abstract Method" } sub apply_override_method_modifiers { die "Abstract Method" } @@ -61,9 +63,11 @@ This is the abstract base class for role applications. =item B +=item B + =item B -=item B +=item B =item B diff --git a/lib/Moose/Meta/Role/Application/RoleSummation.pm b/lib/Moose/Meta/Role/Application/RoleSummation.pm index 2bfb9f2..0c1bb79 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -52,6 +52,10 @@ sub check_required_methods { $c->add_required_methods(keys %all_required_methods); } +sub check_required_attributes { + +} + sub apply_attributes { my ($self, $c) = @_; @@ -182,9 +186,11 @@ bindings and 'disabling' the conflicting bindings =item B +=item B + =item B -=item B +=item B =item B diff --git a/lib/Moose/Meta/Role/Application/ToClass.pm b/lib/Moose/Meta/Role/Application/ToClass.pm index 03a0a94..3f757d9 100644 --- a/lib/Moose/Meta/Role/Application/ToClass.pm +++ b/lib/Moose/Meta/Role/Application/ToClass.pm @@ -73,6 +73,10 @@ sub check_required_methods { } } +sub check_required_attributes { + +} + sub apply_attributes { my ($self, $role, $class) = @_; foreach my $attribute_name ($role->get_attribute_list) { @@ -178,9 +182,11 @@ Moose::Meta::Role::Application::ToClass =item B +=item B + =item B -=item B +=item B =item B diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index 2caed5e..13fff10 100644 --- a/lib/Moose/Meta/Role/Application/ToRole.pm +++ b/lib/Moose/Meta/Role/Application/ToRole.pm @@ -39,6 +39,10 @@ sub check_required_methods { } } +sub check_required_attributes { + +} + sub apply_attributes { my ($self, $role1, $role2) = @_; foreach my $attribute_name ($role1->get_attribute_list) { @@ -149,9 +153,11 @@ Moose::Meta::Role::Application::ToRole =item B +=item B + =item B -=item B +=item B =item B diff --git a/lib/Moose/Spec/Role.pod b/lib/Moose/Spec/Role.pod index f9a7f62..16bf475 100644 --- a/lib/Moose/Spec/Role.pod +++ b/lib/Moose/Spec/Role.pod @@ -13,12 +13,42 @@ Moose::Spec::Role - Formal spec for Role behavior =item Excluded Roles +A role can have a list of excluded roles, these are basically +roles that they shouldn't be composed with. This is not just +direct composition either, but also "inherited" composition. + +This feature was taken from the Fortress language and is really +of most use when building a large set of role "building blocks" +some of which should never be used together. + =item Attributes +A roles attributes are similar to those of a class, except that +they are not actually applied. This means that methods that are +generated by an attributes accessor will not be generated in the +role, but only created once the role is applied to a class. + =item Methods +These are the methods defined within the role. Simple as that. + =item Required Methods +A role can require a consuming class (or role) to provide a +given method. Failure to do so for classes is a fatal error, +while for roles it simply passes on the method requirement to +the consuming role. + +=item Required Attributes + +Just as a role can require methods, it can also require attributes. +The requirement fufilling attribute must implement at least as much +as is required. That means, for instance, that if the role requires +that the attribute be readonly, then it must at least have a reader +and can also have a writer. It means that if the role requires that +the attribute be an ArrayRef, then it must either be an ArrayRef or +a subtype of an ArrayRef. + =item Overriden Methods The C and C keywords are allowed in roles, but @@ -33,16 +63,72 @@ can never have a I role. =item Method Modifiers +These are the C, C and C modifiers provided +in Moose classes. The difference here is that the modifiers are not +actually applied until the role is composed into a class (this is +just like attributes and the C keyword). + =back -=head2 Role to Role Composition Rules +=head2 Role Composition + +=head3 Composing into a Role + +=over 4 + +=item Excluded Roles + +=item Required Methods + +=item Required Attributes + +=item Attributes + +=item Methods + +=item Overriden methods + +=item Method Modifiers (before, around, after) + +=back -When a role is added to another role (using the C -keyword) the two roles are composed symmetrically. The -product of the composition is a third composite role. +=head3 Composing into a Class =over 4 +=item Excluded Roles + +=item Required Methods + +=item Required Attributes + +=item Attributes + +=item Methods + +=item Overriden methods + +=item Method Modifiers (before, around, after) + +=back + +=head3 Composing into a Instance + +=head2 Role Summation + +When multiple roles are added to another role (using the +C keyword) the roles are composed symmetrically. +The product of the composition is a composite role +(L). + +=over 4 + +=item Excluded Roles + +=item Required Methods + +=item Required Attributes + =item Attributes Attributes with the same name will conflict and are considered