cleaned up some debug prints
[urisagit/Stem.git] / BuildStem.pm
CommitLineData
b3407611 1package BuildStem;
4536f655 2
3use strict;
b3407611 4use warnings;
4536f655 5
4536f655 6use Config;
b3407611 7use File::Basename;
8use File::Spec;
9use IO::File;
4536f655 10
b3407611 11use Module::Build;
4536f655 12
b3407611 13use vars qw(@ISA);
14@ISA = qw(Module::Build);
4536f655 15
4536f655 16
17sub process_script_files {
4536f655 18 my ( $self ) = @_ ;
b3407611 19 my $files = $self->find_script_files();
20 return unless keys %$files;
21
22 my $script_dir = File::Spec->catdir($self->blib, 'script');
23 my $demo_dir = File::Spec->catdir($self->blib, 'demo');
24 File::Path::mkpath( $script_dir );
25 File::Path::mkpath( $demo_dir );
6b34fa66 26 $self->add_to_cleanup($demo_dir);
b3407611 27
28 foreach my $file (keys %$files) {
29 my $dest_dir = $file =~ /_demo$/ ? $demo_dir : $script_dir ;
30 my $result = $self->copy_if_modified($file, $dest_dir, 'flatten') or next;
31 $self->fix_shebang_line($result) if $self->is_unixish();
32 $self->make_executable($result);
33 my $demo_run_dir = File::Spec->catdir($self->base_dir(), 'demo');
34 if ( $result =~ /(?:run_stem$)|(?:_demo$)/ ) {
35 my $result2 = $self->copy_if_modified($result, $demo_run_dir, 'flatten') or next;
36 $self->add_to_cleanup($result2);
4536f655 37 }
38 }
b3407611 39 return 1;
4536f655 40}
41
b3407611 42sub process_conf_files {
4536f655 43 my ( $self ) = @_ ;
b3407611 44 my $files = $self->_find_file_by_type('stem','conf');
45 return unless keys %$files;
4536f655 46
b3407611 47 my $conf_dir = File::Spec->catdir($self->blib, 'conf');
48 File::Path::mkpath( $conf_dir );
4536f655 49
b3407611 50 foreach my $file (keys %$files) {
51 my $result = $self->copy_if_modified($file, $conf_dir, 'flatten') or next;
52 $self->fix_shebang_line($result) if $self->is_unixish();
4536f655 53 }
b3407611 54 return 1;
4536f655 55}
56
b3407611 57sub find_binary {
58 my ( $self, $prog ) = @_ ;
59 if ( $self->do_system( "which $prog >/dev/null" ) ) {
60 return `which $prog` ;
4536f655 61 }
4536f655 62 return;
63}
64
4536f655 65
afbe0126 66###########################################################
67# Various convenience routines.
68#
69# To use ACTION_foo, call ./Build foo
70
71
72
73# ACTION: grep through MANIFEST
74# command line args:
75# files=<regex>
76#
77# do we need this action?
78#
79
80sub ACTION_grep_manifest {
81
82 my( $self ) = @_ ;
83
84 my @manifest_sublist = $self->grep_manifest() ;
85
86 print join( "\n", @manifest_sublist ), "\n" ;
87 return;
88}
89
90
91
92# grep through all matched files
93# command line args:
94# files=<regex> (default is all .pm files)
95# re=<regex>
96
97sub ACTION_grep {
98
99 my( $self ) = @_ ;
100
101 my $args = $self->{'args'} ;
102
103 my $file_regex = $args->{ files } || qr/\.pm$/ ;
104 my $grep_regex = $args->{ re } or die "need grep regex" ;
105
106 my @manifest_sublist = $self->grep_manifest( $file_regex ) ;
107
108 local( @ARGV ) = @manifest_sublist ;
109
110 while( <> ) {
111
112 next unless /$grep_regex/ ;
113
114 print "$ARGV:$. $_"
115 }
116 continue {
117
118 close ARGV if eof ;
119 }
120
121 return;
122}
123
124my ( @manifest_lines ) ;
125
126# MANIFEST helper subs
127
128sub grep_manifest {
129
130 my( $self, $file_regex ) = @_ ;
131
132 $file_regex ||= $self->{ args }{ files } || qr/.*/ ;
133
134 manifest_load() ;
135
136 return grep( /$file_regex/, @manifest_lines ) ;
137}
138
139sub manifest_load {
140
141 return if @manifest_lines ;
142
143 @manifest_lines = grep ! /^\s*$|^\s*#/, read_file( 'MANIFEST' ) ;
144
145 chomp @manifest_lines ;
146
147 return ;
148}
149
150sub read_file {
151
152 my ( $file_name ) = @_ ;
153
154 local( *FH );
155
156 open( FH, $file_name ) || die "Can't open $file_name $!";
157
158 return <FH> if wantarray;
159
160 read FH, my $buf, -s FH;
161 return $buf;
162}
163
164
b3407611 1651;