);
push @initial_value, (
- '$attrs->[' . $idx . ']->set_initial_value(',
+ '$attrs[' . $idx . ']->set_initial_value(',
'$instance,',
$attr->_inline_instance_get('$instance'),
');',
my @initial_value = $attr->_inline_set_value('$instance', $default);
push @initial_value, (
- '$attrs->[' . $idx . ']->set_initial_value(',
+ '$attrs[' . $idx . ']->set_initial_value(',
'$instance,',
$attr->_inline_instance_get('$instance'),
');',
# in which case we can just deal with them
# in the code we eval.
if ($attr->is_default_a_coderef) {
- return '$defaults->[' . $index . ']->($instance)';
+ return '$defaults[' . $index . ']->($instance)';
}
else {
- return '$defaults->[' . $index . ']';
+ return '$defaults[' . $index . ']';
}
}
elsif ($attr->has_builder) {
my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes;
- my $defaults = [map { $_->default } @attrs];
+ my @defaults = map { $_->default } @attrs;
return {
- '$defaults' => \$defaults,
+ '@defaults' => \@defaults,
};
}
}
}
+sub _method_lookup_order {
+ return (shift->linearized_isa, 'UNIVERSAL');
+}
+
## Methods
{
my ($self, $method_name) = @_;
(defined $method_name && length $method_name)
|| confess "You must define a method name to find";
- foreach my $class ($self->linearized_isa, 'UNIVERSAL') {
+ foreach my $class ($self->_method_lookup_order) {
my $method = Class::MOP::Class->initialize($class)->get_method($method_name);
return $method if defined $method;
}
my $self = shift;
my %methods;
- for my $class ( 'UNIVERSAL', reverse $self->linearized_isa ) {
+ for my $class ( reverse $self->_method_lookup_order ) {
my $meta = Class::MOP::Class->initialize($class);
$methods{ $_->name } = $_ for $meta->_get_local_methods;
sub get_all_method_names {
my $self = shift;
- my %uniq;
-
- return
- grep { !$uniq{$_}++ }
- map { Class::MOP::Class->initialize($_)->get_method_list }
- $self->linearized_isa, 'UNIVERSAL';
+ map { $_->name } $self->get_all_methods;
}
sub find_all_methods_by_name {
(defined $method_name && length $method_name)
|| confess "You must define a method name to find";
my @methods;
- foreach my $class ($self->linearized_isa, 'UNIVERSAL') {
+ foreach my $class ($self->_method_lookup_order) {
# fetch the meta-class ...
my $meta = Class::MOP::Class->initialize($class);
push @methods => {
my ($self, $method_name) = @_;
(defined $method_name && length $method_name)
|| confess "You must define a method name to find";
- my @cpl = ($self->linearized_isa, 'UNIVERSAL');
+ my @cpl = ($self->_method_lookup_order);
shift @cpl; # discard ourselves
foreach my $class (@cpl) {
my $method = Class::MOP::Class->initialize($class)->get_method($method_name);
sub make_immutable {
my ( $self, @args ) = @_;
- return unless $self->is_mutable;
+ return $self unless $self->is_mutable;
my ($file, $line) = (caller)[1..2];
=back
+=head2 Overload introspection and creation
+
+These methods provide an API to the core L<overload> functionality.
+
+=over 4
+
+=item B<< $metaclass->is_overloaded >>
+
+Returns true if overloading is enabled for this class. Corresponds to
+L<overload::Overloaded|overload/Public Functions>.
+
+=item B<< $metaclass->get_overloaded_operator($op) >>
+
+Returns the L<Class::MOP::Method::Overload> object corresponding to the
+operator named C<$op>, if one exists for this class.
+
+=item B<< $metaclass->has_overloaded_operator($op) >>
+
+Returns whether or not the operator C<$op> is overloaded for this class.
+
+=item B<< $metaclass->get_overload_list >>
+
+Returns a list of operator names which have been overloaded (see
+L<overload/Overloadable Operations> for the list of valid operator names).
+
+=item B<< $metaclass->get_all_overloaded_operators >>
+
+Returns a list of L<Class::MOP::Method::Overload> objects corresponding to the
+operators that have been overloaded.
+
+=item B<< $metaclass->add_overloaded_operator($op, $impl) >>
+
+Overloads the operator C<$op> for this class, with the implementation C<$impl>.
+C<$impl> can be either a coderef or a method name. Corresponds to
+C<< use overload $op => $impl; >>
+
+=item B<< $metaclass->remove_overloaded_operator($op) >>
+
+Remove overloading for operator C<$op>. Corresponds to C<< no overload $op; >>
+
+=back
+
=head2 Class Immutability
Making a class immutable "freezes" the class definition. You can no
=item B<< $metaclass->make_immutable(%options) >>
This method will create an immutable transformer and use it to make
-the class and its metaclass object immutable.
+the class and its metaclass object immutable, and returns true
+(you should not rely on the details of this value apart from its truth).
This method accepts the following options: