2 package Class::MOP::Object;
8 use Scalar::Util 'blessed';
13 require Class::MOP::Class;
14 Class::MOP::Class->initialize(blessed($_[0]) || $_[0]);
18 Class::MOP::class_of(shift)->new_object(@_);
22 # Cmon, how many times have you written
23 # the following code while debugging:
28 # It can get seriously annoying, so why
29 # not just do this ...
33 local $Data::Dumper::Maxdepth = shift || 1;
34 Data::Dumper::Dumper $self;
39 return blessed($self);
42 sub _is_compatible_with {
44 my ($other_name) = @_;
46 return $self->isa($other_name);
49 sub _can_be_made_compatible_with {
51 return !$self->_is_compatible_with(@_)
52 && defined($self->_get_compatible_metaclass(@_));
55 sub _make_compatible_with {
57 my ($other_name) = @_;
59 my $new_metaclass = $self->_get_compatible_metaclass($other_name);
61 confess "Can't make $self compatible with metaclass $other_name"
62 unless defined $new_metaclass;
64 # can't use rebless_instance here, because it might not be an actual
65 # subclass in the case of, e.g. moose role reconciliation
66 $new_metaclass->meta->_force_rebless_instance($self)
67 if blessed($self) ne $new_metaclass;
72 sub _get_compatible_metaclass {
74 my ($other_name) = @_;
76 return $self->_get_compatible_metaclass_by_subclassing($other_name);
79 sub _get_compatible_metaclass_by_subclassing {
81 my ($other_name) = @_;
82 my $meta_name = blessed($self) ? $self->_real_ref_name : $self;
84 if ($meta_name->isa($other_name)) {
87 elsif ($other_name->isa($meta_name)) {
102 Class::MOP::Object - Base class for metaclasses
106 This class is a very minimal base class for metaclasses.
110 This class provides a few methods which are useful in all metaclasses.
114 =item B<< Class::MOP::???->meta >>
116 This returns a L<Class::MOP::Class> object.
118 =item B<< $metaobject->dump($max_depth) >>
120 This method uses L<Data::Dumper> to dump the object. You can pass an
121 optional maximum depth, which will set C<$Data::Dumper::Maxdepth>. The
122 default maximum depth is 1.