1 # autoconf -- create `configure' using m4 macros
2 # Copyright (C) 2003 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 package Autom4te
::C4che
;
23 Autom4te::C4che - a single m4 run request
31 This Perl module handles the cache of M4 runs used by autom4te.
36 use Autom4te
::Request
;
46 We cannot declare it "my" as the loading, performed via "do", would
47 refer to another scope, and @request would not be updated. It used to
48 work with "my" vars, and I do not know whether the current behavior
49 (5.6) is wanted or not.
53 use vars
qw(@request);
55 =item C<$req = Autom4te::C4che-E<gt>retrieve (%attr)>
57 Find a request with the same path and input.
63 my ($self, %attr) = @_;
69 if join ("\n", @{$_->path}) ne join ("\n", @{$attr{path}});
73 if join ("\n", @{$_->input}) ne join ("\n", @{$attr{input}});
82 =item C<$req = Autom4te::C4che-E<gt>register (%attr)>
84 Create and register a request for these path and input.
89 # register ($SELF, %ATTR)
90 # -----------------------
91 # NEW should not be called directly.
95 my ($self, %attr) = @_;
97 # path and input are the only ID for a request object.
98 my $obj = new Autom4te::Request ('path' => $attr{path},
99 'input' => $attr{input});
102 # Assign an id for cache file.
103 $obj->id ("$#request");
109 =item C<$req = Autom4te::C4che-E<gt>request (%request)>
111 Get (retrieve or create) a request for the path C<$request{path}> and
112 the input C<$request{input}>.
117 # request($SELF, %REQUEST)
118 # ------------------------
121 my ($self, %request) = @_;
124 Autom4te::C4che->retrieve (%request)
125 || Autom4te::C4che->register (%request);
127 # If there are new traces to produce, then we are not valid.
128 foreach (@{$request{'macro'}})
130 if (! exists ${$req->macro}{$_})
132 ${$req->macro}{$_} = 1;
137 # It would be great to have $REQ check that it up to date wrt its
138 # dependencies, but that requires getting traces (to fetch the
139 # included files), which is out of the scope of Request
146 =item C<$string = Autom4te::C4che-E<gt>marshall ()>
148 Serialize all the current requests.
160 my $marshall = Data::Dumper->new ([\@request], [qw (*request)]);
161 $marshall->Indent(2)->Terse(0);
162 $res = $marshall->Dump . "\n";
168 =item C<Autom4te::C4che-E<gt>save ($file)>
170 Save the cache in the C<$file> file object.
178 my ($self, $file) = @_;
180 confess "cannot save a single request\n"
186 "# This file was generated.\n",
187 "# It contains the lists of macros which have been traced.\n",
188 "# It can be safely removed.\n",
194 =item C<Autom4te::C4che-E<gt>load ($file)>
196 Load the cache from the C<$file> file object.
204 my ($self, $file) = @_;
205 my $fname = $file->name;
207 confess "cannot load a single request\n"
210 my $contents = join "", $file->getlines;
214 confess "cannot eval $fname: $@\n" if $@;
224 Written by Akim Demaille E<lt>F<akim@freefriends.org>E<gt>.
230 ### Setup "GNU" style for perl-mode and cperl-mode.
232 ## perl-indent-level: 2
233 ## perl-continued-statement-offset: 2
234 ## perl-continued-brace-offset: 0
235 ## perl-brace-offset: 0
236 ## perl-brace-imaginary-offset: 0
237 ## perl-label-offset: -2
238 ## cperl-indent-level: 2
239 ## cperl-brace-offset: 0
240 ## cperl-continued-brace-offset: 0
241 ## cperl-label-offset: -2
242 ## cperl-extra-newline-before-brace: t
243 ## cperl-merge-trailing-else: nil
244 ## cperl-continued-statement-offset: 2