package Dist::Zilla::Plugin::GitIgnore;
$Dist::Zilla::Plugin::GitIgnore::VERSION = '0.001';
use Moose;
with qw/Dist::Zilla::Role::FileGatherer/;
use MooseX::Types::Moose qw/ArrayRef Str/;

use experimental 'signatures';

use namespace::autoclean;

sub mvp_multivalue_args($class) {
	return 'extras';
}

sub mvp_aliases($class) {
	return { extra => 'extras' };
}

has filename => (
	is => 'ro',
	isa => Str,
	default => '.gitignore',
);

has extras => (
	isa     => ArrayRef[Str],
	traits  => ['Array'],
	default => sub { [] },
	handles => {
		extras => 'elements',
	},
);

sub gather_files($self) {
	my @patterns = '.build';
	push @patterns, $self->zilla->name . "-*";
	push @patterns, $self->extras;
	my $payload = join '', map { "$_\n" } @patterns;

	$self->add_file(Dist::Zilla::File::InMemory->new(
		name => $self->filename,
		content => $payload,
	));

	return;
}

1;

# ABSTRACT: Add .gitignore during minting

__END__

=pod

=encoding UTF-8

=head1 NAME

Dist::Zilla::Plugin::GitIgnore - Add .gitignore during minting

=head1 VERSION

version 0.001

=head1 SYNOPSIS

In your profile.ini

 [GitIgnore]
 extra = *.swp

=head1 DESCRIPTION

This is a minting plugin to add a C<.gitignore> file. By default it ignores only two things that L<Dist::Zilla> itself generates: the F<.build> directory, and any file starting with C<"$dist_name-"> (e.g. the tarball that C<Dist::Zilla> produces). More patterns can be added using the C<extra> argument.

=head1 ATTRIBUTES

=head2 extras

This is the list of extra patterns for the gitignore file.

=head2 filename

This sets the filename. It defaults to F<.gitignore> and probably shouldn't be changed.

=head1 AUTHOR

Leon Timmermans <fawaka@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2025 by Leon Timmermans.

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
