1 package Dist
::Zilla
::Plugin
::Prepender
;
2 # ABSTRACT: prepend lines at the top of your perl files
8 with
'Dist::Zilla::Role::FileMunger';
13 # accept some arguments multiple times.
14 sub multivalue_args
{ qw{ line
} }
26 default => sub { [] },
33 my ($self, $file) = @_;
35 return $self->_munge_perl($file) if $file->name =~ /\.(?:pm|pl)$/i;
36 return $self->_munge_perl($file) if $file->content =~ /^#!(?:.*)perl(?:$|\s)/;
43 # $self->_munge_perl($file);
45 # munge content of perl $file: add stuff at the top of the file
48 my ($self, $file) = @_;
50 my @lines = split /\n/, $file->content;
52 # add copyright information if requested
53 if ( $self->copyright ) {
56 "This file is part of " . $self->zilla->name,
58 split(/\n/, $self->zilla->license->notice),
61 push @prepend, map { "# $_" } @copyright;
64 # add hand-written lines to prepend
65 push @prepend, $self->_lines;
67 # insertion point depends if there's a shebang line
68 my $id = ( $lines[0] =~ /^#!(?:.*)perl(?:$|\s)/ ) ?
1 : 0;
69 splice @lines, $id, 0, @prepend;
70 $file->content(join "\n", @lines);
73 __PACKAGE__
->meta->make_immutable;
97 This plugin will prepend the specified lines in each Perl module or
98 program within the distribution. For scripts having a shebang line,
99 lines will be inserted just after it.
101 This is useful to enforce a set of pragmas to your files (since pragmas
102 are lexical, they will be active for the whole file), or to add some
103 copyright comments, as the fsf recommends.
105 The module accepts the following options in its F<dist.ini> section:
109 =item * copyright - whether to insert a boilerplate copyright comment.
112 =item * line - anything you want to add. may be specified multiple
119 Please report any bugs or feature request to
120 C<< <bug-dist-zilla-plugin-prepender@rt.cpan.org> >>, or through the web interface
121 at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dist-Zilla-Plugin-Prepender>.