From 70fd5bbda9a0099ed3e9cd963e02e2d3da2d0ca3 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Tue, 12 Jan 2016 18:12:46 +1300 Subject: [PATCH 1/4] Add a `github` function to provision github-oriented metadata --- lib/Distar.pm | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/lib/Distar.pm b/lib/Distar.pm index 2248b39..8714e00 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) = @_; + + 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 From 944fa91eb1aa23e354c4d707af3d619416a101e4 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Tue, 12 Jan 2016 18:31:45 +1300 Subject: [PATCH 2/4] Allow github() helper to take a hashref instead of a balanced pair set --- lib/Distar.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Distar.pm b/lib/Distar.pm index 8714e00..9232812 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -30,7 +30,7 @@ sub github { our $REPO; our $BUGTRACKER; - my (%github_args) = @_; + 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 => "; From e8ea2b836ecc37996c15d37bb657e01a4ad49ace Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Tue, 12 Jan 2016 18:39:32 +1300 Subject: [PATCH 3/4] Add support for adding github magic based on ENV flags --- bin/distar-init | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/distar-init b/bin/distar-init index b0518f0..bc63fde 100755 --- a/bin/distar-init +++ b/bin/distar-init @@ -12,6 +12,19 @@ my $lib_file = join('/', 'lib', @parts).".pm"; my $author = $ENV{DISTAR_INIT_AUTHOR} or die "DISTAR_INIT_AUTHOR unset"; +my $include_postlude = ""; + +if ( $ENV{DISTAR_INIT_GITHUB_USER} ) { + require Data::Dumper; + 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], + scalar Data::Dumper->new([\%github_args])->Indent(0)->Purity(1)->Useqq(0)->Quotekeys(0)->Sortkeys(1)->Terse(1)->Dump(); +} + mkpath "${project}/maint"; mkpath join('/', $project, 'lib', @parts[0..$#parts-1]); @@ -39,7 +52,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 sprintf(<<'END', $author, $include_postlude); BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") @@ -48,6 +61,7 @@ use lib 'Distar/lib'; use Distar; author '%s'; +%s END close($mpl_maint); From 9e4d51df3fcf1d0de56d3a1d31691dcb41537925 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Tue, 12 Jan 2016 20:57:06 +1300 Subject: [PATCH 4/4] Unify Makefile.PL.include postlude generation logic --- bin/distar-init | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/distar-init b/bin/distar-init index bc63fde..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,17 +17,15 @@ my $lib_file = join('/', 'lib', @parts).".pm"; my $author = $ENV{DISTAR_INIT_AUTHOR} or die "DISTAR_INIT_AUTHOR unset"; -my $include_postlude = ""; +my $include_postlude = sprintf "author %s;\n", _dump_var($author); if ( $ENV{DISTAR_INIT_GITHUB_USER} ) { - require Data::Dumper; 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], - scalar Data::Dumper->new([\%github_args])->Indent(0)->Purity(1)->Useqq(0)->Quotekeys(0)->Sortkeys(1)->Terse(1)->Dump(); + $include_postlude .= sprintf qq[github %s;\n], _dump_var( \%github_args ); } mkpath "${project}/maint"; @@ -52,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, $include_postlude); +print $mpl_maint <<'END' . $include_postlude; BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") @@ -60,8 +63,6 @@ BEGIN { use lib 'Distar/lib'; use Distar; -author '%s'; -%s END close($mpl_maint);