3 package Devel::REPL::Plugin::ShowClass;
4 # ABSTRACT: Dump classes initialized with Class::MOP
6 our $VERSION = '1.003029';
8 use Devel::REPL::Plugin;
9 use namespace::autoclean;
11 has 'metaclass_cache' => (
18 before 'eval' => sub {
20 $self->update_metaclass_cache;
28 foreach my $class (Class::MOP::get_all_metaclass_names()) {
29 unless (exists $self->metaclass_cache->{$class}) {
30 push @metas_to_show => Class::MOP::get_metaclass_by_name($class)
34 $self->display_class($_) foreach @metas_to_show;
36 $self->update_metaclass_cache;
39 sub update_metaclass_cache {
41 foreach my $class (Class::MOP::get_all_metaclass_names()) {
42 $self->metaclass_cache->{$class} = (
43 ("" . Class::MOP::get_metaclass_by_name($class))
49 my ($self, $meta) = @_;
50 $self->print('package ' . $meta->name . ";\n\n");
51 $self->print('extends (' . (join ", " => $meta->superclasses) . ");\n\n") if $meta->superclasses;
52 $self->print('with (' . (join ", " => map { $_->name } @{$meta->roles}) . ");\n\n") if $meta->can('roles');
53 foreach my $attr (map { $meta->get_attribute($_) } $meta->get_attribute_list) {
54 $self->print('has ' . $attr->name . " => (\n");
55 $self->print(' is => ' . $attr->_is_metadata . ",\n") if $attr->_is_metadata;
56 $self->print(' isa => ' . $attr->_isa_metadata . ",\n") if $attr->_isa_metadata;
57 $self->print(' required => ' . $attr->is_required . ",\n") if $attr->is_required;
58 $self->print(' lazy => ' . $attr->is_lazy . ",\n") if $attr->is_lazy;
59 $self->print(' coerce => ' . $attr->should_coerce . ",\n") if $attr->should_coerce;
60 $self->print(' is_weak_ref => ' . $attr->is_weak_ref . ",\n") if $attr->is_weak_ref;
61 $self->print(' auto_deref => ' . $attr->should_auto_deref . ",\n") if $attr->should_auto_deref;
65 foreach my $method_name ($meta->get_method_list) {
66 next if $method_name eq 'meta'
67 || $meta->get_method($method_name)->isa('Class::MOP::Method::Accessor');
68 $self->print("sub $method_name { ... }\n");