burak / CPAN-Sys-Info-Driver-BSD

BSD driver for Sys::Info (Perl)

Changed (Δ3.0 KB):

raw changeset »

tools/Build.pm (103 lines added, 0 lines removed)

Up to file-list tools/Build.pm:

1
use strict;
2
use vars qw( $VERSION );
3
use warnings;
4
use File::Find;
5
use File::Spec;
6
use File::Path;
7
use constant RE_VERSION_LINE => qr{
8
   \A \$VERSION \s+ = \s+ ["'] (.+?) ['"] ; (.+?) \z
9
}xms;
10
use constant RE_POD_LINE => qr{
11
\A =head1 \s+ DESCRIPTION \s+ \z
12
}xms;
13
use constant VTEMP  => q{$VERSION = '%s';};
14
use constant MONTHS => qw(
15
   January February March     April   May      June
16
   July    August   September October November December
17
);
18
use constant MONOLITH_TEST_FAIL =>
19
   "\nFAILED! Building the monolithic version failed during unit testing\n\n";
20
21
$VERSION = '0.40';
22
23
sub ACTION_dist {
24
   my $self = shift;
25
   warn  sprintf(
26
            "RUNNING 'dist' Action from subclass %s v%s\n",
27
            ref($self),
28
            $VERSION
29
         );
30
   my @modules;
31
   find {
32
      wanted => sub {
33
         my $file = $_;
34
         return if $file !~ m{ \. pm \z }xms;
35
         $file = File::Spec->catfile( $file );
36
         push @modules, $file;
37
         warn "FOUND Module: $file\n";
38
      },
39
      no_chdir => 1,
40
   }, "lib";
41
   $self->_change_versions( \@modules );
42
   $self->SUPER::ACTION_dist( @_ );
43
}
44
45
sub _change_versions {
46
   my $self  = shift;
47
   my $files = shift;
48
   my $dver  = $self->dist_version;
49
50
   my($mday, $mon, $year) = (localtime time)[3, 4, 5];
51
   my $date = join ' ', $mday, [MONTHS]->[$mon], $year + 1900;
52
53
   warn "CHANGING VERSIONS\n";
54
   warn "\tDISTRO Version: $dver\n";
55
56
   foreach my $mod ( @{ $files } ) {
57
      warn "\tPROCESSING $mod\n";
58
      my $new = $mod . '.new';
59
      open my $RO_FH, '<:raw', $mod or die "Can not open file($mod): $!";
60
      open my $W_FH , '>:raw', $new or die "Can not open file($new): $!";
61
62
      CHANGE_VERSION: while ( my $line = readline $RO_FH ) {
63
         if ( $line =~ RE_VERSION_LINE ) {
64
            my $oldv      = $1;
65
            my $remainder = $2;
66
            warn "\tCHANGED Version from $oldv to $dver\n";
67
            printf $W_FH VTEMP . $remainder, $dver;
68
            last CHANGE_VERSION;
69
         }
70
         print $W_FH $line;
71
      }
72
73
      my $ns  = $mod;
74
         $ns  =~ s{ [\\/]     }{::}xmsg;
75
         $ns  =~ s{ \A lib :: }{}xms;
76
         $ns  =~ s{ \. pm \z  }{}xms;
77
      my $pod = "\nThis document describes version C<$dver> of C<$ns>\n"
78
              . "released on C<$date>.\n"
79
              ;
80
81
      if ( $dver =~ m{[_]}xms ) {
82
         $pod .= "\nB<WARNING>: This version of the module is part of a\n"
83
              .  "developer (beta) release of the distribution and it is\n"
84
              .  "not suitable for production use.\n";
85
      }
86
87
      CHANGE_POD: while ( my $line = readline $RO_FH ) {
88
         print $W_FH $line;
89
         print $W_FH $pod if $line =~ RE_POD_LINE;
90
      }
91
92
      close $RO_FH or die "Can not close file($mod): $!";
93
      close $W_FH  or die "Can not close file($new): $!";
94
95
      unlink($mod) || die "Can not remove original module($mod): $!";
96
      rename( $new, $mod ) || die "Can not rename( $new, $mod ): $!";
97
      warn "\tRENAME Successful!\n";
98
   }
99
100
   return;
101
}
102
103
1;