File Coverage

blib/lib/Dist/Zilla/Plugin/Signature.pm
Criterion Covered Total %
statement 2 4 50.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 4 6 66.6


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Signature;
2             BEGIN {
3 1     1   1462 $Dist::Zilla::Plugin::Signature::VERSION = '1.100930';
4             }
5 1     1   475 use Moose;
  0            
  0            
6             with 'Dist::Zilla::Role::FileGatherer';
7             with 'Dist::Zilla::Role::BeforeArchive';
8             with 'Dist::Zilla::Role::AfterBuild';
9              
10              
11             has sign => (is => 'ro', default => 'archive');
12              
13              
14             sub do_sign {
15             my $self = shift;
16             my $dir = shift;
17              
18             require Module::Signature;
19             require File::chdir;
20              
21             local $File::chdir::CWD = $dir;
22             Module::Signature::sign(overwrite => 1) && die "Cannot sign";
23             }
24              
25             sub before_archive {
26             my $self = shift;
27              
28             $self->do_sign($self->zilla->built_in)
29             if $self->sign =~ /archive/i;
30             }
31              
32             sub after_build {
33             my $self = shift;
34             my $arg = shift;
35              
36             $self->do_sign($arg->{build_root})
37             if $self->sign =~ /always/i;
38             }
39              
40              
41             sub gather_files {
42             my ($self, $arg) = @_;
43              
44             require Dist::Zilla::File::InMemory;
45              
46             my $file = Dist::Zilla::File::InMemory->new(
47             { name => 'SIGNATURE',
48             content => "",
49             }
50             );
51              
52             $self->add_file($file);
53              
54             return;
55             }
56              
57             sub BUILDARGS {
58             my $self = shift;
59             my $args = @_ == 1 ? shift : {@_};
60             $args->{sign} = $ENV{DZSIGN} if exists $ENV{DZSIGN};
61             $args;
62             }
63              
64              
65             no Moose;
66             __PACKAGE__->meta->make_immutable;
67             1;
68              
69             __END__
70             =pod
71              
72             =head1 NAME
73              
74             Dist::Zilla::Plugin::Signature - sign releases with Module::Signature
75              
76              
77             =head1 VERSION
78              
79             version 1.100930
80              
81             =head1 DESCRIPTION
82              
83             This plugin will sign a distribution using Module::Signature.
84              
85             This plugin should appear after any other AfterBuild plugin in your C<dist.ini> file
86             to ensre that no files are modified after it has been run
87              
88             =head1 ATTRIBUTES
89              
90             =over
91              
92             =item sign
93              
94             A string value. If C<archive> then a signature will be created when an archive is being created.
95             If C<always> then the directory will be signed whenever it is built. Default is C<archive>
96              
97             This attribute can be overridden by an environment variable C<DZSIGN>
98              
99             =back
100              
101             =head1 AUTHOR
102              
103             Graham Barr <gbarr@pobox.com>
104              
105             =head1 COPYRIGHT AND LICENSE
106              
107             This software is copyright (c) 2010 by Graham Barr.
108              
109             This is free software; you can redistribute it and/or modify it under
110             the same terms as the Perl 5 programming language system itself.
111              
112             =cut