pod update
[dist-zilla-plugin-prepender.git] / lib / Dist / Zilla / Plugin / Prepender.pm
blob9320464b0ce0d30aa020b6ccf77e3643adf681b1
1 package Dist::Zilla::Plugin::Prepender;
2 # ABSTRACT: prepend lines at the top of your perl files
4 use Moose;
5 with 'Dist::Zilla::Role::FileMunger';
8 # -- attributes
10 # accept some arguments multiple times.
11 sub multivalue_args { qw{ line } }
13 has _lines => (
14 is => 'ro',
15 isa => 'ArrayRef',
16 lazy => 1,
17 auto_deref => 1,
18 init_arg => 'line',
19 default => sub { [] },
23 # -- public methods
25 sub munge_file {
26 my ($self, $file) = @_;
28 return $self->_munge_perl($file) if $file->name =~ /\.(?:pm|pl)$/i;
29 return $self->_munge_perl($file) if $file->content =~ /^#!(?:.*)perl(?:$|\s)/;
30 return;
33 # -- private methods
36 # $self->_munge_perl($file);
38 # munge content of perl $file: add stuff at the top of the file
40 sub _munge_perl {
41 my ($self, $file) = @_;
42 my $stuff = join "\n", $self->_lines;
43 my @lines = split /\n/, $file->content;
45 # if there's a shebang line, insert stuff just after it
46 my $id = ( $lines[0] =~ /^#!(?:.*)perl(?:$|\s)/ ) ? 1 : 0;
48 splice @lines, $id, 0, $stuff;
49 $file->content(join "\n", @lines);
52 __PACKAGE__->meta->make_immutable;
53 no Moose;
56 __END__
58 =begin Pod::Coverage
60 multivalue_args
61 munge_file
63 =end Pod::Coverage
65 =head1 SYNOPSIS
67 In your F<dist.ini>:
69 [Prepender]
70 line = # This file is part of Foo::Bar
71 line = # Foo::Bar is copyright...
72 line = use strict;
73 line = use warnings;
75 =head1 DESCRIPTION
77 This plugin will prepend the specified lines in each Perl module or
78 program within the distribution. For scripts having a shebang line,
79 lines will be inserted just after it.
81 This is useful to enforce a set of pragmas to your files (since pragmas
82 are lexical, they will be active for the whole file), or to add some
83 copyright comments, as the fsf recommends.
85 =head1 BUGS
87 Please report any bugs or feature request to
88 C<< <bug-dist-zilla-plugin-prepender@rt.cpan.org> >>, or through the web interface
89 at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dist-Zilla-Plugin-Prepender>.