Skip to content

Commit 5a17f4a

Browse files
author
Hunter McMillen
committed
Add support for multiple authors to Module::Starter; Issue xsawyerx#25
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 <andy@petdance.com> \ --author="Sawyer X <sawyerx@cpan.org> 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.
1 parent 7b7c894 commit 5a17f4a

File tree

4 files changed

+83
-48
lines changed

4 files changed

+83
-48
lines changed

bin/module-starter

+11-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ Options:
2929
--mi Same as --builder=Module::Install
3030

3131
--author=name Author's name (taken from getpwuid if not provided)
32-
--email=email Author's email (taken from EMAIL if not provided)
32+
and Email address ( taken from $ENV{EMAIL} if Author's name is not provided )
33+
Format: Author Name <author_email@domain.tld>
34+
This option can be supplied multiple times for projects
35+
that have multiple authors.
3336

3437
--ignores=type Ignore type files to include (repeatable)
3538
--license=type License under which the module will be distributed
@@ -61,6 +64,10 @@ Example:
6164
module-starter --module=Foo::Bar,Foo::Bat \
6265
--author="Andy Lester" --email=andy@petdance.com
6366

67+
module-starter --module=Foo::Bar,Foo::Bat \
68+
--author="Andy Lester <andy@petdance.com> \
69+
--author="Sawyer X <sawyerx@cpan.org>
70+
6471
=head1 DESCRIPTION
6572

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

107+
Please note, as of right now the configuration file does *not* have support
108+
for multiple authors.
109+
100110
=cut
101111

lib/Module/Starter/App.pm

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ sub _process_command_line {
7878
mb => sub { push @{$config{builder}}, 'Module::Build' },
7979
mi => sub { push @{$config{builder}}, 'Module::Install' },
8080

81-
'author=s' => \$config{author},
82-
'email=s' => \$config{email},
81+
'author=s@' => \@{ $config{author} },
8382
'license=s' => \$config{license},
8483
'minperl=s' => \$config{minperl},
8584
'fatalize' => \$config{fatalize},

lib/Module/Starter/Simple.pm

+41-28
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,21 @@ sub create_distro {
9595

9696
if ( ( not $self->{author} ) && ( $^O ne 'MSWin32' ) ) {
9797
( $self->{author} ) = split /,/, ( getpwuid $> )[6];
98+
$self->{author} = [
99+
exists $ENV{EMAIL}
100+
? "$self->{author} <$ENV{EMAIL}>"
101+
: $self->{author}
102+
];
98103
}
99104

100-
if ( not $self->{email} and exists $ENV{EMAIL} ) {
101-
$self->{email} = $ENV{EMAIL};
102-
}
103-
104-
croak "Must specify an author\n" unless $self->{author};
105-
croak "Must specify an email address\n" unless $self->{email};
106-
($self->{email_obfuscated} = $self->{email}) =~ s/@/ at /;
105+
croak "Must specify one or more authors\n"
106+
unless $self->{author}
107+
&& ref($self->{author}) eq 'ARRAY'
108+
&& @{$self->{author}} > 0;
107109

110+
croak "author strings must be in the format: 'Author Name <author-email\@domain.tld>'"
111+
if grep { $_ !~ m/^.*?\s*\<.*?\>\s*$/ } @{$self->{author}};
112+
108113
$self->{license} ||= 'artistic2';
109114
$self->{minperl} ||= 5.006;
110115
$self->{ignores_type} ||= ['generic'];
@@ -610,7 +615,7 @@ sub _license_blurb {
610615
This program is released under the following license: $self->{license}
611616
EOT
612617

613-
$license_blurb =~ s/___AUTHOR___/$self->{author}/ge;
618+
$license_blurb =~ s/___AUTHOR___/join(',', @{$self->{author}})/ge;
614619
chomp $license_blurb;
615620
return $license_blurb;
616621
}
@@ -749,8 +754,10 @@ sub Makefile_PL_guts {
749754
my $main_module = shift;
750755
my $main_pm_file = shift;
751756

752-
(my $author = "$self->{author} <$self->{email}>") =~ s/'/\'/g;
753-
757+
my $author = '[' .
758+
join(',', map { s/'/\'/g; "'$_'"; } @{ $self->{author} })
759+
. ']';
760+
754761
my $slname = $self->{license_record} ? $self->{license_record}->{slname} : $self->{license};
755762

756763
my $warnings = sprintf 'warnings%s;', ($self->{fatalize} ? " FATAL => 'all" : '');
@@ -763,7 +770,7 @@ use ExtUtils::MakeMaker;
763770
764771
WriteMakefile(
765772
NAME => '$main_module',
766-
AUTHOR => q{$author},
773+
AUTHOR => $author,
767774
VERSION_FROM => '$main_pm_file',
768775
ABSTRACT_FROM => '$main_pm_file',
769776
LICENSE => '$slname',
@@ -799,9 +806,13 @@ sub MI_Makefile_PL_guts {
799806
my $main_module = shift;
800807
my $main_pm_file = shift;
801808

802-
my $author = "$self->{author} <$self->{email}>";
809+
my $author = join ',', @{$self->{author}};
803810
$author =~ s/'/\'/g;
804-
811+
812+
# if there is more than one author, select the first one as
813+
# the repository owner
814+
my ($repo_author) = (split /\s*\</, $self->{author}->[0])[0];
815+
805816
my $license_url = $self->{license_record} ? $self->{license_record}->{url} : '';
806817

807818
my $warnings = sprintf 'warnings%s;', ($self->{fatalize} ? " FATAL => 'all" : '');
@@ -825,8 +836,8 @@ resources (
825836
#homepage => 'http://yourwebsitehere.com',
826837
#IRC => 'irc://irc.perl.org/#$self->{distro}',
827838
license => '$license_url',
828-
#repository => 'git://github.com/$self->{author}/$self->{distro}.git',
829-
#repository => 'https://bitbucket.org/$self->{author}/$self->{distro}',
839+
#repository => 'git://github.com/$repo_author/$self->{distro}.git',
840+
#repository => 'https://bitbucket.org/$repo_author/$self->{distro}',
830841
bugtracker => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=$self->{distro}',
831842
);
832843
@@ -891,8 +902,9 @@ sub Build_PL_guts {
891902
my $main_module = shift;
892903
my $main_pm_file = shift;
893904

894-
(my $author = "$self->{author} <$self->{email}>") =~ s/'/\'/g;
895-
905+
my $author = '[' .
906+
join(',', map { s/'/\'/g; "'$_'"; } @{$self->{author}})
907+
. ']';
896908
my $slname = $self->{license_record} ? $self->{license_record}->{slname} : $self->{license};
897909

898910
my $warnings = sprintf 'warnings%s;', ($self->{fatalize} ? " FATAL => 'all" : '');
@@ -906,7 +918,7 @@ use Module::Build;
906918
my \$builder = Module::Build->new(
907919
module_name => '$main_module',
908920
license => '$slname',
909-
dist_author => q{$author},
921+
dist_author => $author,
910922
dist_version_from => '$main_pm_file',
911923
release_status => 'stable',
912924
configure_requires => {
@@ -1029,11 +1041,11 @@ sub _README_license {
10291041

10301042
my $year = $self->_thisyear();
10311043
my $license_blurb = $self->_license_blurb();
1032-
1044+
my $author_string = join ',', @{$self->{author}};
10331045
return <<"HERE";
10341046
LICENSE AND COPYRIGHT
10351047
1036-
Copyright (C) $year $self->{author}
1048+
Copyright (C) $year $author_string
10371049
10381050
$license_blurb
10391051
HERE
@@ -1757,11 +1769,11 @@ sub _module_license {
17571769

17581770
my $license_blurb = $self->_license_blurb();
17591771
my $year = $self->_thisyear();
1760-
1772+
my $author_string = join ',', @{$self->{author}};
17611773
my $content = qq[
17621774
\=head1 LICENSE AND COPYRIGHT
17631775
1764-
Copyright $year $self->{author}.
1776+
Copyright $year $author_string.
17651777
17661778
$license_blurb
17671779
];
@@ -1775,11 +1787,12 @@ sub module_guts {
17751787
my $rtname = shift;
17761788

17771789
# Sub-templates
1778-
my $header = $self->_module_header($module, $rtname);
1779-
my $bugs = $self->_module_bugs($module, $rtname);
1780-
my $support = $self->_module_support($module, $rtname);
1781-
my $license = $self->_module_license($module, $rtname);
1782-
1790+
my $header = $self->_module_header($module, $rtname);
1791+
my $bugs = $self->_module_bugs($module, $rtname);
1792+
my $support = $self->_module_support($module, $rtname);
1793+
my $license = $self->_module_license($module, $rtname);
1794+
my $author_string = join ',', @{$self->{author}};
1795+
17831796
my $content = <<"HERE";
17841797
$header
17851798
@@ -1817,7 +1830,7 @@ sub function2 {
18171830
18181831
\=head1 AUTHOR
18191832
1820-
$self->{author}, C<< <$self->{email_obfuscated}> >>
1833+
$author_string
18211834
18221835
$bugs
18231836

t/test-dist.t

+30-17
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ sub parse_paras {
506506
local $Test::Builder::Level = $Test::Builder::Level + 1;
507507

508508
my ($self, $paras, $msg) = @_;
509-
510509
# Construct a large regex.
511510
my $regex =
512511
join '',
@@ -545,8 +544,7 @@ sub parse_file_start {
545544

546545
my $slname = $LICENSES->{ $self->{license} }->{slname};
547546
my $license_url = $LICENSES->{ $self->{license} }->{url};
548-
549-
(my $authoremail = "$self->{author} <$self->{email}>") =~ s/'/\'/g;
547+
550548
(my $libmod = "lib/$mainmod".'.pm') =~ s|::|/|g;
551549

552550
my $install_pl = $self->{builder} eq 'Module::Build' ? 'Build.PL' : 'Makefile.PL';
@@ -594,6 +592,9 @@ sub parse_file_start {
594592
}
595593
elsif ($basefn eq 'Build.PL' && $self->{builder} eq 'Module::Build') {
596594
plan tests => 11;
595+
my $authoremail = join ',', map { "'$_'" } @{$self->{author}};
596+
$authoremail =~ s/'/\'/g;
597+
597598
$self->parse($mswb_re,
598599
"Min/Strict/Warning/Builder"
599600
);
@@ -606,7 +607,7 @@ sub parse_file_start {
606607
"license",
607608
);
608609

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

@@ -645,6 +646,9 @@ sub parse_file_start {
645646
}
646647
elsif ($basefn eq 'Makefile.PL' && $self->{builder} eq 'ExtUtils::MakeMaker') {
647648
plan tests => 11;
649+
my $authoremail = join ',', map { "'$_'" } @{$self->{author}};
650+
$authoremail =~ s/'/\'/g;
651+
648652
$self->parse($mswb_re,
649653
"Min/Strict/Warning/Builder"
650654
);
@@ -653,7 +657,7 @@ sub parse_file_start {
653657
"NAME",
654658
);
655659

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

@@ -693,7 +697,12 @@ sub parse_file_start {
693697
);
694698
}
695699
elsif ($basefn eq 'Makefile.PL' && $self->{builder} eq 'Module::Install') {
696-
plan tests => 13;
700+
plan tests => 13;
701+
# do not quote authoremail combinations for Module::Install since
702+
# author is a string not an arrayref
703+
my $authoremail = join ',', @{$self->{author}};
704+
$authoremail =~ s/'/\'/g;
705+
697706
$self->parse($mswb_re,
698707
"Min/Strict/Warning/Builder"
699708
);
@@ -722,13 +731,15 @@ sub parse_file_start {
722731
"tests_recursive",
723732
);
724733

734+
my $repo_author = $self->{author}->[0];
735+
($repo_author) = (split /\s*\</, $repo_author)[0];
725736
$self->consume(<<"EOT", 'resources');
726737
resources (
727738
#homepage => 'http://yourwebsitehere.com',
728739
#IRC => 'irc://irc.perl.org/#$distro',
729740
license => '$license_url',
730-
#repository => 'git://github.com/$self->{author}/$distro.git',
731-
#repository => 'https://bitbucket.org/$self->{author}/$self->{distro}',
741+
#repository => 'git://github.com/$repo_author/$distro.git',
742+
#repository => 'https://bitbucket.org/$repo_author/$self->{distro}',
732743
bugtracker => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=$distro',
733744
);
734745
@@ -1046,7 +1057,7 @@ sub parse_module_start {
10461057

10471058
my $perl_name = $self->{module};
10481059
my $dist_name = $self->{distro};
1049-
my $author_name = $self->{author};
1060+
my $author_name = join ',', @{$self->{author}};
10501061
my $lc_dist_name = lc($dist_name);
10511062
my $minperl = $self->{minperl} || 5.006;
10521063

@@ -1121,7 +1132,7 @@ sub parse_module_start {
11211132
$self->parse_paras(
11221133
[
11231134
"=head1 AUTHOR",
1124-
{ re => quotemeta($author_name) . q{[^\n]+} },
1135+
{ re => quotemeta($author_name) },
11251136
],
11261137
"AUTHOR",
11271138
);
@@ -1239,6 +1250,7 @@ srand($random_seed);
12391250

12401251
sub run_settest {
12411252
my ($base_dir, $distro_var) = @_;
1253+
12421254
my $module_base_dir = File::Spec->catdir(qw(t data), ref $base_dir ? @$base_dir : $base_dir);
12431255
$distro_var->{dir} = $module_base_dir;
12441256

@@ -1345,8 +1357,10 @@ run_settest('MyModule-Test', {
13451357
modules => ['MyModule::Test', 'MyModule::Test::App'],
13461358
builder => 'Module::Build',
13471359
license => 'artistic2',
1348-
author => 'Baruch Spinoza',
1349-
email => 'spinoza@philosophers.tld',
1360+
author => [
1361+
'Baruch Spinoza <spinoza@philosophers.tld>',
1362+
'Sandra OConnor <sdoc@philosphers.tld>'
1363+
],
13501364
verbose => 0,
13511365
force => $DONT_DEL,
13521366
});
@@ -1361,8 +1375,7 @@ run_settest('Book-Park-Mansfield', {
13611375
],
13621376
builder => 'Module::Build',
13631377
license => 'artistic2',
1364-
author => 'Jane Austen',
1365-
email => 'jane.austen@writers.tld',
1378+
author => [ 'Jane Austen <jane.austen@writers.tld>' ],
13661379
verbose => 0,
13671380
force => $DONT_DEL,
13681381
});
@@ -1409,7 +1422,8 @@ subtest "builder = $builder" => sub {
14091422
my $distro = join('-', rstr_array);
14101423
my $author = rstr.' '.rstr;
14111424
my $email = join('.', rstr_array).'@'.join('.', rstr_array).'.tld';
1412-
1425+
$author .= ' <$email>';
1426+
14131427
my @modules;
14141428
my $len = int(rand(20)) + 1;
14151429
push(@modules, rstr_module ) for (1 .. $len);
@@ -1430,8 +1444,7 @@ subtest "builder = $builder" => sub {
14301444
modules => \@modules,
14311445
builder => $builder,
14321446
license => $license,
1433-
author => $author,
1434-
email => $email,
1447+
author => [ $author ],
14351448
minperl => $minperl,
14361449
verbose => 0,
14371450
force => $force,

0 commit comments

Comments
 (0)