| 1 | package Dist::Zilla::PluginBundle::DROLSKY; | ||
| 2 | |||
| 3 | use v5.10; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use autodie; | ||
| 8 | use namespace::autoclean; | ||
| 9 | |||
| 10 | our $VERSION = '1.25'; | ||
| 11 | |||
| 12 | use Devel::PPPort 3.42; | ||
| 13 | use Dist::Zilla 6.0; | ||
| 14 | use Path::Tiny::Rule; | ||
| 15 | |||
| 16 | # For the benefit of AutoPrereqs | ||
| 17 | use Dist::Zilla::Plugin::Authority; | ||
| 18 | use Dist::Zilla::Plugin::AutoPrereqs; | ||
| 19 | use Dist::Zilla::Plugin::BumpVersionAfterRelease; | ||
| 20 | use Dist::Zilla::Plugin::CPANFile; | ||
| 21 | use Dist::Zilla::Plugin::CheckPrereqsIndexed; | ||
| 22 | use Dist::Zilla::Plugin::CheckSelfDependency; | ||
| 23 | use Dist::Zilla::Plugin::CheckStrictVersion; | ||
| 24 | use Dist::Zilla::Plugin::CheckVersionIncrement; | ||
| 25 | use Dist::Zilla::Plugin::CopyFilesFromBuild; | ||
| 26 | use Dist::Zilla::Plugin::DROLSKY::BundleAuthordep; | ||
| 27 | use Dist::Zilla::Plugin::DROLSKY::Contributors; | ||
| 28 | use Dist::Zilla::Plugin::DROLSKY::DevTools; | ||
| 29 | use Dist::Zilla::Plugin::DROLSKY::License; | ||
| 30 | use Dist::Zilla::Plugin::DROLSKY::MakeMaker; | ||
| 31 | use Dist::Zilla::Plugin::DROLSKY::PerlLinterConfigFiles; | ||
| 32 | use Dist::Zilla::Plugin::DROLSKY::Precious; | ||
| 33 | use Dist::Zilla::Plugin::DROLSKY::WeaverConfig; | ||
| 34 | use Dist::Zilla::Plugin::EnsureChangesHasContent 0.02; | ||
| 35 | use Dist::Zilla::Plugin::GenerateFile::FromShareDir 0.013; | ||
| 36 | use Dist::Zilla::Plugin::Git::Check; | ||
| 37 | use Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts; | ||
| 38 | use Dist::Zilla::Plugin::Git::Commit; | ||
| 39 | use Dist::Zilla::Plugin::Git::Contributors; | ||
| 40 | use Dist::Zilla::Plugin::Git::GatherDir; | ||
| 41 | use Dist::Zilla::Plugin::Git::Push; | ||
| 42 | use Dist::Zilla::Plugin::Git::Tag; | ||
| 43 | use Dist::Zilla::Plugin::GitHub::Meta 0.45; | ||
| 44 | use Dist::Zilla::Plugin::GitHub::Update 0.45; | ||
| 45 | use Dist::Zilla::Plugin::InstallGuide; | ||
| 46 | use Dist::Zilla::Plugin::Meta::Contributors; | ||
| 47 | use Dist::Zilla::Plugin::MetaConfig; | ||
| 48 | use Dist::Zilla::Plugin::MetaJSON; | ||
| 49 | use Dist::Zilla::Plugin::MetaProvides::Package; | ||
| 50 | use Dist::Zilla::Plugin::MetaResources; | ||
| 51 | use Dist::Zilla::Plugin::MojibakeTests; | ||
| 52 | use Dist::Zilla::Plugin::NextRelease; | ||
| 53 | use Dist::Zilla::Plugin::PPPort; | ||
| 54 | use Dist::Zilla::Plugin::PodSyntaxTests; | ||
| 55 | use Dist::Zilla::Plugin::PromptIfStale 0.056; | ||
| 56 | use Dist::Zilla::Plugin::ReadmeAnyFromPod; | ||
| 57 | use Dist::Zilla::Plugin::RunExtraTests; | ||
| 58 | use Dist::Zilla::Plugin::SurgicalPodWeaver; | ||
| 59 | use Dist::Zilla::Plugin::Test::CPAN::Changes; | ||
| 60 | use Dist::Zilla::Plugin::Test::CPAN::Meta::JSON; | ||
| 61 | use Dist::Zilla::Plugin::Test::CleanNamespaces; | ||
| 62 | use Dist::Zilla::Plugin::Test::Compile; | ||
| 63 | use Dist::Zilla::Plugin::Test::EOL 0.14; | ||
| 64 | use Dist::Zilla::Plugin::Test::NoTabs; | ||
| 65 | use Dist::Zilla::Plugin::Test::Pod::Coverage::Configurable; | ||
| 66 | use Dist::Zilla::Plugin::Test::PodSpelling; | ||
| 67 | use Dist::Zilla::Plugin::Test::Portability; | ||
| 68 | use Dist::Zilla::Plugin::Test::ReportPrereqs; | ||
| 69 | use Dist::Zilla::Plugin::Test::Synopsis; | ||
| 70 | use Dist::Zilla::Plugin::Test::Version; | ||
| 71 | use Dist::Zilla::Plugin::VersionFromMainModule 0.02; | ||
| 72 | |||
| 73 | use Moose; | ||
| 74 | |||
| 75 | with 'Dist::Zilla::Role::PluginBundle::Easy', | ||
| 76 | 'Dist::Zilla::Role::PluginBundle::PluginRemover', | ||
| 77 | 'Dist::Zilla::Role::PluginBundle::Config::Slicer'; | ||
| 78 | |||
| 79 | has dist => ( | ||
| 80 | is => 'ro', | ||
| 81 | isa => 'Str', | ||
| 82 | required => 1, | ||
| 83 | ); | ||
| 84 | |||
| 85 | has make_tool => ( | ||
| 86 | is => 'ro', | ||
| 87 | isa => 'Str', | ||
| 88 | default => 'DROLSKY::MakeMaker', | ||
| 89 | ); | ||
| 90 | |||
| 91 | has authority => ( | ||
| 92 | is => 'ro', | ||
| 93 | isa => 'Str', | ||
| 94 | default => 'DROLSKY', | ||
| 95 | ); | ||
| 96 | |||
| 97 | has prereqs_skip => ( | ||
| 98 | traits => ['Array'], | ||
| 99 | is => 'ro', | ||
| 100 | isa => 'ArrayRef[Str]', | ||
| 101 | required => 1, | ||
| 102 | handles => { | ||
| 103 | _has_prereqs_skip => 'count', | ||
| 104 | }, | ||
| 105 | ); | ||
| 106 | |||
| 107 | has exclude_files => ( | ||
| 108 | is => 'ro', | ||
| 109 | isa => 'ArrayRef[Str]', | ||
| 110 | required => 1, | ||
| 111 | ); | ||
| 112 | |||
| 113 | has has_xs => ( | ||
| 114 | is => 'ro', | ||
| 115 | isa => 'Bool', | ||
| 116 | lazy => 1, | ||
| 117 | builder => '_build_has_xs', | ||
| 118 | ); | ||
| 119 | |||
| 120 | has _exclude => ( | ||
| 121 | is => 'ro', | ||
| 122 | isa => 'HashRef[ArrayRef]', | ||
| 123 | lazy => 1, | ||
| 124 | builder => '_build_exclude', | ||
| 125 | ); | ||
| 126 | |||
| 127 | has _exclude_filenames => ( | ||
| 128 | is => 'ro', | ||
| 129 | isa => 'ArrayRef[Str]', | ||
| 130 | lazy => 1, | ||
| 131 | default => sub { $_[0]->_exclude->{filenames} }, | ||
| 132 | ); | ||
| 133 | |||
| 134 | has _exclude_match => ( | ||
| 135 | is => 'ro', | ||
| 136 | isa => 'ArrayRef[Regexp]', | ||
| 137 | lazy => 1, | ||
| 138 | default => sub { $_[0]->_exclude->{match} }, | ||
| 139 | ); | ||
| 140 | |||
| 141 | has _allow_dirty => ( | ||
| 142 | is => 'ro', | ||
| 143 | isa => 'ArrayRef[Str]', | ||
| 144 | lazy => 1, | ||
| 145 | builder => '_build_allow_dirty', | ||
| 146 | ); | ||
| 147 | |||
| 148 | has pod_coverage_class => ( | ||
| 149 | is => 'ro', | ||
| 150 | isa => 'Str', | ||
| 151 | predicate => '_has_pod_coverage_class', | ||
| 152 | ); | ||
| 153 | |||
| 154 | has pod_coverage_skip => ( | ||
| 155 | traits => ['Array'], | ||
| 156 | is => 'ro', | ||
| 157 | isa => 'ArrayRef[Str]', | ||
| 158 | required => 1, | ||
| 159 | handles => { | ||
| 160 | _has_pod_coverage_skip => 'count', | ||
| 161 | }, | ||
| 162 | ); | ||
| 163 | |||
| 164 | has pod_coverage_trustme => ( | ||
| 165 | traits => ['Array'], | ||
| 166 | is => 'ro', | ||
| 167 | isa => 'ArrayRef[Str]', | ||
| 168 | required => 1, | ||
| 169 | handles => { | ||
| 170 | _has_pod_coverage_trustme => 'count', | ||
| 171 | }, | ||
| 172 | ); | ||
| 173 | |||
| 174 | has pod_coverage_also_private => ( | ||
| 175 | traits => ['Array'], | ||
| 176 | is => 'ro', | ||
| 177 | isa => 'ArrayRef[Str]', | ||
| 178 | required => 1, | ||
| 179 | handles => { | ||
| 180 | _has_pod_coverage_also_private => 'count', | ||
| 181 | }, | ||
| 182 | ); | ||
| 183 | |||
| 184 | has stopwords => ( | ||
| 185 | traits => ['Array'], | ||
| 186 | is => 'ro', | ||
| 187 | isa => 'ArrayRef[Str]', | ||
| 188 | required => 1, | ||
| 189 | ); | ||
| 190 | |||
| 191 | has stopwords_file => ( | ||
| 192 | is => 'ro', | ||
| 193 | isa => 'Str', | ||
| 194 | predicate => '_has_stopwords_file', | ||
| 195 | ); | ||
| 196 | |||
| 197 | has next_release_width => ( | ||
| 198 | is => 'ro', | ||
| 199 | isa => 'Int', | ||
| 200 | default => 8, | ||
| 201 | ); | ||
| 202 | |||
| 203 | has use_github_homepage => ( | ||
| 204 | is => 'ro', | ||
| 205 | isa => 'Bool', | ||
| 206 | default => 0, | ||
| 207 | ); | ||
| 208 | |||
| 209 | has _plugins => ( | ||
| 210 | is => 'ro', | ||
| 211 | isa => 'ArrayRef', | ||
| 212 | init_arg => undef, | ||
| 213 | lazy => 1, | ||
| 214 | builder => '_build_plugins', | ||
| 215 | ); | ||
| 216 | |||
| 217 | has _files_to_copy_from_build => ( | ||
| 218 | is => 'ro', | ||
| 219 | isa => 'ArrayRef[Str]', | ||
| 220 | init_arg => undef, | ||
| 221 | lazy => 1, | ||
| 222 | builder => '_build_files_to_copy_from_build', | ||
| 223 | ); | ||
| 224 | |||
| 225 | has _running_in_ci => ( | ||
| 226 | is => 'ro', | ||
| 227 | isa => 'Bool', | ||
| 228 | default => sub { | ||
| 229 | |||
| 230 | # AGENT_ID is Azure Pipelines. | ||
| 231 | return $ENV{TRAVIS} || $ENV{AGENT_ID} ? 1 : 0; | ||
| 232 | }, | ||
| 233 | ); | ||
| 234 | |||
| 235 | my @array_params = grep { !/^_/ } map { $_->name } | ||
| 236 | grep { | ||
| 237 | $_->has_type_constraint | ||
| 238 | && $_->type_constraint->is_a_type_of('ArrayRef') | ||
| 239 | } __PACKAGE__->meta->get_all_attributes; | ||
| 240 | |||
| 241 | sub mvp_multivalue_args { | ||
| 242 | return @array_params; | ||
| 243 | } | ||
| 244 | |||
| 245 | around BUILDARGS => sub { | ||
| 246 | my $orig = shift; | ||
| 247 | my $class = shift; | ||
| 248 | |||
| 249 | my $p = $class->$orig(@_); | ||
| 250 | |||
| 251 | my %args = ( %{ $p->{payload} }, %{$p} ); | ||
| 252 | |||
| 253 | for my $key (@array_params) { | ||
| 254 | if ( $args{$key} && !ref $args{$key} ) { | ||
| 255 | $args{$key} = [ delete $args{$key} ]; | ||
| 256 | } | ||
| 257 | $args{$key} //= []; | ||
| 258 | } | ||
| 259 | |||
| 260 | return \%args; | ||
| 261 | }; | ||
| 262 | |||
| 263 | sub configure { | ||
| 264 | my $self = shift; | ||
| 265 | $self->add_plugins( @{ $self->_plugins } ); | ||
| 266 | return; | ||
| 267 | } | ||
| 268 | |||
| 269 | sub _build_plugins { | ||
| 270 | my $self = shift; | ||
| 271 | |||
| 272 | my %make_tool_args; | ||
| 273 | if ( $self->make_tool =~ /MakeMaker/ ) { | ||
| 274 | $make_tool_args{has_xs} = $self->has_xs; | ||
| 275 | } | ||
| 276 | |||
| 277 | return [ | ||
| 278 | 'DROLSKY::BundleAuthordep', | ||
| 279 | $self->_gather_dir_plugin, | ||
| 280 | $self->_basic_plugins, | ||
| 281 | $self->_authority_plugin, | ||
| 282 | $self->_auto_prereqs_plugin, | ||
| 283 | $self->_copy_files_from_build_plugin, | ||
| 284 | $self->_github_plugins, | ||
| 285 | $self->_meta_plugins, | ||
| 286 | $self->_next_release_plugin, | ||
| 287 | $self->_explicit_prereq_plugins, | ||
| 288 | $self->_prompt_if_stale_plugin, | ||
| 289 | $self->_pod_test_plugins, | ||
| 290 | $self->_extra_test_plugins, | ||
| 291 | $self->_contributors_plugins, | ||
| 292 | $self->_pod_weaver_plugin, | ||
| 293 | |||
| 294 | # README.md generation needs to come after pod weaving | ||
| 295 | $self->_readme_md_plugin, | ||
| 296 | $self->_contributing_md_plugin, | ||
| 297 | $self->_code_of_conduct_plugin, | ||
| 298 | 'InstallGuide', | ||
| 299 | 'CPANFile', | ||
| 300 | $self->_maybe_ppport_plugin, | ||
| 301 | 'DROLSKY::License', | ||
| 302 | $self->_release_check_plugins, | ||
| 303 | 'DROLSKY::PerlLinterConfigFiles', | ||
| 304 | $self->_precious_plugin, | ||
| 305 | $self->_git_plugins, | ||
| 306 | |||
| 307 | # This needs to be last so that MakeMaker::Awesome can see all the | ||
| 308 | # prereqs that a distro has. If it comes first, it tries to check the | ||
| 309 | # prereqs before they've been added and makes a mess of things. | ||
| 310 | [ $self->make_tool => \%make_tool_args ], | ||
| 311 | ]; | ||
| 312 | } | ||
| 313 | |||
| 314 | sub _gather_dir_plugin { | ||
| 315 | my $self = shift; | ||
| 316 | |||
| 317 | my $match = $self->_exclude_match; | ||
| 318 | [ | ||
| 319 | 'Git::GatherDir' => { | ||
| 320 | exclude_filename => $self->_exclude_filenames, | ||
| 321 | ( @{$match} ? ( exclude_match => $match ) : () ), | ||
| 322 | }, | ||
| 323 | ]; | ||
| 324 | } | ||
| 325 | |||
| 326 | sub _build_exclude { | ||
| 327 | my $self = shift; | ||
| 328 | |||
| 329 | my @filenames = @{ $self->_files_to_copy_from_build }; | ||
| 330 | |||
| 331 | my @match; | ||
| 332 | for my $exclude ( @{ $self->exclude_files } ) { | ||
| 333 | if ( $exclude =~ m{^[\w\-\./]+$} ) { | ||
| 334 | push @filenames, $exclude; | ||
| 335 | } | ||
| 336 | else { | ||
| 337 | push @match, qr/$exclude/; | ||
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | return { | ||
| 342 | filenames => \@filenames, | ||
| 343 | match => \@match, | ||
| 344 | }; | ||
| 345 | } | ||
| 346 | |||
| 347 | sub _basic_plugins { | ||
| 348 | |||
| 349 | # These are a subset of the @Basic bundle except for CheckVersionIncrement | ||
| 350 | # and VersionFromMainModule. | ||
| 351 | qw( | ||
| 352 | ManifestSkip | ||
| 353 | License | ||
| 354 | ExecDir | ||
| 355 | ShareDir | ||
| 356 | Manifest | ||
| 357 | CheckVersionIncrement | ||
| 358 | TestRelease | ||
| 359 | ConfirmRelease | ||
| 360 | UploadToCPAN | ||
| 361 | VersionFromMainModule | ||
| 362 | ); | ||
| 363 | } | ||
| 364 | |||
| 365 | sub _authority_plugin { | ||
| 366 | my $self = shift; | ||
| 367 | |||
| 368 | return [ | ||
| 369 | Authority => { | ||
| 370 | authority => 'cpan:' . $self->authority, | ||
| 371 | do_munging => 0, | ||
| 372 | }, | ||
| 373 | ]; | ||
| 374 | } | ||
| 375 | |||
| 376 | sub _auto_prereqs_plugin { | ||
| 377 | my $self = shift; | ||
| 378 | |||
| 379 | return [ | ||
| 380 | AutoPrereqs => { | ||
| 381 | $self->_has_prereqs_skip | ||
| 382 | ? ( skip => $self->prereqs_skip ) | ||
| 383 | : () | ||
| 384 | }, | ||
| 385 | ]; | ||
| 386 | } | ||
| 387 | |||
| 388 | sub _copy_files_from_build_plugin { | ||
| 389 | my $self = shift; | ||
| 390 | |||
| 391 | return [ | ||
| 392 | CopyFilesFromBuild => { | ||
| 393 | copy => $self->_files_to_copy_from_build, | ||
| 394 | }, | ||
| 395 | ]; | ||
| 396 | } | ||
| 397 | |||
| 398 | # These are files which are generated as part of the build process and then | ||
| 399 | # copied back into the git repo and checked in. | ||
| 400 | sub _build_files_to_copy_from_build { | ||
| 401 | my $self = shift; | ||
| 402 | |||
| 403 | my @files = qw( | ||
| 404 | CODE_OF_CONDUCT.md | ||
| 405 | CONTRIBUTING.md | ||
| 406 | LICENSE | ||
| 407 | README.md | ||
| 408 | cpanfile | ||
| 409 | ); | ||
| 410 | |||
| 411 | push @files, | ||
| 412 | $self->make_tool =~ /MakeMaker/ ? 'Makefile.PL' : 'Build.PL'; | ||
| 413 | |||
| 414 | if ( $self->has_xs ) { | ||
| 415 | if ( $self->payload->{'PPPort.filename'} ) { | ||
| 416 | push @files, $self->payload->{'PPPort.filename'}; | ||
| 417 | } | ||
| 418 | else { | ||
| 419 | push @files, 'ppport.h'; | ||
| 420 | } | ||
| 421 | } | ||
| 422 | |||
| 423 | return \@files; | ||
| 424 | } | ||
| 425 | |||
| 426 | sub _github_plugins { | ||
| 427 | my $self = shift; | ||
| 428 | |||
| 429 | return if $self->_running_in_ci; | ||
| 430 | |||
| 431 | return ( | ||
| 432 | [ | ||
| 433 | 'GitHub::Meta' => { | ||
| 434 | bugs => 1, | ||
| 435 | homepage => $self->use_github_homepage, | ||
| 436 | require_auth => 1, | ||
| 437 | }, | ||
| 438 | ], | ||
| 439 | [ 'GitHub::Update' => { metacpan => 1 } ], | ||
| 440 | ); | ||
| 441 | } | ||
| 442 | |||
| 443 | sub _meta_plugins { | ||
| 444 | my $self = shift; | ||
| 445 | |||
| 446 | return ( | ||
| 447 | [ MetaResources => $self->_meta_resources, ], | ||
| 448 | [ 'MetaProvides::Package' => { meta_noindex => 1 } ], | ||
| 449 | qw( | ||
| 450 | Meta::Contributors | ||
| 451 | MetaConfig | ||
| 452 | MetaJSON | ||
| 453 | MetaYAML | ||
| 454 | ), | ||
| 455 | ); | ||
| 456 | } | ||
| 457 | |||
| 458 | sub _meta_resources { | ||
| 459 | my $self = shift; | ||
| 460 | |||
| 461 | my %resources; | ||
| 462 | |||
| 463 | unless ( $self->use_github_homepage ) { | ||
| 464 | $resources{homepage} | ||
| 465 | = sprintf( 'https://metacpan.org/release/%s', $self->dist ); | ||
| 466 | } | ||
| 467 | |||
| 468 | return \%resources; | ||
| 469 | } | ||
| 470 | |||
| 471 | sub _next_release_plugin { | ||
| 472 | my $self = shift; | ||
| 473 | |||
| 474 | return [ | ||
| 475 | NextRelease => { | ||
| 476 | format => '%-' | ||
| 477 | . $self->next_release_width | ||
| 478 | . 'v %{yyyy-MM-dd}d%{ (TRIAL RELEASE)}T' | ||
| 479 | }, | ||
| 480 | ]; | ||
| 481 | } | ||
| 482 | |||
| 483 | sub _explicit_prereq_plugins { | ||
| 484 | my $self = shift; | ||
| 485 | |||
| 486 | my $test_more = $self->_dist_uses_test2 | ||
| 487 | ? [ | ||
| 488 | 'Prereqs' => 'Test::More with Test2' => { | ||
| 489 | -phase => 'test', | ||
| 490 | -type => 'requires', | ||
| 491 | 'Test::More' => '1.302015', | ||
| 492 | } | ||
| 493 | ] | ||
| 494 | : [ | ||
| 495 | 'Prereqs' => 'Test::More with subtest' => { | ||
| 496 | -phase => 'test', | ||
| 497 | -type => 'requires', | ||
| 498 | 'Test::More' => '0.96', | ||
| 499 | } | ||
| 500 | ]; | ||
| 501 | |||
| 502 | # These are needed for use with tidyall, but they're not direct tidyall | ||
| 503 | # prereqs. | ||
| 504 | my @lint_tool_prereqs; | ||
| 505 | my %shared_lint_prereqs = ( | ||
| 506 | 'Perl::Critic' => '1.138', | ||
| 507 | 'Perl::Critic::Moose' => '1.05', | ||
| 508 | 'Perl::Tidy' => '20210111', | ||
| 509 | ); | ||
| 510 | |||
| 511 | if ( -e 'tidyall.ini' ) { | ||
| 512 | @lint_tool_prereqs = ( | ||
| 513 | 'Prereqs' => 'Modules for use with tidyall' => { | ||
| 514 | -phase => 'develop', | ||
| 515 | -type => 'requires', | ||
| 516 | 'Code::TidyAll' => '0.56', | ||
| 517 | 'Code::TidyAll::Plugin::SortLines::Naturally' => '0.000003', | ||
| 518 | 'Code::TidyAll::Plugin::Test::Vars' => '0.02', | ||
| 519 | 'Parallel::ForkManager' => '1.19', | ||
| 520 | 'Test::Vars' => '0.009', | ||
| 521 | %shared_lint_prereqs, | ||
| 522 | } | ||
| 523 | ); | ||
| 524 | } | ||
| 525 | else { | ||
| 526 | @lint_tool_prereqs = ( | ||
| 527 | 'Prereqs' => 'Tools for use with precious' => { | ||
| 528 | -phase => 'develop', | ||
| 529 | -type => 'requires', | ||
| 530 | 'Pod::Checker' => '1.74', | ||
| 531 | 'Pod::Tidy' => '0.10', | ||
| 532 | %shared_lint_prereqs, | ||
| 533 | }, | ||
| 534 | ); | ||
| 535 | } | ||
| 536 | |||
| 537 | return ( | ||
| 538 | $test_more, | ||
| 539 | \@lint_tool_prereqs, | ||
| 540 | [ | ||
| 541 | 'Prereqs' => | ||
| 542 | 'Test::Version which fixes https://github.com/plicease/Test-Version/issues/7' | ||
| 543 | => { | ||
| 544 | -phase => 'develop', | ||
| 545 | -type => 'requires', | ||
| 546 | 'Test::Version' => '2.05', | ||
| 547 | }, | ||
| 548 | ], | ||
| 549 | ); | ||
| 550 | } | ||
| 551 | |||
| 552 | sub _dist_uses_test2 { | ||
| 553 | my $rule = Path::Tiny::Rule->new; | ||
| 554 | my $iter | ||
| 555 | = $rule->file->name(qr/\.(t|pm)$/) | ||
| 556 | ->contents_match(qr/^use Test2/m) | ||
| 557 | ->iter('t'); | ||
| 558 | |||
| 559 | while ( my $file = $iter->() ) { | ||
| 560 | return 1; | ||
| 561 | } | ||
| 562 | |||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | |||
| 566 | sub _prompt_if_stale_plugin { | ||
| 567 | my $name = __PACKAGE__; | ||
| 568 | return ( | ||
| 569 | [ | ||
| 570 | 'PromptIfStale' => $name => { | ||
| 571 | phase => 'build', | ||
| 572 | module => [__PACKAGE__], | ||
| 573 | }, | ||
| 574 | ], | ||
| 575 | [ | ||
| 576 | 'PromptIfStale' => { | ||
| 577 | phase => 'release', | ||
| 578 | check_all_plugins => 1, | ||
| 579 | check_all_prereqs => 1, | ||
| 580 | check_authordeps => 1, | ||
| 581 | skip => [ | ||
| 582 | qw( | ||
| 583 | Dist::Zilla::Plugin::DROLSKY::BundleAuthordep | ||
| 584 | Dist::Zilla::Plugin::DROLSKY::Contributors | ||
| 585 | Dist::Zilla::Plugin::DROLSKY::Git::CheckFor::CorrectBranch | ||
| 586 | Dist::Zilla::Plugin::DROLSKY::License | ||
| 587 | Dist::Zilla::Plugin::DROLSKY::MakeMaker | ||
| 588 | Dist::Zilla::Plugin::DROLSKY::PerlLinterConfigFiles | ||
| 589 | Dist::Zilla::Plugin::DROLSKY::Precious | ||
| 590 | Dist::Zilla::Plugin::DROLSKY::WeaverConfig | ||
| 591 | Pod::Weaver::PluginBundle::DROLSKY | ||
| 592 | ) | ||
| 593 | ], | ||
| 594 | } | ||
| 595 | ], | ||
| 596 | ); | ||
| 597 | } | ||
| 598 | |||
| 599 | sub _pod_test_plugins { | ||
| 600 | my $self = shift; | ||
| 601 | |||
| 602 | return ( | ||
| 603 | [ | ||
| 604 | 'Test::Pod::Coverage::Configurable' => { | ||
| 605 | ( | ||
| 606 | $self->_has_pod_coverage_also_private | ||
| 607 | ? ( also_private => $self->pod_coverage_also_private ) | ||
| 608 | : () | ||
| 609 | ), | ||
| 610 | ( | ||
| 611 | $self->_has_pod_coverage_skip | ||
| 612 | ? ( skip => $self->pod_coverage_skip ) | ||
| 613 | : () | ||
| 614 | ), | ||
| 615 | ( | ||
| 616 | $self->_has_pod_coverage_trustme | ||
| 617 | ? ( trustme => $self->pod_coverage_trustme ) | ||
| 618 | : () | ||
| 619 | ), | ||
| 620 | ( | ||
| 621 | $self->_has_pod_coverage_class | ||
| 622 | ? ( class => $self->pod_coverage_class ) | ||
| 623 | : () | ||
| 624 | ), | ||
| 625 | }, | ||
| 626 | ], | ||
| 627 | [ | ||
| 628 | 'Test::PodSpelling' => { stopwords => $self->_all_stopwords }, | ||
| 629 | ], | ||
| 630 | 'PodSyntaxTests', | ||
| 631 | ); | ||
| 632 | } | ||
| 633 | |||
| 634 | sub _all_stopwords { | ||
| 635 | my $self = shift; | ||
| 636 | |||
| 637 | my @stopwords = $self->_default_stopwords; | ||
| 638 | push @stopwords, @{ $self->stopwords }; | ||
| 639 | |||
| 640 | if ( $self->_has_stopwords_file ) { | ||
| 641 | open my $fh, '<:encoding(UTF-8)', $self->stopwords_file; | ||
| 642 | while (<$fh>) { | ||
| 643 | chomp; | ||
| 644 | next unless length $_ && $_ !~ /^\#/; | ||
| 645 | push @stopwords, $_; | ||
| 646 | } | ||
| 647 | close $fh; | ||
| 648 | } | ||
| 649 | |||
| 650 | return \@stopwords; | ||
| 651 | } | ||
| 652 | |||
| 653 | sub _default_stopwords { | ||
| 654 | return qw( | ||
| 655 | drolsky | ||
| 656 | DROLSKY | ||
| 657 | DROLSKY's | ||
| 658 | PayPal | ||
| 659 | Rolsky | ||
| 660 | Rolsky's | ||
| 661 | ); | ||
| 662 | } | ||
| 663 | |||
| 664 | sub _extra_test_plugins { | ||
| 665 | my $self = shift; | ||
| 666 | |||
| 667 | my @plugins = ( | ||
| 668 | qw( | ||
| 669 | MojibakeTests | ||
| 670 | RunExtraTests | ||
| 671 | Test::CleanNamespaces | ||
| 672 | Test::CPAN::Changes | ||
| 673 | Test::CPAN::Meta::JSON | ||
| 674 | Test::EOL | ||
| 675 | Test::NoTabs | ||
| 676 | Test::Portability | ||
| 677 | Test::Synopsis | ||
| 678 | ), | ||
| 679 | [ 'Test::Compile' => { xt_mode => 1 } ], | ||
| 680 | [ 'Test::ReportPrereqs' => { verify_prereqs => 1 } ], | ||
| 681 | [ 'Test::Version' => { is_strict => 1 } ], | ||
| 682 | ); | ||
| 683 | |||
| 684 | push @plugins, 'Test::TidyAll' if -f 'tidyall.ini'; | ||
| 685 | |||
| 686 | return @plugins; | ||
| 687 | } | ||
| 688 | |||
| 689 | sub _contributors_plugins { | ||
| 690 | qw( | ||
| 691 | DROLSKY::Contributors | ||
| 692 | Git::Contributors | ||
| 693 | ); | ||
| 694 | } | ||
| 695 | |||
| 696 | sub _pod_weaver_plugin { | ||
| 697 | return ( | ||
| 698 | [ | ||
| 699 | SurgicalPodWeaver => { | ||
| 700 | config_plugin => '@DROLSKY', | ||
| 701 | }, | ||
| 702 | ], | ||
| 703 | 'DROLSKY::WeaverConfig', | ||
| 704 | ); | ||
| 705 | } | ||
| 706 | |||
| 707 | sub _readme_md_plugin { | ||
| 708 | [ | ||
| 709 | 'ReadmeAnyFromPod' => 'README.md in build' => { | ||
| 710 | type => 'markdown', | ||
| 711 | filename => 'README.md', | ||
| 712 | location => 'build', | ||
| 713 | phase => 'build', | ||
| 714 | }, | ||
| 715 | ]; | ||
| 716 | } | ||
| 717 | |||
| 718 | sub _contributing_md_plugin { | ||
| 719 | my $self = shift; | ||
| 720 | |||
| 721 | return [ | ||
| 722 | 'GenerateFile::FromShareDir' => 'Generate CONTRIBUTING.md' => { | ||
| 723 | -dist => ( __PACKAGE__ =~ s/::/-/gr ), | ||
| 724 | -filename => 'CONTRIBUTING.md', | ||
| 725 | has_xs => $self->has_xs, | ||
| 726 | }, | ||
| 727 | ]; | ||
| 728 | } | ||
| 729 | |||
| 730 | sub _code_of_conduct_plugin { | ||
| 731 | my $self = shift; | ||
| 732 | |||
| 733 | return [ | ||
| 734 | 'GenerateFile::FromShareDir' => 'Generate CODE_OF_CONDUCT.md' => { | ||
| 735 | -dist => ( __PACKAGE__ =~ s/::/-/gr ), | ||
| 736 | -filename => 'CODE_OF_CONDUCT.md', | ||
| 737 | has_xs => $self->has_xs, | ||
| 738 | }, | ||
| 739 | ]; | ||
| 740 | } | ||
| 741 | |||
| 742 | sub _maybe_ppport_plugin { | ||
| 743 | my $self = shift; | ||
| 744 | |||
| 745 | return unless $self->has_xs; | ||
| 746 | return 'PPPort'; | ||
| 747 | } | ||
| 748 | |||
| 749 | sub _release_check_plugins { | ||
| 750 | return ( | ||
| 751 | [ CheckStrictVersion => { decimal_only => 1 } ], | ||
| 752 | qw( | ||
| 753 | CheckSelfDependency | ||
| 754 | CheckPrereqsIndexed | ||
| 755 | DROLSKY::Git::CheckFor::CorrectBranch | ||
| 756 | EnsureChangesHasContent | ||
| 757 | Git::CheckFor::MergeConflicts | ||
| 758 | ), | ||
| 759 | ); | ||
| 760 | } | ||
| 761 | |||
| 762 | sub _precious_plugin { | ||
| 763 | my $self = shift; | ||
| 764 | |||
| 765 | return if -e 'tidyall.ini'; | ||
| 766 | |||
| 767 | my %precious_config; | ||
| 768 | $precious_config{stopwords_file} = $self->stopwords_file | ||
| 769 | if $self->_has_stopwords_file; | ||
| 770 | |||
| 771 | return ( | ||
| 772 | 'DROLSKY::DevTools', | ||
| 773 | ( | ||
| 774 | keys %precious_config | ||
| 775 | ? [ 'DROLSKY::Precious' => \%precious_config ] | ||
| 776 | : 'DROLSKY::Precious' | ||
| 777 | ), | ||
| 778 | ); | ||
| 779 | } | ||
| 780 | |||
| 781 | sub _git_plugins { | ||
| 782 | my $self = shift; | ||
| 783 | |||
| 784 | # These are mostly from @Git, except for BumpVersionAfterRelease. That | ||
| 785 | # one's in here because the order of all these plugins is | ||
| 786 | # important. We want to check the release, then we ... | ||
| 787 | |||
| 788 | return ( | ||
| 789 | # Check that the working directory does not contain any surprising uncommitted | ||
| 790 | # changes (except for things we expect to be dirty like the README.md or | ||
| 791 | # Changes). | ||
| 792 | [ 'Git::Check' => { allow_dirty => $self->_allow_dirty }, ], | ||
| 793 | |||
| 794 | # Commit all the dirty files before the release. | ||
| 795 | [ | ||
| 796 | 'Git::Commit' => 'Commit generated files' => { | ||
| 797 | allow_dirty => $self->_allow_dirty, | ||
| 798 | }, | ||
| 799 | ], | ||
| 800 | |||
| 801 | # Tag the release and push both the above commit and the tag. | ||
| 802 | qw( | ||
| 803 | Git::Tag | ||
| 804 | Git::Push | ||
| 805 | ), | ||
| 806 | |||
| 807 | # Bump all module versions. | ||
| 808 | 'BumpVersionAfterRelease', | ||
| 809 | |||
| 810 | # Make another commit with just the version bump. | ||
| 811 | [ | ||
| 812 | 'Git::Commit' => 'Commit version bump' => { | ||
| 813 | allow_dirty_match => ['.+'], | ||
| 814 | commit_msg => 'Bump version after release' | ||
| 815 | }, | ||
| 816 | ], | ||
| 817 | |||
| 818 | # Push the version bump commit. | ||
| 819 | [ 'Git::Push' => 'Push version bump' ], | ||
| 820 | ); | ||
| 821 | } | ||
| 822 | |||
| 823 | sub _build_allow_dirty { | ||
| 824 | my $self = shift; | ||
| 825 | |||
| 826 | # Anything we auto-generate and check in could be dirty. We also allow any | ||
| 827 | # other file which might get munged by this bundle to be dirty. | ||
| 828 | return [ | ||
| 829 | @{ $self->_exclude_filenames }, | ||
| 830 | qw( | ||
| 831 | Changes | ||
| 832 | precious.toml | ||
| 833 | ) | ||
| 834 | ]; | ||
| 835 | } | ||
| 836 | |||
| 837 | sub _build_has_xs { | ||
| 838 | my $self = shift; | ||
| 839 | |||
| 840 | my $rule = Path::Tiny::Rule->new; | ||
| 841 | return $rule->skip_dirs( | ||
| 842 | '.build', | ||
| 843 | $self->dist . '-*', | ||
| 844 | )->file->name(qr/\.xs$/)->iter('.')->() ? 1 : 0; | ||
| 845 | } | ||
| 846 | |||
| 847 | __PACKAGE__->meta->make_immutable; | ||
| 848 | |||
| 849 | 1; | ||
| 850 | |||
| 851 | # ABSTRACT: DROLSKY's plugin bundle | ||
| 852 | |||
| 853 | __END__ |