Skip to content

Commit

Permalink
Add support for multiple authors to Module::Starter; Issue xsawyerx#25
Browse files Browse the repository at this point in the history
The included changes add support for multiple authors to Module::Starter and propogate to the chosen builder option. To do this, it seemed appropriate to remove the --email option and ask that users' specify both the author name and email as a single option, which most of the builders expect anyway:

    module-starter --module=Foo::Bar,Foo::Bat \
        --author="Andy Lester <[email protected]> \
        --author="Sawyer X <[email protected]>

The attribute that previously held the author, `$self->{author}` now holds an arrayref of authoremails. Which are passed in turn to Module::Build and ExtUtils::MakeMaker as arrayrefs and to Module::Install as a string.

I tried to follow the existing conventions that were used within the module, but please let me know if I missed anything and/or there are other change you would like me to make.
  • Loading branch information
Hunter McMillen committed Nov 29, 2015
1 parent 7b7c894 commit 5a17f4a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 48 deletions.
12 changes: 11 additions & 1 deletion bin/module-starter
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ Options:
--mi Same as --builder=Module::Install

--author=name Author's name (taken from getpwuid if not provided)
--email=email Author's email (taken from EMAIL if not provided)
and Email address ( taken from $ENV{EMAIL} if Author's name is not provided )
Format: Author Name <[email protected]>
This option can be supplied multiple times for projects
that have multiple authors.

--ignores=type Ignore type files to include (repeatable)
--license=type License under which the module will be distributed
Expand Down Expand Up @@ -61,6 +64,10 @@ Example:
module-starter --module=Foo::Bar,Foo::Bat \
--author="Andy Lester" [email protected]

module-starter --module=Foo::Bar,Foo::Bat \
--author="Andy Lester <[email protected]> \
--author="Sawyer X <[email protected]>

=head1 DESCRIPTION

C<module-starter> is a command-line interface to L<Module::Starter>, which it
Expand Down Expand Up @@ -97,5 +104,8 @@ configuration file entry. A sample configuration file might read:
This format may become more elaborate in the future, but a file of this type
should remain valid.

Please note, as of right now the configuration file does *not* have support
for multiple authors.

=cut

3 changes: 1 addition & 2 deletions lib/Module/Starter/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ sub _process_command_line {
mb => sub { push @{$config{builder}}, 'Module::Build' },
mi => sub { push @{$config{builder}}, 'Module::Install' },

'author=s' => \$config{author},
'email=s' => \$config{email},
'author=s@' => \@{ $config{author} },
'license=s' => \$config{license},
'minperl=s' => \$config{minperl},
'fatalize' => \$config{fatalize},
Expand Down
69 changes: 41 additions & 28 deletions lib/Module/Starter/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,21 @@ sub create_distro {

if ( ( not $self->{author} ) && ( $^O ne 'MSWin32' ) ) {
( $self->{author} ) = split /,/, ( getpwuid $> )[6];
$self->{author} = [
exists $ENV{EMAIL}
? "$self->{author} <$ENV{EMAIL}>"
: $self->{author}
];
}

if ( not $self->{email} and exists $ENV{EMAIL} ) {
$self->{email} = $ENV{EMAIL};
}

croak "Must specify an author\n" unless $self->{author};
croak "Must specify an email address\n" unless $self->{email};
($self->{email_obfuscated} = $self->{email}) =~ s/@/ at /;
croak "Must specify one or more authors\n"
unless $self->{author}
&& ref($self->{author}) eq 'ARRAY'
&& @{$self->{author}} > 0;

croak "author strings must be in the format: 'Author Name <author-email\@domain.tld>'"
if grep { $_ !~ m/^.*?\s*\<.*?\>\s*$/ } @{$self->{author}};

$self->{license} ||= 'artistic2';
$self->{minperl} ||= 5.006;
$self->{ignores_type} ||= ['generic'];
Expand Down Expand Up @@ -610,7 +615,7 @@ sub _license_blurb {
This program is released under the following license: $self->{license}
EOT

$license_blurb =~ s/___AUTHOR___/$self->{author}/ge;
$license_blurb =~ s/___AUTHOR___/join(',', @{$self->{author}})/ge;
chomp $license_blurb;
return $license_blurb;
}
Expand Down Expand Up @@ -749,8 +754,10 @@ sub Makefile_PL_guts {
my $main_module = shift;
my $main_pm_file = shift;

(my $author = "$self->{author} <$self->{email}>") =~ s/'/\'/g;

my $author = '[' .
join(',', map { s/'/\'/g; "'$_'"; } @{ $self->{author} })
. ']';

my $slname = $self->{license_record} ? $self->{license_record}->{slname} : $self->{license};

my $warnings = sprintf 'warnings%s;', ($self->{fatalize} ? " FATAL => 'all" : '');
Expand All @@ -763,7 +770,7 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => '$main_module',
AUTHOR => q{$author},
AUTHOR => $author,
VERSION_FROM => '$main_pm_file',
ABSTRACT_FROM => '$main_pm_file',
LICENSE => '$slname',
Expand Down Expand Up @@ -799,9 +806,13 @@ sub MI_Makefile_PL_guts {
my $main_module = shift;
my $main_pm_file = shift;

my $author = "$self->{author} <$self->{email}>";
my $author = join ',', @{$self->{author}};
$author =~ s/'/\'/g;


# if there is more than one author, select the first one as
# the repository owner
my ($repo_author) = (split /\s*\</, $self->{author}->[0])[0];

my $license_url = $self->{license_record} ? $self->{license_record}->{url} : '';

my $warnings = sprintf 'warnings%s;', ($self->{fatalize} ? " FATAL => 'all" : '');
Expand All @@ -825,8 +836,8 @@ resources (
#homepage => 'http://yourwebsitehere.com',
#IRC => 'irc://irc.perl.org/#$self->{distro}',
license => '$license_url',
#repository => 'git://github.com/$self->{author}/$self->{distro}.git',
#repository => 'https://bitbucket.org/$self->{author}/$self->{distro}',
#repository => 'git://github.com/$repo_author/$self->{distro}.git',
#repository => 'https://bitbucket.org/$repo_author/$self->{distro}',
bugtracker => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=$self->{distro}',
);
Expand Down Expand Up @@ -891,8 +902,9 @@ sub Build_PL_guts {
my $main_module = shift;
my $main_pm_file = shift;

(my $author = "$self->{author} <$self->{email}>") =~ s/'/\'/g;

my $author = '[' .
join(',', map { s/'/\'/g; "'$_'"; } @{$self->{author}})
. ']';
my $slname = $self->{license_record} ? $self->{license_record}->{slname} : $self->{license};

my $warnings = sprintf 'warnings%s;', ($self->{fatalize} ? " FATAL => 'all" : '');
Expand All @@ -906,7 +918,7 @@ use Module::Build;
my \$builder = Module::Build->new(
module_name => '$main_module',
license => '$slname',
dist_author => q{$author},
dist_author => $author,
dist_version_from => '$main_pm_file',
release_status => 'stable',
configure_requires => {
Expand Down Expand Up @@ -1029,11 +1041,11 @@ sub _README_license {

my $year = $self->_thisyear();
my $license_blurb = $self->_license_blurb();

my $author_string = join ',', @{$self->{author}};
return <<"HERE";
LICENSE AND COPYRIGHT
Copyright (C) $year $self->{author}
Copyright (C) $year $author_string
$license_blurb
HERE
Expand Down Expand Up @@ -1757,11 +1769,11 @@ sub _module_license {

my $license_blurb = $self->_license_blurb();
my $year = $self->_thisyear();

my $author_string = join ',', @{$self->{author}};
my $content = qq[
\=head1 LICENSE AND COPYRIGHT
Copyright $year $self->{author}.
Copyright $year $author_string.
$license_blurb
];
Expand All @@ -1775,11 +1787,12 @@ sub module_guts {
my $rtname = shift;

# Sub-templates
my $header = $self->_module_header($module, $rtname);
my $bugs = $self->_module_bugs($module, $rtname);
my $support = $self->_module_support($module, $rtname);
my $license = $self->_module_license($module, $rtname);

my $header = $self->_module_header($module, $rtname);
my $bugs = $self->_module_bugs($module, $rtname);
my $support = $self->_module_support($module, $rtname);
my $license = $self->_module_license($module, $rtname);
my $author_string = join ',', @{$self->{author}};

my $content = <<"HERE";
$header
Expand Down Expand Up @@ -1817,7 +1830,7 @@ sub function2 {
\=head1 AUTHOR
$self->{author}, C<< <$self->{email_obfuscated}> >>
$author_string
$bugs
Expand Down
47 changes: 30 additions & 17 deletions t/test-dist.t
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ sub parse_paras {
local $Test::Builder::Level = $Test::Builder::Level + 1;

my ($self, $paras, $msg) = @_;

# Construct a large regex.
my $regex =
join '',
Expand Down Expand Up @@ -545,8 +544,7 @@ sub parse_file_start {

my $slname = $LICENSES->{ $self->{license} }->{slname};
my $license_url = $LICENSES->{ $self->{license} }->{url};

(my $authoremail = "$self->{author} <$self->{email}>") =~ s/'/\'/g;

(my $libmod = "lib/$mainmod".'.pm') =~ s|::|/|g;

my $install_pl = $self->{builder} eq 'Module::Build' ? 'Build.PL' : 'Makefile.PL';
Expand Down Expand Up @@ -594,6 +592,9 @@ sub parse_file_start {
}
elsif ($basefn eq 'Build.PL' && $self->{builder} eq 'Module::Build') {
plan tests => 11;
my $authoremail = join ',', map { "'$_'" } @{$self->{author}};
$authoremail =~ s/'/\'/g;

$self->parse($mswb_re,
"Min/Strict/Warning/Builder"
);
Expand All @@ -606,7 +607,7 @@ sub parse_file_start {
"license",
);

$self->parse(qr{\A\s*dist_author *=> *\Qq{$authoremail},\E\n}ms,
$self->parse(qr{\A\s*dist_author *=> *\Q[$authoremail],\E\n}ms,
"dist_author",
);

Expand Down Expand Up @@ -645,6 +646,9 @@ sub parse_file_start {
}
elsif ($basefn eq 'Makefile.PL' && $self->{builder} eq 'ExtUtils::MakeMaker') {
plan tests => 11;
my $authoremail = join ',', map { "'$_'" } @{$self->{author}};
$authoremail =~ s/'/\'/g;

$self->parse($mswb_re,
"Min/Strict/Warning/Builder"
);
Expand All @@ -653,7 +657,7 @@ sub parse_file_start {
"NAME",
);

$self->parse(qr{\A\s*AUTHOR *=> *\Qq{$authoremail},\E\n}ms,
$self->parse(qr{\A\s*AUTHOR *=> *\Q[$authoremail],\E\n}ms,
"AUTHOR",
);

Expand Down Expand Up @@ -693,7 +697,12 @@ sub parse_file_start {
);
}
elsif ($basefn eq 'Makefile.PL' && $self->{builder} eq 'Module::Install') {
plan tests => 13;
plan tests => 13;
# do not quote authoremail combinations for Module::Install since
# author is a string not an arrayref
my $authoremail = join ',', @{$self->{author}};
$authoremail =~ s/'/\'/g;

$self->parse($mswb_re,
"Min/Strict/Warning/Builder"
);
Expand Down Expand Up @@ -722,13 +731,15 @@ sub parse_file_start {
"tests_recursive",
);

my $repo_author = $self->{author}->[0];
($repo_author) = (split /\s*\</, $repo_author)[0];
$self->consume(<<"EOT", 'resources');
resources (
#homepage => 'http://yourwebsitehere.com',
#IRC => 'irc://irc.perl.org/#$distro',
license => '$license_url',
#repository => 'git://github.com/$self->{author}/$distro.git',
#repository => 'https://bitbucket.org/$self->{author}/$self->{distro}',
#repository => 'git://github.com/$repo_author/$distro.git',
#repository => 'https://bitbucket.org/$repo_author/$self->{distro}',
bugtracker => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=$distro',
);
Expand Down Expand Up @@ -1046,7 +1057,7 @@ sub parse_module_start {

my $perl_name = $self->{module};
my $dist_name = $self->{distro};
my $author_name = $self->{author};
my $author_name = join ',', @{$self->{author}};
my $lc_dist_name = lc($dist_name);
my $minperl = $self->{minperl} || 5.006;

Expand Down Expand Up @@ -1121,7 +1132,7 @@ sub parse_module_start {
$self->parse_paras(
[
"=head1 AUTHOR",
{ re => quotemeta($author_name) . q{[^\n]+} },
{ re => quotemeta($author_name) },
],
"AUTHOR",
);
Expand Down Expand Up @@ -1239,6 +1250,7 @@ srand($random_seed);

sub run_settest {
my ($base_dir, $distro_var) = @_;

my $module_base_dir = File::Spec->catdir(qw(t data), ref $base_dir ? @$base_dir : $base_dir);
$distro_var->{dir} = $module_base_dir;

Expand Down Expand Up @@ -1345,8 +1357,10 @@ run_settest('MyModule-Test', {
modules => ['MyModule::Test', 'MyModule::Test::App'],
builder => 'Module::Build',
license => 'artistic2',
author => 'Baruch Spinoza',
email => '[email protected]',
author => [
'Baruch Spinoza <[email protected]>',
'Sandra OConnor <[email protected]>'
],
verbose => 0,
force => $DONT_DEL,
});
Expand All @@ -1361,8 +1375,7 @@ run_settest('Book-Park-Mansfield', {
],
builder => 'Module::Build',
license => 'artistic2',
author => 'Jane Austen',
email => '[email protected]',
author => [ 'Jane Austen <[email protected]>' ],
verbose => 0,
force => $DONT_DEL,
});
Expand Down Expand Up @@ -1409,7 +1422,8 @@ subtest "builder = $builder" => sub {
my $distro = join('-', rstr_array);
my $author = rstr.' '.rstr;
my $email = join('.', rstr_array).'@'.join('.', rstr_array).'.tld';

$author .= ' <$email>';

my @modules;
my $len = int(rand(20)) + 1;
push(@modules, rstr_module ) for (1 .. $len);
Expand All @@ -1430,8 +1444,7 @@ subtest "builder = $builder" => sub {
modules => \@modules,
builder => $builder,
license => $license,
author => $author,
email => $email,
author => [ $author ],
minperl => $minperl,
verbose => 0,
force => $force,
Expand Down

0 comments on commit 5a17f4a

Please sign in to comment.