| 1 | package Dist::Inkt::Role::SignDistribution; | ||
| 2 | |||
| 3 | our $AUTHORITY = 'cpan:TOBYINK'; | ||
| 4 | our $VERSION = '0.026'; | ||
| 5 | |||
| 6 | use Moose::Role; | ||
| 7 | use Module::Signature (); | ||
| 8 | use Types::Standard qw(Bool); | ||
| 9 | use File::chdir; | ||
| 10 | use namespace::autoclean; | ||
| 11 | |||
| 12 | has should_sign => ( | ||
| 13 | is => 'ro', | ||
| 14 | isa => Bool, | ||
| 15 | default => sub { !$ENV{PERL_DIST_INKT_NOSIGNATURE} }, | ||
| 16 | ); | ||
| 17 | |||
| 18 | after BUILD => sub { | ||
| 19 | my $self = shift; | ||
| 20 | unshift @{ $self->targets }, 'SIGNATURE' if $self->should_sign; | ||
| 21 | }; | ||
| 22 | |||
| 23 | sub Build_SIGNATURE | ||
| 24 | { | ||
| 25 | my $self = shift; | ||
| 26 | my $file = $self->targetfile('SIGNATURE'); | ||
| 27 | $file->exists and return $self->log('Skipping %s; it already exists', $file); | ||
| 28 | $self->log('Writing %s', $file); | ||
| 29 | $self->rights_for_generated_files->{'SIGNATURE'} ||= [ | ||
| 30 | 'None', 'public-domain' | ||
| 31 | ]; | ||
| 32 | $file->spew('placeholder'); | ||
| 33 | } | ||
| 34 | |||
| 35 | after BuildManifest => sub { | ||
| 36 | my $self = shift; | ||
| 37 | |||
| 38 | $self->should_sign or return; | ||
| 39 | $self->targetfile('SIGNATURE')->exists or die("Missing SIGNATURE"); | ||
| 40 | |||
| 41 | local $CWD = $self->targetdir; | ||
| 42 | system("cpansign sign"); | ||
| 43 | if ($?) { | ||
| 44 | $self->log("ERROR: signature failed!!!"); | ||
| 45 | die("Bailing out"); | ||
| 46 | } | ||
| 47 | }; | ||
| 48 | |||
| 49 | 1; |