| 1 | package Dist::Zilla::Plugin::Babble; | ||||||||||
| 2 | 1 | $Dist::Zilla::Plugin::Babble::VERSION = '0.004'; | |||||||||
| 3 | 1 | ▶ | use Carp 'croak'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use MooseX::Types::Moose qw/ArrayRef Str/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use MooseX::Types::Perl qw/StrictVersionStr/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use List::Util 'any'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | with 'Dist::Zilla::Role::FileMunger', | |||||||||
| 10 | 'Dist::Zilla::Role::FileFinderUser' => { | ||||||||||
| 11 | default_finders => [ ':InstallModules', ':ExecFiles' ], | ||||||||||
| 12 | }, | ||||||||||
| 13 | 'Dist::Zilla::Role::FileFinderUser' => { | ||||||||||
| 14 | method => 'found_test_files', | ||||||||||
| 15 | finder_arg_names => [ 'test_finder' ], | ||||||||||
| 16 | default_finders => [ ':TestFiles' ], | ||||||||||
| 17 | }, | ||||||||||
| 18 | 'Dist::Zilla::Role::FileFinderUser' => { | ||||||||||
| 19 | method => 'found_configure_files', | ||||||||||
| 20 | finder_arg_names => [ 'configure_finder' ], | ||||||||||
| 21 | default_finders => [], | ||||||||||
| 22 | }; | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 2 | ▶ | sub mvp_multivalue_args { | ||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 2 | return qw/files plugins/; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 2 | ▶ | sub mvp_aliases { | ||||||||
|
Subroutine
mvp_aliases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | return { | ||||||||||
| 31 | 2 | file => 'files', | |||||||||
| 32 | plugin => 'plugins', | ||||||||||
| 33 | }; | ||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | has files => ( | ||||||||||
| 37 | isa => ArrayRef[Str], | ||||||||||
| 38 | traits => ['Array'], | ||||||||||
| 39 | lazy => 1, | ||||||||||
| 40 | 2 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 1 | handles => { | |||||||||
| 42 | files => 'elements', | ||||||||||
| 43 | }, | ||||||||||
| 44 | ); | ||||||||||
| 45 | |||||||||||
| 46 | has extra_plugins => ( | ||||||||||
| 47 | isa => ArrayRef[Str], | ||||||||||
| 48 | traits => ['Array'], | ||||||||||
| 49 | lazy => 1, | ||||||||||
| 50 | 1 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 1 | handles => { | |||||||||
| 52 | extra_plugins => 'elements', | ||||||||||
| 53 | }, | ||||||||||
| 54 | ); | ||||||||||
| 55 | |||||||||||
| 56 | 1 | has plugins => ( | |||||||||
| 57 | isa => ArrayRef[Str], | ||||||||||
| 58 | traits => ['Array'], | ||||||||||
| 59 | lazy => 1, | ||||||||||
| 60 | builder => '_build_plugins', | ||||||||||
| 61 | handles => { | ||||||||||
| 62 | plugins => 'elements', | ||||||||||
| 63 | }, | ||||||||||
| 64 | ); | ||||||||||
| 65 | |||||||||||
| 66 | has filter_plugins => ( | ||||||||||
| 67 | isa => ArrayRef[Str], | ||||||||||
| 68 | traits => ['Array'], | ||||||||||
| 69 | lazy => 1, | ||||||||||
| 70 | 1 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 71 | 1 | handles => { | |||||||||
| 72 | filter_plugins => 'elements', | ||||||||||
| 73 | }, | ||||||||||
| 74 | ); | ||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | 1 | my %supported_since = ( | |||||||||
| 78 | '::CoreSignatures' => '5.028', | ||||||||||
| 79 | '::State' => '5.010', | ||||||||||
| 80 | '::DefinedOr' => '5.010', | ||||||||||
| 81 | '::PostfixDeref' => '5.020', | ||||||||||
| 82 | '::SubstituteAndReturn' => '5.014', | ||||||||||
| 83 | '::Ellipsis' => '5.012', | ||||||||||
| 84 | '::PackageBlock' => '5.014', | ||||||||||
| 85 | '::PackageVersion' => '5.012', | ||||||||||
| 86 | ); | ||||||||||
| 87 | |||||||||||
| 88 | 1 | ▶ | sub _build_plugins { | ||||||||
|
Subroutine
_build_plugins: called CC=1 SCAR=0.0
| |||||||||||
| 89 | 1 | my $self = shift; | |||||||||
| 90 | 1 | my @plugins = grep { $supported_since{$_} > $self->for_version } keys %supported_since; | |||||||||
| 91 | 0 | my %filter = map { $_ => 1 } $self->filter_plugins; | |||||||||
| 92 | 1 | @plugins = grep { not $filter{$_} } @plugins; | |||||||||
| 93 | 1 | push @plugins, $self->extra_plugins; | |||||||||
| 94 | 1 | return \@plugins; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 1 | has for_version => ( | |||||||||
| 98 | is => 'ro', | ||||||||||
| 99 | isa => StrictVersionStr, | ||||||||||
| 100 | default => '5.008', | ||||||||||
| 101 | ); | ||||||||||
| 102 | |||||||||||
| 103 | 1 | has transformer => ( | |||||||||
| 104 | is => 'ro', | ||||||||||
| 105 | init_arg => undef, | ||||||||||
| 106 | lazy => 1, | ||||||||||
| 107 | builder => '_build_transformer', | ||||||||||
| 108 | ); | ||||||||||
| 109 | |||||||||||
| 110 | 2 | ▶ | sub _build_transformer { | ||||||||
|
Subroutine
_build_transformer: called CC=2 SCAR=6.9
| |||||||||||
| 111 | 2 | my $self = shift; | |||||||||
| 112 | 2 | require Babble::PluginChain; | |||||||||
| 113 | 2 | my $pc = Babble::PluginChain->new; | |||||||||
| 114 | 2 | $pc->add_plugin($_) for $self->plugins; | |||||||||
| 115 | 2 | return $pc; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 2 | ▶ | sub get_files { | ||||||||
|
Subroutine
get_files: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 119 | 2 | my $self = shift; | |||||||||
| 120 | 2 | my @result = @{ $self->found_files }; | |||||||||
| 121 | 0 | push @result, grep { $_->name =~ /\.t/ } @{ $self->found_test_files }; | |||||||||
| 122 | 2 | return @result; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 2 | ▶ | sub munge_files { | ||||||||
|
Subroutine
munge_files: called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||
| 126 | 2 | my $self = shift; | |||||||||
| 127 | |||||||||||
| 128 | 2 | $self->log("Starting to babble source"); | |||||||||
| 129 | 0 | ▶ | if (my %filename = map { $_ => 1 } $self->files) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 0 | foreach my $file (@{ $self->zilla->files }) { | |||||||||
| 131 | 0 | ▶ | $self->munge_file($file) if $filename{$file->name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | } | ||||||||||
| 133 | } | ||||||||||
| 134 | else { | ||||||||||
| 135 | 2 | $self->munge_file($_) for $self->get_files;; | |||||||||
| 136 | } | ||||||||||
| 137 | 2 | $self->log("Finished babbling source"); | |||||||||
| 138 | |||||||||||
| 139 | 2 | return; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 2 | ▶ | sub munge_file { | ||||||||
|
Subroutine
munge_file: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 143 | 2 | my ($self, $file) = @_; | |||||||||
| 144 | 2 | my $content = $file->content; | |||||||||
| 145 | 2 | my $pc = $self->transformer; | |||||||||
| 146 | 2 | ▶ | eval { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 147 | 2 | $file->content($pc->transform_document($content)); | |||||||||
| 148 | 2 | 1; | |||||||||
| 149 | } or croak 'Could not munge ' . $file->name . ': ' . $@; | ||||||||||
| 150 | 2 | return; | |||||||||
| 151 | } | ||||||||||
| 152 | |||||||||||
| 153 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 154 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 155 | |||||||||||
| 156 | 1 | 'For ScienceĀ®'; | |||||||||
| 157 | |||||||||||
| 158 | # ABSTRACT: EXPERIMENTAL Automatic Babble substitution in Dist::Zilla | ||||||||||
| 159 | |||||||||||
| 160 | |||||||||||
| 161 | # vim: ts=4 sts=4 sw=4 noet : | ||||||||||
| 162 | |||||||||||
| 163 | __END__ | ||||||||||