use 5.006;    # our
use strict;
use warnings;





package Dist::Zilla::Plugin::Author::KENTNL::DistINI;

# ABSTRACT: Generate a dist.ini for @Author::KENTNL projects.

our $VERSION = '2.025020';

our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY














use Moose qw( with );

with qw(Dist::Zilla::Role::FileGatherer);

__PACKAGE__->meta->make_immutable;
no Moose;

use String::Formatter named_stringf => {
  -as   => 'str_rf',
  codes => {
    s => sub { "$_" },
    S => sub { q{"} . "$_" . q{"} },
    n => sub { int },
  },
};







sub _template {
  my $empty = q{};
  return <<"EOF";
; Generated by %{GENPACKAGE}s version %{GENVERSION}s at %{GENTIME}s
; vim: syntax=dosini
name             = %{name}s
author           = %{author}s
license          = %{license}s
copyright_holder = %{copyrightholder}s
$empty
; Uncomment this to bootstrap via self
; [Bootstrap::lib]
$empty
[\@Author::KENTNL]
:version          = %{depversion}s
normal_form       = numify
mantissa          = 6
toolkit           = eumm
toolkit_hardness  = soft
bumpversions      = 1
srcreadme         = mkdn
; twitter_extra_hash_tags =
; auto_prereqs_skip = File::Find
$empty
[Prereqs]
$empty
EOF
}

sub gather_files {
  my ( $self, ) = @_;
  my $code = sub {
    ## no critic (RegularExpressions)
    my $license = ref $self->zilla->license;
    if ( $license =~ /^Software::License::(.+)$/ ) {
      $license = $1;
    }
    else {
      $license = "=$license";
    }

    # TODO: support >1 authors. Too lazy atm, its just me. -- Kentnl - 2010-06-10
    # TODO: Actually workout whatever localtime is where Kentnl lives. Atm, its overkill. -- Kentnl - 2010-06-10
    my $content = str_rf(
      $self->_template,
      {
        GENPACKAGE      => __PACKAGE__,
        GENVERSION      => ( __PACKAGE__->VERSION || '(unversioned:dist)' ),
        GENTIME         => ( scalar localtime ),
        name            => $self->zilla->name,
        author          => $self->zilla->authors->[0],
        license         => $license,
        copyrightholder => $self->zilla->copyright_holder,
        rel_year        => (localtime)[5] + 1900,
        rel_month       => (localtime)[4] + 1,
        rel_day         => (localtime)[3],
        rel_hour        => (localtime)[2],
        tz              => 'Pacific/Auckland',
        tags            => '#perl #cpan',
        depversion      => ( __PACKAGE__->VERSION || '2.016000' ),
      },
    );
    return $content;
  };
  require Dist::Zilla::File::FromCode;
  my $file = Dist::Zilla::File::FromCode->new(
    {
      name => 'dist.ini',
      code => $code,
    },
  );
  $self->add_file($file);
  return 1;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Dist::Zilla::Plugin::Author::KENTNL::DistINI - Generate a dist.ini for @Author::KENTNL projects.

=head1 VERSION

version 2.025020

=head1 SYNOPSIS

  ; ~/.dzil/profiles/default/profile.ini
  [Author::KENTNL::DistINI]

  ; ~/.dzil/config.ini
  [%Rights]
  license_class = Perl_5
  copyright_holder = Kent Fredric <kentnl@cpan.org>

  [%PAUSE]
  user = KENTNL
  password = ; you don't think I'm stupid do you?

  ; ~/.netrc
  machine api.twitter.com
    login kentnlrelease
    password ; still not quite stupid enough

Then

  dzil new Some-Distname
  # start hacking.

This sets up [@Author::KENTNL] packages the way KENTNL likes it.

This involves initial configuration of the parameters that get
passed through to AutoVersion::Relative to provide the
relative frame of reference.

=head1 METHODS

=head2 C<gather_files>

generates a C<dist.ini> file.

=begin MetaPOD::JSON v1.1.0

{
    "namespace":"Dist::Zilla::Plugin::Author::KENTNL::DistINI",
    "interface":"class",
    "inherits":"Moose::Object",
    "does":"Dist::Zilla::Role::FileGatherer"
}


=end MetaPOD::JSON

=head1 NAMING RATIONALE

  Plugin::DistINI::KENTNL # Argh, too pollutive of the ::DistINI subspace
  Plugin::DistINI::Author::KENTNL
    # Argh, its going to result in lots of 'Author' subspaces ;(
  Plugin::Author::KENTNL::* # Low pollution, well clustered.

As it is, the following stuff is starting to get to me in terms of
name-space pollution:

  Plugin::EOLTests  # Would prefer Plugin::Test::EOL
  Plugin::PodSyntaxTests # Would prefer Plugin::Test::Pod::Syntax

And I have half a mind to rename L<< C<Dist::Zilla::PluginBundle::KENTNL>|Dist::Zilla::PluginBundle::KENTNL >> to be
C<Dist::Zilla::PluginBundle::Author::KENTNL> just to keep the top level cleaner, for stuff where bundles of plug-ins are useful
for people other than ... well.. me. Call me a counter-egotist, if you will.

=head1 AUTHOR

Kent Fredric <kentnl@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Kent Fredric <kentfredric@gmail.com>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
