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
76 This plugin will prepend the specified lines in each Perl module or
77 program within the distribution. For scripts having a shebang line,
78 lines will be inserted just after it.
80 This is useful to enforce a set of pragmas to your files (since pragmas
81 are lexical, they will be active for the whole file), or to add some
82 copyright comments, as the fsf recommends.