File Coverage

blib/lib/Dist/Inkt/Role/Hg.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1 1     1   983 use 5.010001;
  1         4  
  1         69  
2 1     1   6 use strict;
  1         1  
  1         41  
3 1     1   15 use warnings;
  1         2  
  1         81  
4              
5             package Dist::Inkt::Role::Hg;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.001';
9              
10 1     1   2939 use Moose::Role;
  0            
  0            
11             use File::chdir;
12             use Types::Standard 'Bool';
13             use namespace::autoclean;
14              
15             has source_control_is_hg => (
16             is => "ro",
17             isa => Bool,
18             lazy => 1,
19             builder => "_build_source_control_is_hg",
20             );
21              
22             sub _build_source_control_is_hg
23             {
24             my $self = shift;
25             !! $self->rootdir->child(".hg")->is_dir;
26             }
27              
28             before BuildAll => sub
29             {
30             my $self = shift;
31             return unless $self->source_control_is_hg;
32            
33             local $CWD = $self->rootdir;
34             my $stat = `hg status`;
35             if ($stat =~ /\w/) {
36             $self->log("Mercurial has uncommitted changes");
37             $self->log($_) for grep /\w/, split /\r?\n/, $stat;
38             die "Please commit them";
39             }
40             };
41              
42             after BUILD => sub
43             {
44             my $self = shift;
45             return unless $self->source_control_is_hg;
46             return unless $self->can("setup_postrelease_action");
47            
48             $self->setup_postrelease_action(sub {
49             my $self = shift;
50             local $CWD = $self->rootdir;
51             $self->log("hg tag " . $self->version);
52             system("hg", "tag", $self->version);
53             $self->log("hg push");
54             system("hg", "push");
55             });
56             };
57              
58             1;
59              
60             __END__
61              
62             =pod
63              
64             =encoding utf-8
65              
66             =head1 NAME
67              
68             Dist::Inkt::Role::Hg - Mercurial-related behaviour for Dist::Inkt
69              
70             =head1 DESCRIPTION
71              
72             =over
73              
74             =item *
75              
76             Prevents a release from being built if there are uncommitted changes.
77              
78             =item *
79              
80             Does an << hg tag >> and C<< hg push >> after release.
81              
82             =back
83              
84             =head1 BUGS
85              
86             Please report any bugs to
87             L<http://rt.cpan.org/Dist/Display.html?Queue=Dist-Inkt-Role-Hg>.
88              
89             =head1 SEE ALSO
90              
91             =head1 AUTHOR
92              
93             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
94              
95             =head1 COPYRIGHT AND LICENCE
96              
97             This software is copyright (c) 2014 by Toby Inkster.
98              
99             This is free software; you can redistribute it and/or modify it under
100             the same terms as the Perl 5 programming language system itself.
101              
102              
103             =head1 DISCLAIMER OF WARRANTIES
104              
105             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
106             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
107             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
108