| 1 | package Dist::Zilla::Plugin::Web::StripBOM; | ||
| 2 | $Dist::Zilla::Plugin::Web::StripBOM::VERSION = '0.0.10'; | ||
| 3 | # ABSTRACT: Embedd module version to sources | ||
| 4 | |||
| 5 | use Moose; | ||
| 6 | |||
| 7 | use Path::Class; | ||
| 8 | use String::BOM qw(string_has_bom strip_bom_from_string); | ||
| 9 | |||
| 10 | with 'Dist::Zilla::Role::FileMunger'; | ||
| 11 | with 'Dist::Zilla::Plugin::Web::Role::FileMatcher'; | ||
| 12 | |||
| 13 | has 'file_match' => ( | ||
| 14 | is => 'rw', | ||
| 15 | |||
| 16 | default => sub { [ '.*' ] } | ||
| 17 | ); | ||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | sub munge_files { | ||
| 22 | my ($self) = @_; | ||
| 23 | |||
| 24 | $self->for_each_matched_file(sub { | ||
| 25 | my ($file) = @_; | ||
| 26 | |||
| 27 | my $content = $file->content; | ||
| 28 | |||
| 29 | if (string_has_bom($content)) { | ||
| 30 | $file->content(strip_bom_from_string($content)); | ||
| 31 | } | ||
| 32 | }); | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | no Moose; | ||
| 37 | __PACKAGE__->meta->make_immutable(); | ||
| 38 | |||
| 39 | |||
| 40 | 1; | ||
| 41 | |||
| 42 | __END__ |