use Class::MOP;
use Carp 'confess';
-use Scalar::Util 'weaken', 'blessed';
+use Scalar::Util 'weaken', 'blessed', 'reftype';
-our $VERSION = '0.05';
+our $VERSION = '0.06';
use base 'Class::MOP::Class';
my ($self, $role_name) = @_;
(defined $role_name)
|| confess "You must supply a role name to look for";
- foreach my $role (@{$self->roles}) {
- return 1 if $role->does_role($role_name);
+ foreach my $class ($self->class_precedence_list) {
+ foreach my $role (@{$class->meta->roles}) {
+ return 1 if $role->does_role($role_name);
+ }
+ }
+ return 0;
+}
+
+sub excludes_role {
+ my ($self, $role_name) = @_;
+ (defined $role_name)
+ || confess "You must supply a role name to look for";
+ foreach my $class ($self->class_precedence_list) {
+ foreach my $role (@{$class->meta->roles}) {
+ return 1 if $role->excludes_role($role_name);
+ }
}
return 0;
}
sub construct_instance {
my ($class, %params) = @_;
my $meta_instance = $class->get_meta_instance;
+ # FIXME:
+ # the code below is almost certainly incorrect
+ # but this is foreign inheritence, so we might
+ # have to kludge it in the end.
my $instance = $params{'__INSTANCE__'} || $meta_instance->create_instance();
foreach my $attr ($class->compute_all_applicable_attributes()) {
$attr->initialize_instance_slot($meta_instance, $instance, \%params)
return $self->SUPER::has_method($method_name);
}
-
sub add_override_method_modifier {
my ($self, $name, $method, $_super_package) = @_;
+ (!$self->has_method($name))
+ || confess "Cannot add an override method if a local method is already present";
# need this for roles ...
$_super_package ||= $self->name;
my $super = $self->find_next_method_by_name($name);
sub add_augment_method_modifier {
my ($self, $name, $method) = @_;
+ (!$self->has_method($name))
+ || confess "Cannot add an augment method if a local method is already present";
my $super = $self->find_next_method_by_name($name);
(defined $super)
|| confess "You cannot augment '$name' because it has no super method";
not only check it's local roles, but ask them as well in order to
cascade down the role hierarchy.
+=item B<excludes_role ($role_name)>
+
+This will test if this class C<excludes> a given C<$role_name>. It will
+not only check it's local roles, but ask them as well in order to
+cascade down the role hierarchy.
+
+=item B<add_attribute $attr_name, %params>
+
+This method does the same thing as L<Class::MOP::Class/add_attribute>, but adds
+suport for delegation.
+
+=back
+
+=head1 INTERNAL METHODS
+
+=over 4
+
+=item compute_delegation
+
+=item generate_delegation_list
+
+=item generate_delgate_method
+
+=item get_delegatable_methods
+
+=item filter_delegations
+
=back
=head1 BUGS
it under the same terms as Perl itself.
=cut
+