2 package Class::MOP::Object;
8 use Scalar::Util 'blessed';
10 our $VERSION = '1.12';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
17 require Class::MOP::Class;
18 Class::MOP::Class->initialize(blessed($_[0]) || $_[0]);
22 Class::MOP::class_of(shift)->new_object(@_);
26 # Cmon, how many times have you written
27 # the following code while debugging:
32 # It can get seriously annoying, so why
33 # not just do this ...
37 local $Data::Dumper::Maxdepth = shift || 1;
38 Data::Dumper::Dumper $self;
43 return blessed($self);
46 sub _is_compatible_with {
48 my ($other_name) = @_;
50 return $self->isa($other_name);
53 sub _can_be_made_compatible_with {
55 return !$self->_is_compatible_with(@_)
56 && defined($self->_get_compatible_metaclass(@_));
59 sub _make_compatible_with {
61 my ($other_name) = @_;
63 my $new_metaclass = $self->_get_compatible_metaclass($other_name);
65 confess "Can't make $self compatible with metaclass $other_name"
66 unless defined $new_metaclass;
68 # can't use rebless_instance here, because it might not be an actual
69 # subclass in the case of, e.g. moose role reconciliation
70 $new_metaclass->meta->_force_rebless_instance($self)
71 if blessed($self) ne $new_metaclass;
76 sub _get_compatible_metaclass {
78 my ($other_name) = @_;
80 return $self->_get_compatible_metaclass_by_subclassing($other_name);
83 sub _get_compatible_metaclass_by_subclassing {
85 my ($other_name) = @_;
86 my $meta_name = blessed($self) ? $self->_real_ref_name : $self;
88 if ($meta_name->isa($other_name)) {
91 elsif ($other_name->isa($meta_name)) {
106 Class::MOP::Object - Base class for metaclasses
110 This class is a very minimal base class for metaclasses.
114 This class provides a few methods which are useful in all metaclasses.
118 =item B<< Class::MOP::???->meta >>
120 This returns a L<Class::MOP::Class> object.
122 =item B<< $metaobject->dump($max_depth) >>
124 This method uses L<Data::Dumper> to dump the object. You can pass an
125 optional maximum depth, which will set C<$Data::Dumper::Maxdepth>. The
126 default maximum depth is 1.
132 Stevan Little E<lt>stevan@iinteractive.comE<gt>
134 =head1 COPYRIGHT AND LICENSE
136 Copyright 2006-2010 by Infinity Interactive, Inc.
138 L<http://www.iinteractive.com>
140 This library is free software; you can redistribute it and/or modify
141 it under the same terms as Perl itself.