| 1 | package Dist::Zilla::Plugin::Test::TidyAll; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use namespace::autoclean; | ||
| 6 | |||
| 7 | our $VERSION = '0.04'; | ||
| 8 | |||
| 9 | use B; | ||
| 10 | use Dist::Zilla::File::InMemory; | ||
| 11 | |||
| 12 | use Moose; | ||
| 13 | |||
| 14 | has conf_file => ( | ||
| 15 | is => 'ro', | ||
| 16 | isa => 'Str', | ||
| 17 | predicate => '_has_conf_file', | ||
| 18 | ); | ||
| 19 | |||
| 20 | has verbose => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'Bool', | ||
| 23 | default => 0, | ||
| 24 | ); | ||
| 25 | |||
| 26 | has jobs => ( | ||
| 27 | is => 'ro', | ||
| 28 | isa => 'Int', | ||
| 29 | default => 1, | ||
| 30 | ); | ||
| 31 | |||
| 32 | has minimum_perl => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => 'Str', | ||
| 35 | predicate => '_has_minimum_perl', | ||
| 36 | ); | ||
| 37 | |||
| 38 | with qw( | ||
| 39 | Dist::Zilla::Role::FileGatherer | ||
| 40 | Dist::Zilla::Role::PrereqSource | ||
| 41 | ); | ||
| 42 | |||
| 43 | sub register_prereqs { | ||
| 44 | my ($self) = @_; | ||
| 45 | |||
| 46 | $self->zilla->register_prereqs( | ||
| 47 | { | ||
| 48 | type => 'requires', | ||
| 49 | phase => 'develop', | ||
| 50 | }, | ||
| 51 | 'Test::Code::TidyAll' => '0.50', | ||
| 52 | 'Test::More' => '0.88', | ||
| 53 | ); | ||
| 54 | |||
| 55 | return; | ||
| 56 | } | ||
| 57 | |||
| 58 | sub gather_files { | ||
| 59 | my ($self) = @_; | ||
| 60 | |||
| 61 | $self->add_file( | ||
| 62 | Dist::Zilla::File::InMemory->new( | ||
| 63 | { | ||
| 64 | name => 'xt/author/tidyall.t', | ||
| 65 | content => $self->_file_content, | ||
| 66 | } | ||
| 67 | ), | ||
| 68 | ); | ||
| 69 | |||
| 70 | return; | ||
| 71 | } | ||
| 72 | |||
| 73 | sub _file_content { | ||
| 74 | my $self = shift; | ||
| 75 | |||
| 76 | my $content = <<'EOF'; | ||
| 77 | # This file was automatically generated by Dist::Zilla::Plugin::Test::TidyAll v$VERSION | ||
| 78 | |||
| 79 | use Test::More 0.88; | ||
| 80 | EOF | ||
| 81 | |||
| 82 | if ( $self->_has_minimum_perl ) { | ||
| 83 | $content .= sprintf( <<'EOF', ( $self->minimum_perl ) x 2 ); | ||
| 84 | BEGIN { | ||
| 85 | if ( $] < %s ) { | ||
| 86 | plan skip_all => 'This test requires Perl version %s'; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | EOF | ||
| 90 | } | ||
| 91 | |||
| 92 | $content .= <<'EOF'; | ||
| 93 | use Test::Code::TidyAll 0.24; | ||
| 94 | |||
| 95 | EOF | ||
| 96 | |||
| 97 | my @args; | ||
| 98 | if ( $self->_has_conf_file ) { | ||
| 99 | ## no critic (Subroutines::ProhibitCallsToUnexportedSubs) | ||
| 100 | push @args, ' conf_file => ' . B::perlstring( $self->conf_file ); | ||
| 101 | ## use critic | ||
| 102 | } | ||
| 103 | |||
| 104 | push @args, | ||
| 105 | ' verbose => ( exists $ENV{TEST_TIDYALL_VERBOSE} ? $ENV{TEST_TIDYALL_VERBOSE} : ' | ||
| 106 | . ( $self->verbose ? 1 : 0 ) . ' )'; | ||
| 107 | push @args, | ||
| 108 | ' jobs => ( exists $ENV{TEST_TIDYALL_JOBS} ? $ENV{TEST_TIDYALL_JOBS} : ' | ||
| 109 | . $self->jobs . ' )'; | ||
| 110 | |||
| 111 | my $args = join q{}, map { $_ . ",\n" } @args; | ||
| 112 | $args =~ s/^/ /gm; | ||
| 113 | |||
| 114 | $content .= <<"EOF"; | ||
| 115 | tidyall_ok( | ||
| 116 | $args); | ||
| 117 | |||
| 118 | done_testing; | ||
| 119 | EOF | ||
| 120 | |||
| 121 | return $content; | ||
| 122 | } | ||
| 123 | |||
| 124 | __PACKAGE__->meta->make_immutable; | ||
| 125 | |||
| 126 | 1; | ||
| 127 | |||
| 128 | # ABSTRACT: Adds a tidyall test to your distro | ||
| 129 | |||
| 130 | __END__ |