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
} }
23 default => sub { [] },
30 my ($self, $file) = @_;
32 return $self->_munge_perl($file) if $file->name =~ /\.(?:pm|pl)$/i;
33 return $self->_munge_perl($file) if $file->content =~ /^#!(?:.*)perl(?:$|\s)/;
40 # $self->_munge_perl($file);
42 # munge content of perl $file: add stuff at the top of the file
45 my ($self, $file) = @_;
47 my @lines = split /\n/, $file->content;
49 # add copyright information if requested
50 if ( $self->copyright ) {
53 "This file is part of " . $self->zilla->name,
55 split(/\n/, $self->zilla->license->notice),
58 push @prepend, map { "# $_" } @copyright;
61 # add hand-written lines to prepend
62 push @prepend, $self->_lines;
64 # insertion point depends if there's a shebang line
65 my $id = ( $lines[0] =~ /^#!(?:.*)perl(?:$|\s)/ ) ?
1 : 0;
66 splice @lines, $id, 0, @prepend;
67 $file->content(join "\n", @lines);
70 __PACKAGE__
->meta->make_immutable;
88 line = # This file is part of Foo::Bar
89 line = # Foo::Bar is copyright...
95 This plugin will prepend the specified lines in each Perl module or
96 program within the distribution. For scripts having a shebang line,
97 lines will be inserted just after it.
99 This is useful to enforce a set of pragmas to your files (since pragmas
100 are lexical, they will be active for the whole file), or to add some
101 copyright comments, as the fsf recommends.
105 Please report any bugs or feature request to
106 C<< <bug-dist-zilla-plugin-prepender@rt.cpan.org> >>, or through the web interface
107 at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dist-Zilla-Plugin-Prepender>.