X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=BuildStem.pm;h=a6aa8cb21b78a972d1e636400018c281ce2bf463;hb=c6b0b7550fc1cb81185e5e63a2b1abd360f8f40a;hp=b5108093b27df61e2f130299281824cda70a00a7;hpb=c0baaa7d3112ec2b6d1561fe62bdf9e46a808b42;p=urisagit%2FStem.git diff --git a/BuildStem.pm b/BuildStem.pm index b510809..a6aa8cb 100644 --- a/BuildStem.pm +++ b/BuildStem.pm @@ -63,4 +63,103 @@ sub find_binary { } +########################################################### +# Various convenience routines. +# +# To use ACTION_foo, call ./Build foo + + + +# ACTION: grep through MANIFEST +# command line args: +# files= +# +# do we need this action? +# + +sub ACTION_grep_manifest { + + my( $self ) = @_ ; + + my @manifest_sublist = $self->grep_manifest() ; + + print join( "\n", @manifest_sublist ), "\n" ; + return; +} + + + +# grep through all matched files +# command line args: +# files= (default is all .pm files) +# re= + +sub ACTION_grep { + + my( $self ) = @_ ; + + my $args = $self->{'args'} ; + + my $file_regex = $args->{ files } || qr/\.pm$/ ; + my $grep_regex = $args->{ re } or die "need grep regex" ; + + my @manifest_sublist = $self->grep_manifest( $file_regex ) ; + + local( @ARGV ) = @manifest_sublist ; + + while( <> ) { + + next unless /$grep_regex/ ; + + print "$ARGV:$. $_" + } + continue { + + close ARGV if eof ; + } + + return; +} + +my ( @manifest_lines ) ; + +# MANIFEST helper subs + +sub grep_manifest { + + my( $self, $file_regex ) = @_ ; + + $file_regex ||= $self->{ args }{ files } || qr/.*/ ; + + manifest_load() ; + + return grep( /$file_regex/, @manifest_lines ) ; +} + +sub manifest_load { + + return if @manifest_lines ; + + @manifest_lines = grep ! /^\s*$|^\s*#/, read_file( 'MANIFEST' ) ; + + chomp @manifest_lines ; + + return ; +} + +sub read_file { + + my ( $file_name ) = @_ ; + + local( *FH ); + + open( FH, $file_name ) || die "Can't open $file_name $!"; + + return if wantarray; + + read FH, my $buf, -s FH; + return $buf; +} + + 1;