2 package Class::MOP::Object;
8 use Scalar::Util 'blessed';
10 our $AUTHORITY = 'cpan:STEVAN';
15 require Class::MOP::Class;
16 Class::MOP::Class->initialize(blessed($_[0]) || $_[0]);
20 Class::MOP::class_of(shift)->new_object(@_);
24 # Cmon, how many times have you written
25 # the following code while debugging:
30 # It can get seriously annoying, so why
31 # not just do this ...
35 local $Data::Dumper::Maxdepth = shift || 1;
36 Data::Dumper::Dumper $self;
41 return blessed($self);
44 sub _is_compatible_with {
46 my ($other_name) = @_;
48 return $self->isa($other_name);
51 sub _can_be_made_compatible_with {
53 return !$self->_is_compatible_with(@_)
54 && defined($self->_get_compatible_metaclass(@_));
57 sub _make_compatible_with {
59 my ($other_name) = @_;
61 my $new_metaclass = $self->_get_compatible_metaclass($other_name);
63 confess "Can't make $self compatible with metaclass $other_name"
64 unless defined $new_metaclass;
66 # can't use rebless_instance here, because it might not be an actual
67 # subclass in the case of, e.g. moose role reconciliation
68 $new_metaclass->meta->_force_rebless_instance($self)
69 if blessed($self) ne $new_metaclass;
74 sub _get_compatible_metaclass {
76 my ($other_name) = @_;
78 return $self->_get_compatible_metaclass_by_subclassing($other_name);
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)) {
104 Class::MOP::Object - Base class for metaclasses
108 This class is a very minimal base class for metaclasses.
112 This class provides a few methods which are useful in all metaclasses.
116 =item B<< Class::MOP::???->meta >>
118 This returns a L<Class::MOP::Class> object.
120 =item B<< $metaobject->dump($max_depth) >>
122 This method uses L<Data::Dumper> to dump the object. You can pass an
123 optional maximum depth, which will set C<$Data::Dumper::Maxdepth>. The
124 default maximum depth is 1.