my %options = @_;
(blessed($self))
|| confess "Can only clone an instance";
- return bless { %{$self}, %options } => blessed($self);
+ return bless { %{$self}, %options } => ref($self);
}
sub initialize_instance_slot {
);
}
else {
- confess(blessed($instance)." does not support builder method '". $self->{'builder'} ."' for attribute '" . $self->name . "'");
+ confess(ref($instance)." does not support builder method '". $self->{'builder'} ."' for attribute '" . $self->name . "'");
}
}
}
sub associated_class { $_[0]->{'associated_class'} }
sub associated_methods { $_[0]->{'associated_methods'} }
-sub has_accessor { defined($_[0]->{'accessor'}) ? 1 : 0 }
-sub has_reader { defined($_[0]->{'reader'}) ? 1 : 0 }
-sub has_writer { defined($_[0]->{'writer'}) ? 1 : 0 }
-sub has_predicate { defined($_[0]->{'predicate'}) ? 1 : 0 }
-sub has_clearer { defined($_[0]->{'clearer'}) ? 1 : 0 }
-sub has_builder { defined($_[0]->{'builder'}) ? 1 : 0 }
-sub has_init_arg { defined($_[0]->{'init_arg'}) ? 1 : 0 }
-sub has_default { defined($_[0]->{'default'}) ? 1 : 0 }
-sub has_initializer { defined($_[0]->{'initializer'}) ? 1 : 0 }
+sub has_accessor { defined($_[0]->{'accessor'}) }
+sub has_reader { defined($_[0]->{'reader'}) }
+sub has_writer { defined($_[0]->{'writer'}) }
+sub has_predicate { defined($_[0]->{'predicate'}) }
+sub has_clearer { defined($_[0]->{'clearer'}) }
+sub has_builder { defined($_[0]->{'builder'}) }
+sub has_init_arg { defined($_[0]->{'init_arg'}) }
+sub has_default { defined($_[0]->{'default'}) }
+sub has_initializer { defined($_[0]->{'initializer'}) }
sub accessor { $_[0]->{'accessor'} }
sub reader { $_[0]->{'reader'} }
sub set_initial_value {
my ($self, $instance, $value) = @_;
$self->_set_initial_slot_value(
- Class::MOP::Class->initialize(blessed($instance))->get_meta_instance,
+ Class::MOP::Class->initialize(ref($instance))->get_meta_instance,
$instance,
$value
);
sub set_value {
my ($self, $instance, $value) = @_;
- Class::MOP::Class->initialize(blessed($instance))
+ Class::MOP::Class->initialize(ref($instance))
->get_meta_instance
->set_slot_value($instance, $self->name, $value);
}
sub get_value {
my ($self, $instance) = @_;
- Class::MOP::Class->initialize(blessed($instance))
+ Class::MOP::Class->initialize(ref($instance))
->get_meta_instance
->get_slot_value($instance, $self->name);
}
sub has_value {
my ($self, $instance) = @_;
- Class::MOP::Class->initialize(blessed($instance))
+ Class::MOP::Class->initialize(ref($instance))
->get_meta_instance
->is_slot_initialized($instance, $self->name);
}
sub clear_value {
my ($self, $instance) = @_;
- Class::MOP::Class->initialize(blessed($instance))
+ Class::MOP::Class->initialize(ref($instance))
->get_meta_instance
->deinitialize_slot($instance, $self->name);
}
}
my $method = $class->get_method($accessor);
$class->remove_method($accessor)
- if (blessed($method) && $method->isa('Class::MOP::Method::Accessor'));
+ if (ref($method) && $method->isa('Class::MOP::Method::Accessor'));
};
sub remove_accessors {
# we need to deal with the possibility
# of class immutability here, and then
# get the name of the class appropriately
- $class = (blessed($class)
+ $class = (ref($class)
? ($class->is_immutable
? $class->get_mutable_metaclass_name()
- : blessed($class))
+ : ref($class))
: $class);
# now create the metaclass
my $self = shift;
# this is always okay ...
- return if blessed($self) eq 'Class::MOP::Class' &&
+ return if ref($self) eq 'Class::MOP::Class' &&
$self->instance_metaclass eq 'Class::MOP::Instance';
my @class_list = $self->linearized_isa;
# get the name of the class appropriately
my $meta_type = ($meta->is_immutable
? $meta->get_mutable_metaclass_name()
- : blessed($meta));
+ : ref($meta));
($self->isa($meta_type))
- || confess $self->name . "->meta => (" . (blessed($self)) . ")" .
+ || confess $self->name . "->meta => (" . (ref($self)) . ")" .
" is not compatible with the " .
$class_name . "->meta => (" . ($meta_type) . ")";
# NOTE:
sub is_anon_class {
my $self = shift;
no warnings 'uninitialized';
- $self->name =~ /^$ANON_CLASS_PREFIX/ ? 1 : 0;
+ $self->name =~ /^$ANON_CLASS_PREFIX/;
}
sub create_anon_class {
# FIXME totally lame
$meta->add_method('meta' => sub {
- $class->initialize(blessed($_[0]) || $_[0]);
+ $class->initialize(ref($_[0]) || $_[0]);
});
$meta->superclasses(@{$options{superclasses}})
my $class = shift;
my $instance = shift;
(blessed($instance) && $instance->isa($class->name))
- || confess "You must pass an instance of the metaclass (" . $class->name . "), not ($instance)";
+ || confess "You must pass an instance of the metaclass (" . (ref $class ? $class->name : $class) . "), not ($instance)";
# NOTE:
# we need to protect the integrity of the
$old_metaclass = $instance->meta;
}
else {
- $old_metaclass = $self->initialize(blessed($instance));
+ $old_metaclass = $self->initialize(ref($instance));
}
my $meta_instance = $self->get_meta_instance();
my ($self, $attribute_name) = @_;
(defined $attribute_name && $attribute_name)
|| confess "You must define an attribute name";
- exists $self->get_attribute_map->{$attribute_name} ? 1 : 0;
+ exists $self->get_attribute_map->{$attribute_name};
}
sub get_attribute {
sub get_immutable_transformer {
my $self = shift;
if( $self->is_mutable ){
- my $class = blessed $self || $self;
+ my $class = ref $self || $self;
return $IMMUTABLE_TRANSFORMERS{$class} ||= $self->create_immutable_transformer;
}
confess "unable to find transformer for immutable class"