diff --git a/bin/distar-init b/bin/distar-init index b0518f0..7d1df60 100755 --- a/bin/distar-init +++ b/bin/distar-init @@ -3,6 +3,11 @@ use strict; use warnings FATAL => 'all'; use File::Path qw(mkpath); +use Data::Dumper qw(); + +sub _dump_var { + join q[, ], Data::Dumper->new( [@_] )->Indent(0)->Purity(1)->Useqq(0)->Quotekeys(0)->Sortkeys(1)->Terse(1)->Dump(); +} my $project = $ARGV[0] or die "No project name passed"; @@ -12,6 +17,17 @@ my $lib_file = join('/', 'lib', @parts).".pm"; my $author = $ENV{DISTAR_INIT_AUTHOR} or die "DISTAR_INIT_AUTHOR unset"; +my $include_postlude = sprintf "author %s;\n", _dump_var($author); + +if ( $ENV{DISTAR_INIT_GITHUB_USER} ) { + my %github_args; + $github_args{user} = $ENV{DISTAR_INIT_GITHUB_USER}; + if ( $ENV{DISTAR_INIT_GITHUB_ISSUES} ) { + $github_args{issues} = 1; + } + $include_postlude .= sprintf qq[github %s;\n], _dump_var( \%github_args ); +} + mkpath "${project}/maint"; mkpath join('/', $project, 'lib', @parts[0..$#parts-1]); @@ -39,7 +55,7 @@ close($mpl_main); open my $mpl_maint, '>', "${project}/maint/Makefile.PL.include" or die "couldn't open maint/Makefile.PL.include: $!"; -print $mpl_maint sprintf(<<'END', $author); +print $mpl_maint <<'END' . $include_postlude; BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") @@ -47,7 +63,6 @@ BEGIN { use lib 'Distar/lib'; use Distar; -author '%s'; END close($mpl_maint); diff --git a/lib/Distar.pm b/lib/Distar.pm index 2248b39..9232812 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -11,7 +11,7 @@ $VERSION = eval $VERSION; my $MM_VER = eval $ExtUtils::MakeMaker::VERSION; our @EXPORT = qw( - author manifest_include readme_generator + author manifest_include readme_generator github ); sub import { @@ -26,6 +26,40 @@ sub author { if !ref $Author; } +sub github { + our $REPO; + our $BUGTRACKER; + + my (%github_args) = ( ref $_[0] ? %{$_[0]} : @_ ); + + if ( not $github_args{path} and not $github_args{user} ) { + die "github() must specify either a github relative repo-path (ie: path => 'user/repo') or a user => "; + } + my $github_path = sub { + my $distname = shift; + return $github_args{path} if $github_args{path}; + if ( not $distname ) { + die "No distname found"; + } + return $github_args{user} . '/' . $distname; + }; + + $REPO = sub { + my $GH = $github_path->( $_[0] ); + return { + url => 'git://github.com/' . $GH, + web => 'https://github.com/' . $GH, + type => 'git', + }; + }; + if ( $github_args{issues} ) { + $BUGTRACKER = sub { + my $GH = $github_path->( $_[0] ); + return { web => 'https://github.com/' . $GH . '/issues' }; + }; + } +} + our @Manifest = ( 'lib' => '.pm', 'lib' => '.pod', @@ -90,6 +124,19 @@ sub write_manifest_skip { }); } + sub metafile_data { + my ( $self, $meta_add, $meta_merge ) = @_; + if ( $Distar::REPO ) { + $meta_add->{'meta-spec'}->{'version'} ||= 2; + $meta_add->{'resources'}->{'repository'} = $Distar::REPO->( $self->{DISTNAME} ); + } + if ( $Distar::BUGTRACKER ) { + $meta_add->{'meta-spec'}->{'version'} ||= 2; + $meta_add->{'resources'}->{'bugtracker'} = $Distar::BUGTRACKER->( $self->{DISTNAME} ); + } + return $self->SUPER::metafile_data( $meta_add, $meta_merge ); + } + sub flush { my $self = shift; Distar::write_manifest_skip($self); @@ -258,6 +305,27 @@ F, F<.t> files in F and F, F<.pm> files in F and F, F, F, F, F, F, and F<.PL> files in the dist root, and all files in F. +=head2 C + + # Use user "Foo" and assume DISTNAME is the git repo name + github user => 'Foo'; + + # Assume nothing + github path => 'Foo/RepoNameHere'; + + # Also set up issues as being the bug tracker + github issues => 1, user => 'Foo'; + +=over 4 + +=item * C - The user-name and repository name the distribution is stored at on github, eg: C + +=item * C - The user-name the repository is stored under, and assume repository name from C + +=item * C - Sets up Github issues of C as bug tracker metadata + +=back + =head1 AUTOGENERATED FILES =over 4