| 1 | package Pod::Knit; | ||||||||||
| 2 | 13 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | # ABSTRACT: Stitches together POD documentation | ||||||||||
| 4 | 13 | $Pod::Knit::VERSION = '0.0.1'; | |||||||||
| 5 | |||||||||||
| 6 | 13 | ▶ | use 5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 13 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 13 | ▶ | use YAML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 13 | ▶ | use List::Util qw/ reduce /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 13 | ▶ | use Pod::Knit::Document; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 13 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 13 | ▶ | use experimental 'signatures', 'postderef'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | has config_file => ( | ||||||||||
| 22 | isa => 'Str', | ||||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | lazy => 1, | ||||||||||
| 25 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 26 | 0 | ▶ | -f 'knit.yml' ? 'knit.yml' : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | }, | ||||||||||
| 28 | 13 | ); | |||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | has config => ( | ||||||||||
| 32 | is => 'ro', | ||||||||||
| 33 | lazy => 1, | ||||||||||
| 34 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 0 | my $self = shift; | |||||||||
| 36 | |||||||||||
| 37 | 0 | YAML::LoadFile($self->config_file); | |||||||||
| 38 | }, | ||||||||||
| 39 | 13 | ); | |||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | has stash => ( | ||||||||||
| 43 | is => 'ro', | ||||||||||
| 44 | lazy => 1, | ||||||||||
| 45 | 5 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||
| 46 | $_[0]->config->{stash} || {} | ||||||||||
| 47 | 5 | ▶ | }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 13 | ); | |||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | has plugins => ( | ||||||||||
| 52 | traits => [ 'Array' ], | ||||||||||
| 53 | is => 'ro', | ||||||||||
| 54 | lazy => 1, | ||||||||||
| 55 | 6 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||
| 56 | 6 | my $self = shift; | |||||||||
| 57 | |||||||||||
| 58 | 6 | my @plugins; | |||||||||
| 59 | 6 | ▶ | if( my $plugins = $self->config->{plugins} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 5 | for my $p ( @$plugins ) { | |||||||||
| 61 | 12 | ▶ | my( $plugin, $args ) = ref $p ? %$p : ( $p ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | 12 | $plugin = 'Pod::Knit::Plugin::' . $plugin; | |||||||||
| 64 | |||||||||||
| 65 | 13 | ▶ | use Module::Runtime qw/ use_module /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 12 | use_module( $plugin ); | |||||||||
| 67 | |||||||||||
| 68 | 12 | push @plugins, $plugin->new( | |||||||||
| 69 | stash => $self->stash, | ||||||||||
| 70 | %$args, knit => $self ); | ||||||||||
| 71 | } | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 6 | \@plugins; | |||||||||
| 75 | }, | ||||||||||
| 76 | 13 | handles => { | |||||||||
| 77 | all_plugins => 'elements', | ||||||||||
| 78 | }, | ||||||||||
| 79 | ); | ||||||||||
| 80 | |||||||||||
| 81 | 6 | ▶ | sub munging_plugins ($self) { | ||||||||
|
Subroutine
munging_plugins: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 82 | 6 | grep { $_->can( 'munge' ) } $self->all_plugins; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | 6 | ▶ | sub munge_document($self,@rest) { | ||||||||
|
Subroutine
munge_document: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 87 | 6 | ▶ | my( $doc ) = ( @rest == 1 ) ? @rest : ( Pod::Knit::Document->new( knit => $self, @rest ) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 6 | ▶ | return reduce { $b->munge($a->clone) } $doc, $self->munging_plugins; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 13 | 1; | |||||||||
| 92 | |||||||||||
| 93 | __END__ | ||||||||||