| 1 | package Dist::Zilla::Plugin::Web::Role::FileMatcher; | ||
| 2 | $Dist::Zilla::Plugin::Web::Role::FileMatcher::VERSION = '0.0.10'; | ||
| 3 | # ABSTRACT: Embedd module version to sources | ||
| 4 | |||
| 5 | use Moose::Role; | ||
| 6 | |||
| 7 | |||
| 8 | has 'file_match' => ( | ||
| 9 | is => 'rw', | ||
| 10 | |||
| 11 | default => sub { [ '^lib/.*\\.js$' ] } | ||
| 12 | ); | ||
| 13 | |||
| 14 | |||
| 15 | has 'exculde_match' => ( | ||
| 16 | is => 'rw', | ||
| 17 | |||
| 18 | default => sub { [] } | ||
| 19 | ); | ||
| 20 | |||
| 21 | |||
| 22 | around mvp_multivalue_args => sub { | ||
| 23 | my ($orig, $self) = @_; | ||
| 24 | |||
| 25 | my $original = $self->$orig; | ||
| 26 | |||
| 27 | qw( file_match exculde_match $original) | ||
| 28 | }; | ||
| 29 | |||
| 30 | |||
| 31 | sub for_each_matched_file { | ||
| 32 | my ($self, $sub) = @_; | ||
| 33 | |||
| 34 | my $matches_regex = qr/\000/; | ||
| 35 | my $exclude_regex = qr/\000/; | ||
| 36 | |||
| 37 | $matches_regex = qr/$_|$matches_regex/ for (@{$self->file_match}); | ||
| 38 | $exclude_regex = qr/$_|$exclude_regex/ for (@{$self->exculde_match}); | ||
| 39 | |||
| 40 | for my $file (@{$self->zilla->files}) { | ||
| 41 | next unless $file->name =~ $matches_regex; | ||
| 42 | next if $file->name =~ $exclude_regex; | ||
| 43 | |||
| 44 | $sub->($file); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | no Moose; | ||
| 50 | |||
| 51 | |||
| 52 | 1; | ||
| 53 | |||
| 54 | __END__ |