1 package Devel::REPL::Plugin::ShowClass;
2 use Devel::REPL::Plugin;
3 use namespace::clean -except => [ 'meta' ];
5 has 'metaclass_cache' => (
12 before 'eval' => sub {
14 $self->update_metaclass_cache;
22 foreach my $class (Class::MOP::get_all_metaclass_names()) {
23 unless (exists $self->metaclass_cache->{$class}) {
24 push @metas_to_show => Class::MOP::get_metaclass_by_name($class)
28 $self->display_class($_) foreach @metas_to_show;
30 $self->update_metaclass_cache;
33 sub update_metaclass_cache {
35 foreach my $class (Class::MOP::get_all_metaclass_names()) {
36 $self->metaclass_cache->{$class} = (
37 ("" . Class::MOP::get_metaclass_by_name($class))
43 my ($self, $meta) = @_;
44 $self->print('package ' . $meta->name . ";\n\n");
45 $self->print('extends (' . (join ", " => $meta->superclasses) . ");\n\n") if $meta->superclasses;
46 $self->print('with (' . (join ", " => map { $_->name } @{$meta->roles}) . ");\n\n") if $meta->can('roles');
47 foreach my $attr (map { $meta->get_attribute($_) } $meta->get_attribute_list) {
48 $self->print('has ' . $attr->name . " => (\n");
49 $self->print(' is => ' . $attr->_is_metadata . ",\n") if $attr->_is_metadata;
50 $self->print(' isa => ' . $attr->_isa_metadata . ",\n") if $attr->_isa_metadata;
51 $self->print(' required => ' . $attr->is_required . ",\n") if $attr->is_required;
52 $self->print(' lazy => ' . $attr->is_lazy . ",\n") if $attr->is_lazy;
53 $self->print(' coerce => ' . $attr->should_coerce . ",\n") if $attr->should_coerce;
54 $self->print(' is_weak_ref => ' . $attr->is_weak_ref . ",\n") if $attr->is_weak_ref;
55 $self->print(' auto_deref => ' . $attr->should_auto_deref . ",\n") if $attr->should_auto_deref;
59 foreach my $method_name ($meta->get_method_list) {
60 next if $method_name eq 'meta'
61 || $meta->get_method($method_name)->isa('Class::MOP::Method::Accessor');
62 $self->print("sub $method_name { ... }\n");
74 Devel::REPL::Plugin::ShowClass - Dump classes initialized with Class::MOP