ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/test/twigmaker.pm
Revision: 1.2.2.1
Committed: Thu Nov 2 17:38:01 2000 UTC (24 years, 6 months ago) by williamc
Content type: text/plain
Branch: V0_16branch
CVS Tags: BuildSystemProto1, V0_18_0, V0_18_0alpha
Changes since 1.2: +0 -0 lines
Log Message:
Add tests

File Contents

# Content
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 push @{$self->{dateorder}}, $file;
45 }
46
47 undef $fh;
48 }
49
50 sub contents {
51 my $self=shift;
52 return @{$self->{dateorder}};
53 }
54
55 sub filedate {
56 my $self=shift;
57 my $file=shift;
58
59 return $self->{dates}{$file};
60 }
61
62 sub _loadtwig {
63 my $self=shift;
64 my $infile=shift;
65
66 my $fh=FileHandle->new();
67 $fh->open("<".$infile) || die "Unable to open $infile $!";
68 while (<$fh>) {
69 chomp;
70 ($file,$date)=split / /;
71 $self->{dates}{$file}=$date;
72 push @{$self->{dateorder}}, $file;
73 }
74 undef $fh;
75 }