1use strict; use warnings; 2 3use CPAN::Meta; 4use Software::LicenseUtils; 5use Pod::Readme::Brief; 6 7sub slurp { open my $fh, '<', $_[0] or die "Couldn't open $_[0] to read: $!\n"; readline $fh } 8 9chdir $ARGV[0] or die "Cannot chdir to $ARGV[0]: $!\n"; 10 11my %file; 12 13my $meta = CPAN::Meta->load_file( 'META.json' ); 14 15my $license = do { 16 my @key = ( $meta->license, $meta->meta_spec_version ); 17 my ( $class, @ambiguous ) = Software::LicenseUtils->guess_license_from_meta_key( @key ); 18 die if @ambiguous; 19 $class->new( $meta->custom( 'x_copyright' ) ); 20}; 21 22$file{'LICENSE'} = $license->fulltext; 23 24my @source = slurp 'lib/XML/Atom/SimpleFeed.pm'; 25splice @source, -2, 0, map "$_\n", '', '=head1 AUTHOR', '', $meta->authors; 26splice @source, -2, 0, split /(?<=\n)/, "\n=head1 COPYRIGHT AND LICENSE\n\n" . $license->notice; 27$file{'lib/XML/Atom/SimpleFeed.pm'} = join '', @source; 28 29die unless -e 'Makefile.PL'; 30$file{'README'} = Pod::Readme::Brief->new( @source )->render( installer => 'eumm' ); 31 32my @manifest = slurp 'MANIFEST'; 33my %manifest = map /\A([^\s#]+)()/, @manifest; 34$file{'MANIFEST'} = join '', sort @manifest, map "$_\n", grep !exists $manifest{ $_ }, keys %file; 35 36for my $fn ( sort keys %file ) { 37 unlink $fn if -e $fn; 38 open my $fh, '>', $fn or die "Couldn't open $fn to write: $!\n"; 39 print $fh $file{ $fn }; 40 close $fh or die "Couldn't close $fn after writing: $!\n"; 41} 42