ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/test/twigmaker.pm
Revision: 1.1
Committed: Fri Sep 15 11:20:42 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Log Message:
seperate as a module

File Contents

# User Rev Content
1 williamc 1.1 #
2     # twigmaker - a substitue compiler for testing make rules
3     # use :
4     # perl twigmaker outfile infiles
5     #
6     # - interface
7     # filedate(file) : return the date of the given file stored in twig
8     # contents() : retunr list of all elements in twig
9    
10     package BuildSystem::test::twigmaker;
11     use FileHandle;
12     require 5.004;
13    
14     sub new {
15     my $class=shift;
16     my $self={};
17     bless $self, $class;
18     if ( @_ ) {
19     my $file=shift;
20     $self->_loadtwig($file);
21     }
22     return $self;
23     }
24    
25     sub maketwig {
26     my $self=shift;
27     my $out=shift;
28    
29     undef $self->{dates};
30     # -- open file for output
31     my $fh=FileHandle->new();
32     $fh->open(">".$out) || die "Unable to open $out $!";
33    
34     # -- compile a list of all files with their datestamps
35     foreach $file ( @_ ) {
36     if ( -f $file ) {
37     $date=(stat($file))[9];
38     }
39     else {
40     $date="not_file";
41     }
42     print $fh $file." ".$date."\n";
43     $self->{dates}{$file}=$date;
44     }
45    
46     undef $fh;
47     }
48    
49     sub contents {
50     my $self=shift;
51     return keys %{$self->{dates}};
52     }
53    
54     sub filedate {
55     my $self=shift;
56     my $file=shift;
57    
58     return $self->{dates}{$file};
59     }
60    
61     sub _loadtwig {
62     my $self=shift;
63     my $infile=shift;
64    
65     my $fh=FileHandle->new();
66     $fh->open("<".$infile) || die "Unable to open $infile $!";
67     while (<$fh>) {
68     chomp;
69     ($file,$date)=split / /;
70     $self->{dates}{$file}=$date;
71     }
72     undef $fh;
73     }