2 package Class::MOP::Object;
9 use Scalar::Util 'blessed';
14 require Class::MOP::Class;
15 Class::MOP::Class->initialize(blessed($_[0]) || $_[0]);
19 Class::MOP::class_of(shift)->new_object(@_);
23 # Cmon, how many times have you written
24 # the following code while debugging:
29 # It can get seriously annoying, so why
30 # not just do this ...
34 local $Data::Dumper::Maxdepth = shift || 1;
35 Data::Dumper::Dumper $self;
40 return blessed($self);
43 sub _is_compatible_with {
45 my ($other_name) = @_;
47 return $self->isa($other_name);
50 sub _can_be_made_compatible_with {
52 return !$self->_is_compatible_with(@_)
53 && defined($self->_get_compatible_metaclass(@_));
56 sub _make_compatible_with {
58 my ($other_name) = @_;
60 my $new_metaclass = $self->_get_compatible_metaclass($other_name);
62 confess "Can't make $self compatible with metaclass $other_name"
63 unless defined $new_metaclass;
65 # can't use rebless_instance here, because it might not be an actual
66 # subclass in the case of, e.g. moose role reconciliation
67 $new_metaclass->meta->_force_rebless_instance($self)
68 if blessed($self) ne $new_metaclass;
73 sub _get_compatible_metaclass {
75 my ($other_name) = @_;
77 return $self->_get_compatible_metaclass_by_subclassing($other_name)
78 || $self->_get_compatible_metaclass_by_role_reconciliation(@_);
81 sub _get_compatible_metaclass_by_subclassing {
83 my ($other_name) = @_;
84 my $meta_name = blessed($self) ? $self->_real_ref_name : $self;
86 if ($meta_name->isa($other_name)) {
89 elsif ($other_name->isa($meta_name)) {
96 sub _get_compatible_metaclass_by_role_reconciliation {
98 my ($other_name) = @_;
99 my $meta_name = blessed($self) ? $self->_real_ref_name : $self;
101 return unless Moose::Util::_classes_differ_by_roles_only(
102 $meta_name, $other_name
105 return Moose::Util::_reconcile_roles_for_metaclass(
106 $meta_name, $other_name
112 # ABSTRACT: Base class for metaclasses
120 This class is a very minimal base class for metaclasses.
124 This class provides a few methods which are useful in all metaclasses.
128 =item B<< Class::MOP::???->meta >>
130 This returns a L<Class::MOP::Class> object.
132 =item B<< $metaobject->dump($max_depth) >>
134 This method uses L<Data::Dumper> to dump the object. You can pass an
135 optional maximum depth, which will set C<$Data::Dumper::Maxdepth>. The
136 default maximum depth is 1.