| 1 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Dist::Zilla::Plugin::Test::CleanNamespaces; | ||||||||||
| 4 | # git description: v0.005-2-g77ab320 | ||||||||||
| 5 | 4 | $Dist::Zilla::Plugin::Test::CleanNamespaces::VERSION = '0.006'; | |||||||||
| 6 | # ABSTRACT: Generate a test to check that all namespaces are clean | ||||||||||
| 7 | # KEYWORDS: plugin testing namespaces clean dirty imports exports subroutines methods | ||||||||||
| 8 | # vim: set ts=8 sw=4 tw=78 et : | ||||||||||
| 9 | |||||||||||
| 10 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | with ( | |||||||||
| 12 | 'Dist::Zilla::Role::FileGatherer', | ||||||||||
| 13 | 'Dist::Zilla::Role::FileMunger', | ||||||||||
| 14 | 'Dist::Zilla::Role::TextTemplate', | ||||||||||
| 15 | 'Dist::Zilla::Role::PrereqSource', | ||||||||||
| 16 | ); | ||||||||||
| 17 | 4 | ▶ | use MooseX::Types::Stringlike 'Stringlike'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 4 | ▶ | use Moose::Util::TypeConstraints 'role_type'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 4 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 4 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 3 | ▶ | sub mvp_multivalue_args { qw(skips) } | ||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 23 | 3 | ▶ | sub mvp_aliases { return { skip => 'skips' } } | ||||||||
|
Subroutine
mvp_aliases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | has skips => ( | ||||||||||
| 26 | isa => 'ArrayRef[Str]', | ||||||||||
| 27 | traits => ['Array'], | ||||||||||
| 28 | handles => { skips => 'elements' }, | ||||||||||
| 29 | lazy => 1, | ||||||||||
| 30 | 2 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 4 | ); | |||||||||
| 32 | |||||||||||
| 33 | has filename => ( | ||||||||||
| 34 | is => 'ro', isa => Stringlike, | ||||||||||
| 35 | coerce => 1, | ||||||||||
| 36 | lazy => 1, | ||||||||||
| 37 | 3 | ▶ | default => sub { path('xt', 'author', 'clean-namespaces.t') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 4 | ); | |||||||||
| 39 | |||||||||||
| 40 | 7 | ▶ | sub _tcn_prereq { '0.15' } | ||||||||
|
Subroutine
_tcn_prereq: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | around dump_config => sub | ||||||||||
| 43 | 1 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 1 | my ($orig, $self) = @_; | |||||||||
| 45 | 1 | my $config = $self->$orig; | |||||||||
| 46 | |||||||||||
| 47 | 1 | $config->{+__PACKAGE__} = { | |||||||||
| 48 | skips => [ $self->skips ], | ||||||||||
| 49 | filename => $self->filename, | ||||||||||
| 50 | }; | ||||||||||
| 51 | |||||||||||
| 52 | 1 | return $config; | |||||||||
| 53 | 4 | }; | |||||||||
| 54 | |||||||||||
| 55 | sub register_prereqs | ||||||||||
| 56 | 3 | ▶ | { | ||||||||
|
Subroutine
register_prereqs: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 57 | 3 | my $self = shift; | |||||||||
| 58 | |||||||||||
| 59 | 3 | ▶ | $self->zilla->register_prereqs( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | { | ||||||||||
| 61 | type => 'requires', | ||||||||||
| 62 | phase => $self->filename =~ /^t/ ? 'test' : 'develop', | ||||||||||
| 63 | }, | ||||||||||
| 64 | 'Test::CleanNamespaces' => $self->_tcn_prereq, | ||||||||||
| 65 | ); | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 4 | has _file => ( | |||||||||
| 69 | is => 'rw', isa => role_type('Dist::Zilla::Role::File'), | ||||||||||
| 70 | ); | ||||||||||
| 71 | |||||||||||
| 72 | sub gather_files | ||||||||||
| 73 | 3 | ▶ | { | ||||||||
|
Subroutine
gather_files: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 74 | 3 | my $self = shift; | |||||||||
| 75 | |||||||||||
| 76 | 3 | require Dist::Zilla::File::InMemory; | |||||||||
| 77 | 3 | $self->add_file( $self->_file( | |||||||||
| 78 | Dist::Zilla::File::InMemory->new( | ||||||||||
| 79 | name => $self->filename, | ||||||||||
| 80 | content => <<'TEST', | ||||||||||
| 81 | use strict; | ||||||||||
| 82 | use warnings; | ||||||||||
| 83 | |||||||||||
| 84 | # this test was generated with {{ ref($plugin) . ' ' . ($plugin->VERSION || '<self>') }} | ||||||||||
| 85 | |||||||||||
| 86 | use Test::More 0.94; | ||||||||||
| 87 | use Test::CleanNamespaces {{ $tcn_prereq }}; | ||||||||||
| 88 | |||||||||||
| 89 | subtest all_namespaces_clean => sub {{ | ||||||||||
| 90 | $skips | ||||||||||
| 91 | ? "{\n namespaces_clean( | ||||||||||
| 92 | " . 'grep { my $mod = $_; not grep { $mod =~ $_ } ' . $skips . " } | ||||||||||
| 93 | Test::CleanNamespaces->find_modules\n );\n};" | ||||||||||
| 94 | : '{ all_namespaces_clean() };' | ||||||||||
| 95 | }} | ||||||||||
| 96 | |||||||||||
| 97 | done_testing; | ||||||||||
| 98 | TEST | ||||||||||
| 99 | )) | ||||||||||
| 100 | ); | ||||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | sub munge_file | ||||||||||
| 104 | 11 | ▶ | { | ||||||||
|
Subroutine
munge_file: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 105 | 11 | my ($self, $file) = @_; | |||||||||
| 106 | |||||||||||
| 107 | 11 | ▶ | return unless $file == $self->_file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | |||||||||||
| 109 | $file->content( | ||||||||||
| 110 | $self->fill_in_string( | ||||||||||
| 111 | $file->content, | ||||||||||
| 112 | { | ||||||||||
| 113 | dist => \($self->zilla), | ||||||||||
| 114 | plugin => \$self, | ||||||||||
| 115 | 3 | skips => \( join(', ', map { 'qr/' . $_ . '/' } $self->skips) ), | |||||||||
| 116 | tcn_prereq => \($self->_tcn_prereq), | ||||||||||
| 117 | } | ||||||||||
| 118 | ) | ||||||||||
| 119 | ); | ||||||||||
| 120 | |||||||||||
| 121 | 3 | return; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 125 | |||||||||||
| 126 | __END__ | ||||||||||