File Coverage

blib/lib/EPublisher/Source/Plugin/Module.pm
Criterion Covered Total %
statement 39 39 100.0
branch 14 14 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 1 1 100.0
total 64 64 100.0


line stmt bran cond sub pod time code
1             package EPublisher::Source::Plugin::Module;
2              
3             # ABSTRACT: Module source plugin
4              
5 3     3   56229 use strict;
  3         14  
  3         85  
6 3     3   14 use warnings;
  3         4  
  3         85  
7              
8 3     3   1435 use Module::Info;
  3         18818  
  3         85  
9              
10 3     3   22 use File::Basename;
  3         6  
  3         180  
11              
12 3     3   1332 use EPublisher::Source::Base;
  3         9  
  3         91  
13 3     3   1200 use EPublisher::Utils::PPI qw(extract_pod);
  3         11  
  3         925  
14              
15             our @ISA = qw( EPublisher::Source::Base );
16              
17             our $VERSION = 0.05;
18              
19             sub load_source{
20 10     10 1 856 my ($self, $name) = @_;
21            
22 10         28 my $options = $self->_config;
23 10   100     75 my $module = $name // $options->{name};
24            
25 10 100       33 if ( !defined $module ) {
26 1         2 $self->publisher->debug( '400: No module defined' );
27 1         4 return;
28             }
29              
30 9 100       12 my @my_inc = @{ $options->{lib} || [] };
  9         34  
31            
32 9         53 my $mod = Module::Info->new_from_module( $module, @my_inc );
33              
34 9 100       1304 if ( !$mod ) {
35 2         7 $self->publisher->debug( '400: Cannot find module' );
36 2         7 return;
37             }
38              
39 7         31 my $pod = extract_pod( $mod->file, $self->_config );
40 7         61211 my $filename = File::Basename::basename( $mod->file );
41 7         341 my $title = $module;
42              
43 7 100       33 $options->{title} = '' if !defined $options->{title};
44              
45 7 100       33 if ( $options->{title} eq 'pod' ) {
    100          
46 2         8 ($title) = $pod =~ m{ =head1 \s+ (.*) }x;
47 2 100       7 $title = '' if !defined $title;
48             }
49             elsif ( length $options->{title} ) {
50 1         2 $title = $options->{title};
51             }
52              
53 7         74 return { pod => $pod, filename => $filename, title => $title };
54             }
55              
56             1;
57              
58             __END__