File Coverage

blib/lib/Devel/REPL/Plugin/ShowClass.pm
Criterion Covered Total %
statement 12 38 31.5
branch 0 20 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 0 2 0.0
total 16 69 23.1


line stmt bran cond sub pod time code
1 2     2   1899 use strict;
  2         3  
  2         67  
2 2     2   9 use warnings;
  2         5  
  2         114  
3             # ABSTRACT: Dump classes initialized with Class::MOP
4              
5             our $VERSION = '1.003029';
6              
7             use Devel::REPL::Plugin;
8 2     2   10 use namespace::autoclean;
  2         4  
  2         12  
9 2     2   8185  
  2         4  
  2         17  
10             has 'metaclass_cache' => (
11             is => 'ro',
12             isa => 'HashRef',
13             lazy => 1,
14             default => sub {{}}
15             );
16              
17             before 'eval' => sub {
18             my $self = shift;
19             $self->update_metaclass_cache;
20             };
21              
22             after 'eval' => sub {
23             my $self = shift;
24              
25             my @metas_to_show;
26              
27             foreach my $class (Class::MOP::get_all_metaclass_names()) {
28             unless (exists $self->metaclass_cache->{$class}) {
29             push @metas_to_show => Class::MOP::get_metaclass_by_name($class)
30             }
31             }
32              
33             $self->display_class($_) foreach @metas_to_show;
34              
35             $self->update_metaclass_cache;
36             };
37              
38             my $self = shift;
39             foreach my $class (Class::MOP::get_all_metaclass_names()) {
40 0     0 0   $self->metaclass_cache->{$class} = (
41 0           ("" . Class::MOP::get_metaclass_by_name($class))
42 0           );
43             }
44             }
45              
46             my ($self, $meta) = @_;
47             $self->print('package ' . $meta->name . ";\n\n");
48             $self->print('extends (' . (join ", " => $meta->superclasses) . ");\n\n") if $meta->superclasses;
49 0     0 0   $self->print('with (' . (join ", " => map { $_->name } @{$meta->roles}) . ");\n\n") if $meta->can('roles');
50 0           foreach my $attr (map { $meta->get_attribute($_) } $meta->get_attribute_list) {
51 0 0         $self->print('has ' . $attr->name . " => (\n");
52 0 0         $self->print(' is => ' . $attr->_is_metadata . ",\n") if $attr->_is_metadata;
  0            
  0            
53 0           $self->print(' isa => ' . $attr->_isa_metadata . ",\n") if $attr->_isa_metadata;
  0            
54 0           $self->print(' required => ' . $attr->is_required . ",\n") if $attr->is_required;
55 0 0         $self->print(' lazy => ' . $attr->is_lazy . ",\n") if $attr->is_lazy;
56 0 0         $self->print(' coerce => ' . $attr->should_coerce . ",\n") if $attr->should_coerce;
57 0 0         $self->print(' is_weak_ref => ' . $attr->is_weak_ref . ",\n") if $attr->is_weak_ref;
58 0 0         $self->print(' auto_deref => ' . $attr->should_auto_deref . ",\n") if $attr->should_auto_deref;
59 0 0         $self->print(");\n");
60 0 0         $self->print("\n");
61 0 0         }
62 0           foreach my $method_name ($meta->get_method_list) {
63 0           next if $method_name eq 'meta'
64             || $meta->get_method($method_name)->isa('Class::MOP::Method::Accessor');
65 0           $self->print("sub $method_name { ... }\n");
66 0 0 0       $self->print("\n");
67             }
68 0           $self->print("1;\n");
69 0           }
70              
71 0           1;
72              
73              
74             =pod
75              
76             =encoding UTF-8
77              
78             =head1 NAME
79              
80             Devel::REPL::Plugin::ShowClass - Dump classes initialized with Class::MOP
81              
82             =head1 VERSION
83              
84             version 1.003029
85              
86             =head1 SUPPORT
87              
88             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-REPL>
89             (or L<bug-Devel-REPL@rt.cpan.org|mailto:bug-Devel-REPL@rt.cpan.org>).
90              
91             There is also an irc channel available for users of this distribution, at
92             L<C<#devel> on C<irc.perl.org>|irc://irc.perl.org/#devel-repl>.
93              
94             =head1 AUTHOR
95              
96             Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>)
97              
98             =head1 COPYRIGHT AND LICENCE
99              
100             This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>).
101              
102             This is free software; you can redistribute it and/or modify it under
103             the same terms as the Perl 5 programming language system itself.
104              
105             =cut