MooseExtends.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 89 CC 9 SCAR 31.6
CC
9
Cov
0%
weave_section
56.0
_get_extends
12.0
BEGIN
2.0
CRAP 23.5
1 package Pod::Weaver::Section::MooseExtends;
2 # ABSTRACT: Add Pod::Weaver section with inherited classes (what I am extending) based on Moose OOP framework
3  
4 our $VERSION = '0.02';
5  
6  
7  
8 use strict;
9 use warnings;
10  
11 use Class::Inspector;
12 use Module::Load;
13 use Moose;
14 use Module::Metadata;
15  
16 with 'Pod::Weaver::Role::Section';
17  
18 use aliased 'Pod::Elemental::Element::Nested';
19 use aliased 'Pod::Elemental::Element::Pod5::Command';
20  
21 # This is implicit method of plugin for extending Pod::Weaver, cannot be called directly
22 sub weave_section {
23 my ( $self, $doc, $input ) = @_;
24  
25 my $filename = $input->{filename};
26  
27 return if $filename !~ m{\.pm$};
28  
29 my $info = Module::Metadata->new_from_file( $filename );
30 my $module = $info->name();
31
32 return unless $module;
33  
34 unless ( Class::Inspector->loaded( $module ) ) {
35 eval { local @INC = ( 'lib', @INC ); Module::Load::load $module };
36 print "$@" if $@; #warn
37 }
38  
39 return unless $module->can('meta');
40  
41 my @roles = sort
42 grep { $_ ne $module } $self->_get_extends($module);
43  
44 return unless @roles;
45  
46 my @pod = (
47 Command->new( {
48 command => 'over',
49 content => 4
50 } ),
51 (
52 map {
53 Command->new( {
54 command => 'item',
55 content => "* L<$_>",
56 } ),
57 } @roles
58 ),
59 Command->new( {
60 command => 'back',
61 content => ''
62 } )
63 );
64  
65 push @{ $doc->children },
66 Nested->new( {
67 type => 'command',
68 command => 'head1',
69 content => 'EXTENDS',
70 children => \@pod
71 } );
72 }
73  
74 # Private method for extracting extending classes through meta/superclasses
75 sub _get_extends {
76 my ( $self, $module ) = @_;
77  
78 return () unless $module->meta->can( 'superclasses' );
79  
80 my @extends = eval { $module->meta->superclasses };
81 print "Possibly harmless: $@" if $@;
82  
83 return @extends;
84 }
85  
86 __PACKAGE__->meta->make_immutable;
87 no Moose;
88 1;
89  
90 __END__