X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=samples%2Fgenerate.pl;h=7e67d5789cc5c189a2a6612bc59aa0c4cb2a6abc;hb=683c68d815e9dc2982135c7ef5670e121930c98b;hp=e93562ebbd7b304893bb09b1332c8cd02ee395bc;hpb=2a21a426b896eca2c5be843f178467d4409b969c;p=perl%2Fmodules%2FTask-Devel-Cover-Recommended.git diff --git a/samples/generate.pl b/samples/generate.pl index e93562e..7e67d57 100644 --- a/samples/generate.pl +++ b/samples/generate.pl @@ -11,6 +11,7 @@ use Cwd; use File::Fetch; use File::Spec; use File::Temp 0.19; +use Getopt::Std; use List::Util; use Parse::CPAN::Meta; @@ -30,6 +31,9 @@ my %prereq_desc = ( 'PPI::HTML' => 'Devel::Cover lets you optionally pick between L and L, but it will only use the former if both are installed.', ); +my %opts; +getopts 'n' => \%opts; + sub get_latest_dist { my $dist = shift; @@ -91,6 +95,13 @@ my %eumm_phases = ( build => [ qw ], run => [ qw ], ); +my %meta_phase_relationships = ( + configure => [ qw ], + build => [ qw ], + test => [ qw ], + runtime => [ qw ], +); + my %prereqs = ( configure => { 'ExtUtils::MakeMaker' => '0', @@ -108,7 +119,7 @@ for my $eumm_phase (keys %eumm_phases) { for my $meta_phase (@{$eumm_phases{$eumm_phase}}) { - for my $type (qw) { + for my $type (@{$meta_phase_relationships{$meta_phase}}) { my $phase_prereqs = $meta->{prereqs}{$meta_phase}{$type}; next unless $phase_prereqs; @@ -144,18 +155,28 @@ if (-e $task_file) { } close $old_fh; } -my ($old_task_revision) = $old_task_version =~ /([0-9]+)$/; - -my $new_task_version = version->parse($target_version)->normal; -my $new_task_revision = $old_task_revision; -++$new_task_revision - if version->parse($new_task_version) <= version->parse($old_task_version); -if (($target_version =~ tr/.//) < 2) { - my @components = split /\./, $new_task_version; - $components[2] = $new_task_revision; - $new_task_version = join '.', @components; + +my $new_task_version; + +if ($opts{n}) { + $new_task_version = $old_task_version; } else { - $new_task_version .= ".$new_task_revision"; + my ($old_target_version, $old_task_revision) + = $old_task_version =~ /(.*)\.([0-9]+)$/; + my $new_task_revision; + if (version->parse($target_version) > version->parse($old_target_version)) { + $new_task_revision = 0; + } else { + $new_task_revision = $old_task_revision + 1; + } + $new_task_version = version->parse($target_version)->normal; + if (($target_version =~ tr/.//) < 2) { + my @components = split /\./, $new_task_version; + $components[2] = $new_task_revision; + $new_task_version = join '.', @components; + } else { + $new_task_version .= ".$new_task_revision"; + } } (my $bug_queue = $task_pkg) =~ s/::/-/g; @@ -170,7 +191,7 @@ sub deplist_to_pod { while (@deplist) { my ($module, $version) = splice @deplist, 0, 2; my $X = $module eq 'perl' ? 'C' : 'L'; - $pod .= "=item $X<$module>"; + $pod .= "=item *\n\n$X<$module>"; $pod .= " $version" if $version; $pod .= "\n\n"; if (my $desc = $prereq_desc{$module}) { @@ -188,7 +209,7 @@ sub deplist_to_perl { return '{ }' unless @deplist; my $len = List::Util::max( - map length, @deplist[grep not($_ % 2), 0 .. $#deplist ] + map length, @deplist[grep not($_ % 2), 0 .. $#deplist] ); my $perl = "{\n"; @@ -207,10 +228,15 @@ sub sorthr ($) { map { $_ => $hr->{$_} } sort keys %$hr; } +# Make sure no package FOO statement appears in this file. +my $package_statement = join ' ', 'package', + $task_pkg; + my %vars = ( TARGET_PKG => $target_pkg, TARGET_VERSION => $target_version, TASK_PKG => $task_pkg, + PACKAGE_TASK_PKG => $package_statement, TASK_VERSION => $new_task_version, PERL_PREREQ => $prereqs{perl}, CONFIGURE_PREREQS_POD => deplist_to_pod(sorthr $prereqs{configure}), @@ -226,6 +252,7 @@ my %vars = ( sorthr $prereqs{run}, $target_pkg => $target_version, ), + TESTED_PREREQS => deplist_to_perl(sorthr $prereqs{run}), BUG_EMAIL => $bug_email, BUG_QUEUE => $bug_queue, YEARS => $years, @@ -233,72 +260,77 @@ my %vars = ( my %templates = ( $task_file => <<'TEMPLATE', -package __TASK_PKG__; +__PACKAGE_TASK_PKG__; use strict; use warnings; -=head1 NAME +\=head1 NAME __TASK_PKG__ - Install __TARGET_PKG__ and its recommended dependencies. -=head1 VERSION +\=head1 VERSION Version __TASK_VERSION__ -=cut +\=cut our $VERSION = '__TASK_VERSION__'; -=head1 SYNOPSIS +\=head1 SYNOPSIS $ cpan __TASK_PKG__ $ cpanp -i __TASK_PKG__ $ cpanm __TASK_PKG__ -=head1 DESCRIPTION +\=head1 DESCRIPTION This task module lets you easily install L<__TARGET_PKG__> __TARGET_VERSION__ and all its recommended dependencies. -=head1 DEPENDENCIES +\=head1 DEPENDENCIES -=head2 Configure-time dependencies +\=head2 Configure-time dependencies __CONFIGURE_PREREQS_POD__ -=head2 Build-time and test-time dependencies +\=head2 Build-time and test-time dependencies __BUILD_PREREQS_POD__ -=head2 Run-time dependencies +\=head2 Run-time dependencies __RUN_PREREQS_POD__ -=head1 AUTHOR +\=head1 CAVEATS + +Note that run-time dependencies that are only recommended by __TARGET_PKG__ may not yet be installed at the time __TARGET_PKG__ is tested, as there is no explicit dependency link between them and in that case most CPAN clients default to install prerequisites in alphabetic order. +However, they will be installed when __TASK_PKG__ is, thus will be available when you actually use __TARGET_PKG__. + +\=head1 AUTHOR Vincent Pit, C<< >>, L. You can contact me by mail or on C (vincent). -=head1 BUGS +\=head1 BUGS Please report any bugs or feature requests to C<__BUG_EMAIL__>, or through the web interface at L<__BUG_QUEUE__>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. -=head1 SUPPORT +\=head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc __TASK_PKG__ -=head1 COPYRIGHT & LICENSE +\=head1 COPYRIGHT & LICENSE Copyright __YEARS__ Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut +\=cut 1; # End of __TASK_PKG__ TEMPLATE @@ -328,7 +360,7 @@ my %META = ( build_requires => $BUILD_PREREQS, dynamic_config => 0, resources => { - bugtracker => "http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$dist", + bugtracker => "http://rt.cpan.org/Dist/Display.html?Name=$dist", homepage => "http://search.cpan.org/dist/$dist/", license => 'http://dev.perl.org/licenses/', repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git", @@ -342,6 +374,7 @@ WriteMakefile( VERSION_FROM => $file, ABSTRACT_FROM => $file, PL_FILES => {}, + BUILD_REQUIRES => $BUILD_PREREQS, PREREQ_PM => $RUN_PREREQS, MIN_PERL_VERSION => '__PERL_PREREQ__', META_MERGE => \%META, @@ -353,9 +386,39 @@ WriteMakefile( FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*" } ); +TEMPLATE + # ---------------------------------------------------------------------------- + 't/01-deps.t' => <<'TEMPLATE', +#!perl + +use strict; +use warnings; + +use Test::More; + +my $TESTED_PREREQS = __TESTED_PREREQS__; + +plan tests => keys(%$TESTED_PREREQS) + 1; + +my @tests = map [ $_ => $TESTED_PREREQS->{$_} ], keys %$TESTED_PREREQS; +push @tests, [ '__TARGET_PKG__' => '__TARGET_VERSION__' ]; + +for my $test (@tests) { + my ($module, $version) = @$test; + local $@; + if ($version && $version !~ /^[0._]*$/) { + eval "use $module $version ()"; + is $@, '', "$module v$version is available"; + } else { + eval "use $module ()"; + is $@, '', "any version of $module is available"; + } +} TEMPLATE ); +$templates{$task_file} =~ s/^\\=/=/mg; + my $valid_keys = join '|', keys %vars; $valid_keys = qr/$valid_keys/;