1package MyBuilder;
2
3use base qw( Module::Build );
4
5sub create_build_script {
6  my ( $self, @args ) = @_;
7  $self->_auto_mm;
8  return $self->SUPER::create_build_script( @args );
9}
10
11sub _auto_mm {
12  my $self = shift;
13  my $mm   = $self->meta_merge;
14  my @meta = qw( homepage bugtracker MailingList repository );
15  for my $meta ( @meta ) {
16    next if exists $mm->{resources}{$meta};
17    my $auto = "_auto_$meta";
18    next unless $self->can( $auto );
19    my $av = $self->$auto();
20    $mm->{resources}{$meta} = $av if defined $av;
21  }
22  $self->meta_merge( $mm );
23}
24
25sub _auto_repository {
26  my $self = shift;
27  if ( -d '.svn' ) {
28    my $info = `svn info .`;
29    return $1 if $info =~ /^URL:\s+(.+)$/m;
30  }
31  elsif ( -d '.git' ) {
32    my $info = `git remote -v`;
33    return unless $info =~ /^origin\s+(.+)$/m;
34    my $url = $1;
35    # Special case: patch up github URLs
36    $url =~ s!^git\@github\.com:!git://github.com/!;
37    return $url;
38  }
39  return;
40}
41
42sub _auto_bugtracker {
43  'http://rt.cpan.org/NoAuth/Bugs.html?Dist=' . shift->dist_name;
44}
45
46sub ACTION_disttest {
47  my $self = shift;
48  $self->SUPER::ACTION_disttest( @_ );
49}
50
51sub ACTION_tags {
52  exec(
53    qw(
54     ctags -f tags --recurse --totals
55     --exclude=blib
56     --exclude=.svn
57     --exclude='*~'
58     --languages=Perl
59     t/ lib/
60     )
61  );
62}
63
64sub ACTION_tidy {
65  my $self = shift;
66
67  my @extra = qw( Build.PL );
68
69  my %found_files = map { %$_ } $self->find_pm_files,
70   $self->_find_file_by_type( 'pm', 'inc' ),
71   $self->_find_file_by_type( 'pm', 't' ),
72   $self->_find_file_by_type( 't',  't' ),
73   $self->_find_file_by_type( 'pm', 'xt' ),
74   $self->_find_file_by_type( 't',  'xt' );
75
76  my @files = ( keys %found_files,
77    map { $self->localize_file_path( $_ ) } @extra );
78
79  for my $file ( @files ) {
80    system 'perltidy', '-b', $file;
81    unlink "$file.bak" if $? == 0;
82  }
83}
84
851;
86