| 1 | use 5.008; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | package Dist::Zilla::Role::SVK::DirtyFiles; | ||
| 6 | # ABSTRACT: provide the allow_dirty & changelog attributes | ||
| 7 | |||
| 8 | use Moose::Role; | ||
| 9 | use Moose::Autobox; | ||
| 10 | use MooseX::Has::Sugar; | ||
| 11 | use MooseX::Types::Moose qw{ ArrayRef Str }; | ||
| 12 | |||
| 13 | use Cwd; use File::Basename; | ||
| 14 | |||
| 15 | # -- attributes | ||
| 16 | |||
| 17 | |||
| 18 | has allow_dirty => ( | ||
| 19 | ro, lazy, | ||
| 20 | isa => ArrayRef[Str], | ||
| 21 | builder => '_build_allow_dirty', | ||
| 22 | ); | ||
| 23 | has changelog => ( ro, isa=>Str, default => 'Changes' ); | ||
| 24 | |||
| 25 | around mvp_multivalue_args => sub { | ||
| 26 | my ($orig, $self) = @_; | ||
| 27 | |||
| 28 | my @start = $self->$orig; | ||
| 29 | return (@start, 'allow_dirty'); | ||
| 30 | }; | ||
| 31 | |||
| 32 | # -- builders & initializers | ||
| 33 | |||
| 34 | sub _build_allow_dirty { [ 'dist.ini', shift->changelog ] } | ||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | sub list_dirty_files | ||
| 40 | { | ||
| 41 | my ($self, $listAllowed) = @_; | ||
| 42 | my $allowlist = $self->allow_dirty; | ||
| 43 | my %allowed = map { $_ => 1 } @$allowlist; | ||
| 44 | my @file = qx "svk status"; | ||
| 45 | my @uncommitted = grep m/^("?M|D)/, @file; | ||
| 46 | chomp @uncommitted; | ||
| 47 | s/^.*\s(\S+)$/$1/ for @uncommitted; | ||
| 48 | return grep { $allowed{$_} ? $listAllowed : ! $listAllowed } @uncommitted; | ||
| 49 | } # end list_dirty_files | ||
| 50 | |||
| 51 | |||
| 52 | no Moose::Role; | ||
| 53 | no MooseX::Has::Sugar; | ||
| 54 | 1; | ||
| 55 | |||
| 56 | |||
| 57 | =pod | ||
| 58 | |||
| 59 | =head1 NAME | ||
| 60 | |||
| 61 | Dist::Zilla::Role::SVK::DirtyFiles - provide the allow_dirty & changelog attributes | ||
| 62 | |||
| 63 | =head1 VERSION | ||
| 64 | |||
| 65 | version 0.10 | ||
| 66 | |||
| 67 | =head1 DESCRIPTION | ||
| 68 | |||
| 69 | This role is used within the svk (was: git) plugin to work with files that are | ||
| 70 | dirty in the local svk checkout. | ||
| 71 | |||
| 72 | =head1 ATTRIBUTES | ||
| 73 | |||
| 74 | =head2 allow_dirty | ||
| 75 | |||
| 76 | A list of files that are allowed to be dirty in the svk checkout. | ||
| 77 | Defaults to C<dist.ini> and the changelog (as defined per the | ||
| 78 | C<changelog> attribute. | ||
| 79 | |||
| 80 | =head2 changelog | ||
| 81 | |||
| 82 | The name of the changelog. Defaults to C<Changes>. | ||
| 83 | |||
| 84 | =head1 METHODS | ||
| 85 | |||
| 86 | =head2 list_dirty_files | ||
| 87 | |||
| 88 | my @dirty = $plugin->list_dirty_files($listAllowed); | ||
| 89 | |||
| 90 | This returns a list of the modified or deleted files in the checkout, filtered against the C<allow_dirty> attribute, excluding dot files. If C<$listAllowed> is true, only allowed files are listed. If it's false, only files that are not allowed to be dirty are listed. | ||
| 91 | |||
| 92 | In scalar context, returns the number of dirty files. | ||
| 93 | |||
| 94 | =for Pod::Coverage mvp_multivalue_args | ||
| 95 | |||
| 96 | =head1 AUTHOR | ||
| 97 | |||
| 98 | Dr Bean <drbean at (a) cpan dot (.) org> | ||
| 99 | |||
| 100 | =head1 COPYRIGHT AND LICENSE | ||
| 101 | |||
| 102 | This software is copyright (c) 2010 by Dr Bean. | ||
| 103 | |||
| 104 | This is free software; you can redistribute it and/or modify it under | ||
| 105 | the same terms as the Perl 5 programming language system itself. | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | |||
| 110 | __END__ |