Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions bin/distar-init
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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]);
Expand Down Expand Up @@ -39,15 +55,14 @@ 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")
}
use lib 'Distar/lib';
use Distar;

author '%s';
END

close($mpl_maint);
Expand Down
70 changes: 69 additions & 1 deletion lib/Distar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -258,6 +305,27 @@ F<lib>, F<.t> files in F<t> and F<xt>, F<.pm> files in F<t/lib> and F<xt/lib>,
F<Changes>, F<MANIFEST>, F<README>, F<LICENSE>, F<META.yml>, and F<.PL> files in
the dist root, and all files in F<maint>.

=head2 C<github>

# 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<path> - The user-name and repository name the distribution is stored at on github, eg: C<haarg/Distar>

=item * C<user> - The user-name the repository is stored under, and assume repository name from C<DISTNAME>

=item * C<issues> - Sets up Github issues of C<path/user> as bug tracker metadata

=back

=head1 AUTOGENERATED FILES

=over 4
Expand Down