1 2use strict ; 3use warnings ; 4 5use Module::Build; 6 7my %all_modules ; 8my @split_modules ; 9 10my @pm_files = qw( 11lib/Term/Bash/Completion//Generator.pm 12); 13 14for(@pm_files) 15 { 16 $all_modules{$_} = $_ ; 17 push @split_modules, $_ ; 18 } 19 20sub GetVersionAndRevisionFrom 21{ 22my ($file) = @_ ; 23 24my $version_from = File::Spec->catfile( split '/', $file ); 25my $version = Module::Build->version_from_file($version_from); 26 27if($ENV{'Term_Bash_Completion_Generator_USE_GIT_VERSION_FOR_DIST'}) 28 { 29 my $number_of_commits = `git log | grep -E 'commit [0-9a-f]{40}' | wc -l` ; 30 chomp $number_of_commits ; 31 32 if($number_of_commits) 33 { 34 #~ print "number of git revision $number_of_commits.\n" ; 35 return("${version}.${number_of_commits}") ; 36 } 37 else 38 { 39 print "Couldn't get git revision, using version from '$file'!\n" ; 40 return($version) ; 41 } 42 } 43else 44 { 45 return($version) ; 46 } 47} 48 49my $code = <<'EOC' 50 51use strict ; 52use warnings ; 53 54sub GetVersionAndRevisionFrom 55{ 56my ($file) = @_ ; 57 58my $version_from = File::Spec->catfile( split '/', $file ); 59my $version = Module::Build->version_from_file($version_from); 60 61if($ENV{'Term_Bash_Completion_Generator_USE_GIT_VERSION_FOR_DIST'}) 62 { 63 my $number_of_commits = `git log | grep -E 'commit [0-9a-f]{40}' | wc -l` ; 64 chomp $number_of_commits ; 65 66 if($number_of_commits) 67 { 68 #~ print "number of git revision $number_of_commits.\n" ; 69 return("${version}.${number_of_commits}") ; 70 } 71 else 72 { 73 print "Couldn't get git revision, using version from '$file'!\n" ; 74 return($version) ; 75 } 76 } 77else 78 { 79 return($version) ; 80 } 81} 82 83sub ACTION_author_test 84{ 85my $self = shift; 86local $self->{properties}{test_files} = 'xt/author/*.t' ; 87$self->SUPER::ACTION_test(); 88} 89 90sub ACTION_dist 91{ 92my $self = shift; 93 94if($ENV{'Term_Bash_Completion_Generator_USE_GIT_VERSION_FOR_DIST'}) 95 { 96 my $have_git = $self->do_system('git --version'); 97 98 if($have_git) 99 { 100 print `git status -a`; 101 102 if($self->do_system('git log --decorate > git_Changes')) 103 { 104 use File::Copy; 105 move('git_Changes', 'Changes') ; 106 } 107 else 108 { 109 print "Couldn't get git log, 'Changes' will not be generated from git log!\n" ; 110 } 111 } 112 else 113 { 114 print "git not found, 'Changes' will not be generated from git log!\n" ; 115 } 116 } 117 118$self->SUPER::ACTION_test() ; 119#~ $self->ACTION_author_test() ; 120 121$self->SUPER::ACTION_dist(); 122}; 123 124EOC 125; 126 127my $class = Module::Build->subclass(class => 'Term::Bash::Completion::Generator', code => $code) ; 128 129my $build = $class->new 130 ( 131 module_name => 'Term::Bash::Completion::Generator', 132 133 dist_version => GetVersionAndRevisionFrom('lib/Term/Bash/Completion/Generator.pm'), 134 135 license => 'perl', 136 build_requires => 137 { 138 'Text::Diff' => 0, 139 'Test::Block' => 0, 140 'Test::Exception' => 0, 141 'Test::NoWarnings' => 0, 142 'Test::Warn' => 0, 143 }, 144 requires => 145 { 146 'Readonly' => 0, 147 'Sub::Exporter' => 0, 148 'Tree::Trie' => 0, 149 'IO::Select' => 0, 150 }, 151 152 pm_files => \%all_modules, 153 autosplit => \@split_modules, 154 155 script_files => 'scripts/generate_perl_completion_script', 156 dist_author => 'Nadim ibn hamouda el Khemir. <nkh@cpan.org>', 157 dist_abstract => 'Generate bash completion scripts', 158 ); 159 160$build->create_build_script; 161 162