1 package Dist
::Zilla
::Plugin
::Prepender
;
2 # ABSTRACT: prepend lines at the top of your perl files
5 with
'Dist::Zilla::Role::FileMunger';
10 # accept some arguments multiple times.
11 sub multivalue_args
{ qw{ line
} }
19 default => sub { [] },
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)/;
36 # $self->_munge_perl($file);
38 # munge content of perl $file: add stuff at the top of the file
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;
70 line = # This file is part of Foo::Bar
71 line = # Foo::Bar is copyright...
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.
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>.